question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PROPOSAL: to_crs method to accept an optional transformer kwarg

See original GitHub issue

Follow 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:

  1. pyproj + shapely transform(default)
  2. 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:closed
  • Created 4 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
jorisvandenbosschecommented, May 26, 2021

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:

trans_group = pyproj.transformer.TransformerGroup("EPSG:4326", "EPSG:31370", always_xy=True)
# in case you don't want the first
transformer = trans_group.transformers[1]

from shapely.ops import transform
gdf.geometry.apply(lambda geom: transform(transformer.transform, geom))

For this specific case, it might still be worth adding a transformer keyword to to_crs that would only accept a pyproj Transformer, and with which you could override the default Transformer.from_crs(self.crs, crs, always_xy=True)

1reaction
jorisvandenbosschecommented, Aug 31, 2020

Alternative might be a method name like geom_transform() ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignored unknown kwarg option direction, while running ...
x with transformers 4.x. I tried forcing it, but got errors regarding openssl v3 when trying to import tokenizers. conda search transformers -- ......
Read more >
Source code for transformers.pipelines - Hugging Face
Padding text to help Transformer-XL and XLNet with short prompts as proposed by Aman Rusia # in https://github.com/rusiaaman/XLNet-gen#methodology # and ...
Read more >
Python - Cleanest way to override __init__ where an optional ...
What's a clean way to accept an optional keyword argument when overriding a subclassed init where the optional kwarg has to be used...
Read more >
Optional Arguments in Python With *args and **kwargs
In summary, this is how optional function and method parameters work in Python: *args and ** kwargs let you write functions with a...
Read more >
TensorLayer Documentation - Read the Docs
Take Python3 on Ubuntu for example, to install Python includes pip, ... The simplest way to install TensorLayer is as follow, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found