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

warn for geographic crs input #446

Open
jGaboardi opened this issue Dec 3, 2022 · 1 comment
Open

warn for geographic crs input #446

jGaboardi opened this issue Dec 3, 2022 · 1 comment
Labels
enhancement New feature or request rough edge

Comments

@jGaboardi
Copy link
Member

Following up from #369, it would be nice to implement @martinfleis' idea of throwing a warning when the CRS is geographic. Here is where that happens in geopandas.

What we need to decide is where/how this should happen in momepy, and which classes/functions it should happen inside. Maybe a utility function that can be dropped in; something that mimics check_geographic_crs() in GeometryArray:

Python 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:43:44) [Clang 13.0.1 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import geopandas
   ...: from shapely.geometry import Point
   ...: import warnings
   ...: 
   ...: def warn_if_geographic(df):
   ...:     if df.crs and df.crs.is_geographic:
   ...:         warnings.warn(
   ...:             "Geometry is in a geographic CRS. Results are likely "
   ...:             "incorrect. Use 'GeoSeries.to_crs()' to re-project "
   ...:             "geometries to a projected CRS before this operation.",
   ...:             UserWarning
   ...:         )
   ...: 

In [2]: gdf = geopandas.GeoDataFrame(geometry=[Point(0,0)], crs="EPSG:4236")
   ...: warn_if_geographic(gdf)
<ipython-input-1-c0a117e90671>:7: UserWarning: Geometry is in a geographic CRS. Results are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
  warnings.warn(

In [3]: gdf = geopandas.GeoDataFrame(geometry=[Point(0,0)], crs="EPSG:3857")
   ...: warn_if_geographic(gdf)

In [4]: gdf = geopandas.GeoDataFrame(geometry=[Point(0,0)])
   ...: warn_if_geographic(gdf)

Or possibly using check_geographic_crs() directly?

@jGaboardi jGaboardi added enhancement New feature or request rough edge labels Dec 3, 2022
@martinfleis
Copy link
Member

Or possibly using check_geographic_crs() directly?

That is not public, rather not.

We can potentially have a decorator but it would decorate nearly everything :D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rough edge
Projects
None yet
Development

No branches or pull requests

2 participants