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

fiona.transform.transform - different behavior based on GDAL version #919

Open
calebrob6 opened this issue Jul 15, 2020 · 2 comments
Open
Assignees
Milestone

Comments

@calebrob6
Copy link

fiona.transform.transform exhibits different behavior based on the underlying gdal library installed.

Expected behavior and actual behavior.

If I run fiona.transform.transform("epsg:4326", "epsg:3857", [-75.71], [38.06]) I expect to get: ([-8427998.647958742], [4587905.271362515]) regardless of library version, however with gdal 3.0.2 and fiona 1.8.13.post1 I get the incorrect result.

In particular, the xs, ys position are swapped in the arguments, i.e. if I run fiona.transform.transform("epsg:4326", "epsg:3857", [38.06], [-75.71]) then I do get the correct result.

@snowman2 suggested that this could be related to a PYPROJ issue, pyproj4/pyproj#538 (see https://fiona.groups.io/g/main/topic/75506516#60 for comments).

Steps to reproduce the problem.

conda create --name test python gdal fiona # this installs gdal 3.0.2 and fiona 1.8.13.post1
conda activate test
python
>>> import fiona.transform
>>> fiona.transform.transform("epsg:4326", "epsg:3857", [-75.71], [38.06])
([4236819.819591993], [-13244913.18166699])

If I switch the lat/lon position then I get the correct result (http://epsg.io/transform#s_srs=4326&t_srs=3857&x=-75.7169053&y=38.0624956):

>>> fiona.transform.transform("epsg:4326", "epsg:3857", [38.06], [-75.71])
([-8427998.647958742], [4587905.271362515])

If I instead do the conda install with a gdal version less than 3 I get the expected result:

conda create --name test2 python "gdal<3" fiona # this installs gdal 2.3.3 and fiona 1.8.4
conda activate test2
python
>>> fiona.transform.transform("epsg:4326", "epsg:3857", [-75.71], [38.06])
([-8427998.647958742], [4587905.27136252])

Operating system

I have tested this with conda on Windows 10 and Ubuntu 18.04.

Fiona and GDAL version and provenance

@snorfalorpagus has reproduced with different versions on Travis - https://travis-ci.org/github/snorfalorpagus/Fiona/builds/708143904.

@sgillies sgillies self-assigned this Jul 17, 2020
@sgillies sgillies added the bug label Jul 17, 2020
@sgillies sgillies added this to the 1.8.14 milestone Jul 17, 2020
@sgillies
Copy link
Member

sgillies commented Jul 17, 2020

Thanks for the report @calebrob6 . In another issue I'm recommending that users switch, if they can, to "OGC:CRS84" with GDAL 3 instead of expecting the old defaults for "EPSG:4326". But that doesn't mean that we won't have to do something about this.

@ungarj
Copy link

ungarj commented Aug 25, 2020

I also observed an odd behavior using fiona.transform.transform_geom() with either providing CRSes as string or as rasterio.crs.CRS:

#!/usr/bin/env python
from fiona.transform import transform_geom
from rasterio.crs import CRS
from shapely import wkt
from shapely.geometry import mapping

example_point = mapping(wkt.loads("POINT (289318.0739578609 378154.7763680807)"))
src_crs = "EPSG:31287"
dst_crs = "OGC:CRS84"

# output should be {'type': 'Point', 'coordinates': (11.868736780148138, 47.29350228983309)}

print(transform_geom(src_crs, dst_crs, example_point))

print(transform_geom(CRS.from_user_input(src_crs).to_dict(), CRS.from_user_input(dst_crs).to_dict(), example_point))

Output using GDAL 2.4.4, PROJ 5.2.0, pyproj 1.9.6 looks fine:

{'type': 'Point', 'coordinates': (11.868736780148138, 47.29350228983309)}
{'type': 'Point', 'coordinates': (11.868736780148138, 47.29350228983309)}

However, the output using GDAL 3.0.4, PROJ 6.3.2 and 7.1.0, pyproj 1.9.6 and 2.6.1.post1 swaps the axis on the fiona output not using rasterio.crs.CRS:

{'type': 'Point', 'coordinates': (13.048008632586706, 46.503227029929064)}
{'type': 'Point', 'coordinates': (11.868736773665933, 47.2935022723449)}

When setting dst_crs to EPSG:4326 on the latter the axes are swapped but still the coordinates are not correct:

{'type': 'Point', 'coordinates': (46.503227029929064, 13.048008632586706)}
{'type': 'Point', 'coordinates': (11.868736773665933, 47.2935022723449)}

I was using rasterio 1.1.4 and Fiona 1.8.13.post1 for this, both built from source.

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

3 participants