8000 warn for geographic crs input · Issue #446 · pysal/momepy · GitHub
[go: up one dir, main page]

Skip to content

warn for geographic crs input #446

Open

Description

@jGaboardi

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?

Activity

  1. martinfleis commented on Jan 1, 2023

    @martinfleis
    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.

  2. speco29 commented on Feb 12, 2025

    @speco29

    I understood how these warnings are workings, but I'm still confused on where it will be implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0