Open
Description
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?