PROPOSAL: to_crs method to accept an optional transformer kwarg
See original GitHub issueFollow up from: https://github.com/geopandas/geopandas/issues/1142#issuecomment-537634477
Currently there are several options for transforming geometries. The the current method is to use pyproj + shapely as it is quite performant. However, it does not fit all use cases at the moment (e.g. antimeridian). As such, it might be useful to allow for alternate transformation methods in to_crs()
.
Some defaults could potentially be added to geopandas.transformers
or something.
This would be similar to what we do in geocube to allow users to rasterize their points: https://corteva.github.io/geocube/html/examples/rasterize_point_data.html
The initial supported ones could be based on current dependencies:
- pyproj + shapely transform(default)
- fiona’s
transform_geom
(based on https://github.com/geopandas/geopandas/issues/448#issuecomment-539778719)
It could look something like:
def to_crs(..., transform_maker=None):
...
if transform_maker is None:
transform_maker = pyproj_transform_maker
transformer = partial(transform_maker, src_crs=self.crs, dst_crs=crs)
result = self.apply(transformer)
And the transform maker would use functools.partial
to return a transformer based in the src_crs and dst_crs that would accept a geometry to transform.
Then, could have different transform makers in geopandas.transformers
that could be extended based on various use cases.
Thoughts?
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (13 by maintainers)
Top GitHub Comments
Another use case for such a “transform” method is where you might want to use a different transformation pipeline from pyproj, instead of the default “best” one:
For this specific case, it might still be worth adding a
transformer
keyword toto_crs
that would only accept a pyproj Transformer, and with which you could override the defaultTransformer.from_crs(self.crs, crs, always_xy=True)
Alternative might be a method name like
geom_transform()
?