Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[discussion] optimizing transform_geom for repeated transformations #799

Closed
snowman2 opened this issue Oct 8, 2019 · 6 comments
Closed
Assignees
Milestone

Comments

@snowman2
Copy link
Contributor

snowman2 commented Oct 8, 2019

transform = _crs.OCTNewCoordinateTransformation(src, dst)

Currently, the transformer is recreated each time the geometry transform occurs. I am wondering if creating a Transformer class similar to the one in pyproj would make sense to prevent repeated re-creation of the transformer.

https://pyproj4.github.io/pyproj/stable/advanced_examples.html#repeated-transformations

Thoughts?

@sgillies
Copy link
Member

@snowman2 maybe... is OCTNewCoordinateTransformation slow?

@snowman2
Copy link
Contributor Author

Not that it is slow, but am wondering if GDAL 3 using PROJ 6 might impact performance. Not an issue with earlier versions of PROJ. Will have to time it on different versions and see if it matters.

@snowman2
Copy link
Contributor Author

Actually, one thought I had was to allow users to pass in a list of geometries as well as a single geometry. This might make more sense. Thoughts?

@snowman2
Copy link
Contributor Author

Okay, I modified the code to allow passing in a list of geometries and ran this test:

from functools import partial

import geopandas
import fiona
from fiona.transform import transform_geom
from shapely.geometry import mapping

gdf = geopandas.read_file("zip://ne_110m_land.zip")

def base_transformer(geom, src_crs, dst_crs):
    return transform_geom(
            src_crs=src_crs,
            dst_crs=dst_crs,
            geom=geom,
            antimeridian_cutting=True,
    )

forward_transformer = partial(base_transformer, src_crs=gdf.crs, dst_crs="epsg:32628")

raw_geoms = gdf.geometry.apply(mapping)

def transform_geoms(raw_geoms):
    transform_geom(
        src_crs=gdf.crs,
        dst_crs="epsg:32628",
        geom=raw_geoms,
        antimeridian_cutting=True,
    )

Results:
image

Is this a change you would like to see?

@sgillies
Copy link
Member

@snowman2 I think a function to transform a sequence of geometries would be great. Should it return an iterator?

@snowman2
Copy link
Contributor Author

Sounds good. I have a potential implementation in #811.

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

No branches or pull requests

2 participants