Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage CRS from new geopandas release #71

Open
PyMap opened this issue Apr 12, 2020 · 2 comments
Open

Manage CRS from new geopandas release #71

PyMap opened this issue Apr 12, 2020 · 2 comments

Comments

@PyMap
Copy link

PyMap commented Apr 12, 2020

Hi all! With new gepandas release, the pyproj.CRS object has been enriched and the old way (pyproj4) to specify projection as parameter (`crs') seems to have changed considerably.

When you try to plot a gd over a a layer with display method:

# 1. Plot data:
ax = gdf.plot()

# 2. Display dinamic map
mplleaflet.display(fig=ax.figure, crs=ax.crs)

The following error is returned:

TypeError: type object argument after ** must be a mapping, not CRS

This is seems to be explained because CRS with new geopandas release has a new obtect type.

Passing the crs with the .to_dict() this error doesn't appears again, but as I'm still getting some warnings like this one:

UserWarning: You will likely lose important projection information when converting to a PROJ string from another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
  proj_string = self.to_proj4()

I would like to know if this is the correct way to pass the gdf.crs as parameter in the display method.

Great work wit this library, much thanks!

@MochiYoshi
Copy link

MochiYoshi commented May 16, 2020

Not sure if this is helpful but when I ran into the same problem (only being able to plot things in the default EPSG4326 crs and not being able to pass in a different crs/epsg optional argument for mplleaflet.show), I came up with this workaround:

Besides downgrading pyproj to 1.9.6 (which means you wont be able to use geopandas >= 0.7.0), what you can also do is edit the leaflet_renderer.py script, when defining the LeafletRenderer class you can substitute:

old code which works with pyproj 1.9.6 or below -
proj_in = pyproj.Proj(crs)
proj_out = pyproj.Proj(crs_out)
self.transformfunc = partial(pyproj.transform, proj_in, proj_out)

new code which works for pyproj >= 2.0.0 -
proj_in = pyproj.CRS(crs)
proj_out = pyproj.CRS(crs_out)
transformer = pyproj.Transformer.from_crs(proj_in, proj_out, always_xy=True)
self.transformfunc = partial(transformer.transform)

You should also return epsgstr rather than crs in the _crs_from_epsg(epsg) function at the bottom of leaflet_renderer.py to satisfy the new crs format used in pyproj >= 2.0.0.

Hope this helps someone :)

@PyMap
Copy link
Author

PyMap commented May 16, 2020

Thanks for the workaround, I will try to take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants