Skip to content

Commit a6b9708

Browse files
authored
fix axis ordering for fiona.transform (#926)
1 parent b4ab369 commit a6b9708

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

fiona/_transform.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ cdef void *_crs_from_crs(object crs):
5353
auth, val = init.split(':')
5454
if auth.upper() == 'EPSG':
5555
_crs.OSRImportFromEPSG(osr, int(val))
56-
osr_set_traditional_axis_mapping_strategy(osr)
5756
else:
5857
crs['wktext'] = True
5958
for k, v in crs.items():
@@ -66,12 +65,13 @@ cdef void *_crs_from_crs(object crs):
6665
proj_b = proj.encode('utf-8')
6766
proj_c = proj_b
6867
_crs.OSRImportFromProj4(osr, proj_c)
69-
osr_set_traditional_axis_mapping_strategy(osr)
7068
# Fall back for CRS strings like "EPSG:3857."
7169
else:
7270
proj_b = crs.encode('utf-8')
7371
proj_c = proj_b
7472
_crs.OSRSetFromUserInput(osr, proj_c)
73+
74+
osr_set_traditional_axis_mapping_strategy(osr)
7575
return osr
7676

7777

tests/test_transform.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""Tests of the transform submodule"""
22

33
import math
4-
54
import pytest
6-
75
from fiona import transform
86

97

@@ -48,3 +46,27 @@
4846
def test_transform_geom_with_z(geom):
4947
"""Transforming a geom with Z succeeds"""
5048
g2 = transform.transform_geom("epsg:4326", "epsg:3857", geom, precision=3)
49+
50+
51+
@pytest.mark.parametrize("crs", ["epsg:4326",
52+
"EPSG:4326",
53+
"WGS84",
54+
{'init': 'epsg:4326'},
55+
{'proj': 'longlat', 'datum': 'WGS84', 'no_defs': True},
56+
"OGC:CRS84"])
57+
def test_axis_ordering(crs):
58+
""" Test if transform uses traditional_axis_mapping """
59+
60+
expected = (-8427998.647958742, 4587905.27136252)
61+
t1 = transform.transform(crs, "epsg:3857", [-75.71], [38.06])
62+
assert (t1[0][0], t1[1][0]) == pytest.approx(expected)
63+
geom = {"type": "Point", "coordinates": [-75.71, 38.06]}
64+
g1 = transform.transform_geom(crs, "epsg:3857", geom, precision=3)
65+
assert g1["coordinates"] == pytest.approx(expected)
66+
67+
rev_expected = (-75.71, 38.06)
68+
t2 = transform.transform("epsg:3857", crs, [-8427998.647958742], [4587905.27136252])
69+
assert (t2[0][0], t2[1][0]) == pytest.approx(rev_expected)
70+
geom = {"type": "Point", "coordinates": [-8427998.647958742, 4587905.27136252]}
71+
g2 = transform.transform_geom("epsg:3857", crs, geom, precision=3)
72+
assert g2["coordinates"] == pytest.approx(rev_expected)

0 commit comments

Comments
 (0)