perrygeo/python-rasterstats

Feature request : modify CRS of shp to match raster's automatically

jebouchat opened this issue · 1 comments

Hello,

I thought it would be nice for zonal_stats to be able to handle polygons and rasters with different CRS, or at least warn the user of the fact that they are different.

Regards,
Jean

Dealing with CRS mismatches is a very complex topic and firmly not in the scope of this project. To summarize, CRS matching is a concern that you must deal with explicitly in steps prior to running zonal stats.

  • Not every vector or raster data source has a defined CRS. Any behavior that relied on both being defined would be inconsistent and could lead to very bad misunderstandings - e.g. if you don't get a warning, is it because your CRSs matched or because one was undefined?
  • CRS cannot be accurately compared. There exist many cases of equivalent projections that have only slightly different representations of the projection information. Warning on these would not be appropriate. Performing reprojection on them would be inefficient and might lead to bugs. And determining which CRS are indeed equivalent is an unsolved problem outside the scope of this library.
  • Reprojecting vectors carries many dataset-specific concerns that are best left up to the analyst/developer. Picking the appropriate datum transform, linestring densification, dateline and polar issues, geometry splitting and joining... there is no way to build a generic vector reprojection functionality that will produce accurate zonal stats in every case.
  • Many spatial software packages (including this one) take the explicit stance that operations take place on an arbitrary 2D cartesian plane. This dramatically simplifies the implementation. Concerns about CRS are best handled by specific modules that deal only with CRS. Reprojecting geometries is handled very well by e.g. pyproj and geopandas which are easily combined with rasterstats functionality. No need to reinvent the wheel; please use the CRS functionality that already exists in the ecosystem.