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

Visualizing dataframe with non-EPSG:4326 CRS is failing silently #1274

Open
jorisvandenbossche opened this issue Nov 28, 2019 · 3 comments
Open
Milestone

Comments

@jorisvandenbossche
Copy link
Contributor

jorisvandenbossche commented Nov 28, 2019

When trying to map a GeoDataFrame with projected coordinates (not lat/long EPSG:4326), such as this example (where nybb is in 'epsg:2263'):

import geopandas
nybb = geopandas.read_file(geopandas.datasets.get_path("nybb"))

from cartoframes.viz import Map, Layer
Map(Layer(nybb))

you get a plot area, but with just a grey background (which is probably somewhere in the sea).

Since GeoDataFrames have a crs attribute, I think it would be helpful for users to check this, and either raise an informative error message, or either automatically transform the data when visualizing.

@Jesus89
Copy link
Member

Jesus89 commented Nov 29, 2019

Yes, this is a good point, because actually we are not using the CRS either for the visualization or the upload to our platform. It assumes that everything is 4326.

We are also extracting the SRID in the decoding but it's also not used.

So this is a very good feature we need to integrate. Could you provide some guidance or a PoC about how to integrate and use spatial reference systems in the library? Thanks!

@cmongut cmongut added this to the [1.1] DO next milestone Dec 2, 2019
@jorisvandenbossche
Copy link
Contributor Author

Could you provide some guidance or a PoC about how to integrate and use spatial reference systems in the library? Thanks!

I don't know the online Carto application very well, but I suppose there are good reasons to keep the data on the server always in the same (4326) CRS?

For the local usage of Cartoframes, I think there are basically two options:

  • Raise an informative error if the CRS is not EPSG:4326 and let the user convert themselves
  • Automatically convert the geometries to EPSG:4326 if crs information is available

For both cases, you first need to check if the CRS is equal to CRS:4326. This can be done with using pyproj, but is actually not fully straightforward right now because in geopandas we are not yet using pyproj.CRS as the crs representation (but which is coming: geopandas/geopandas#1003, geopandas/geopandas#1101). This does the trick more or less:

import pyproj
pyproj.CRS.from_user_input(gdf.crs) == "EPSG:4326"

but because many people are probably using the (soon to be deprecated) "+init" method (where the GeoDataFrame.crs is set to eg {'init': 'epsg':4326'}), the above check will fail in this specific case. So you might want to also compare the GeoDataFrame's crs to pyproj.CRS.from_user_input({'init': 'epsg':4326'}) in addition (the difference between both is the "axis order", which is something that is handled by geopandas when converting to another CRS, but for checking the equality of two CRS, it gives a difference).

If you would like to automatically convert the geometries to EPSG:4326 (so the user does not need to do this themselves), you can use the to_crs functionality of GeoPandas:

gdf_wgs84 = gdf.to_crs(epsg=4326)

@Jesus89
Copy link
Member

Jesus89 commented Jul 20, 2020

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

3 participants