Fix lat/lon axis flip for sources with an explicit srs tag - #113
Merged
Conversation
29 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
ogr_source_to_csv()inopenaddr/conform.pybuildsinSpatialReffor the explicit-srscase like this:but never calls
SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER)on it, whileoutSpatialRefa few lines later correctly does. GDAL 3 defaults newSpatialReferenceobjects to authority-compliant axis order, which for geographic CRSes (e.g.EPSG:4326,EPSG:4269, and reportedly the Slovenia source's declared SRS) is (lat, lon) instead of the traditional GIS (lon, lat) order. Since only the output SRS was patched to traditional order and the input SRS was not, the coordinate transform silently swapped lat/lon for any source using an explicitsrs:tag — this matches the issue's own diagnosis thread, where removing thesrstag "fixed" the flip.The sibling function
_transform_to_4326()already sets the axis mapping strategy on both the input and output spatial refs, so it wasn't affected.ogr_source_to_csvonly did it for the output side.Fixes #26.
Fix
Add the same GDAL-3-guarded
SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER)call toinSpatialRefright after it's built from the explicitsrstag, matching the existing style used foroutSpatialRefand in_transform_to_4326.Verification
test_lake_man_shp_epsg4269_axis_order) using a shapefile fixture with coordinates in ordinary (lon, lat) order and an explicit"srs": "EPSG:4269"tag (a geographic CRS, same class as the Slovenia source). With the fix reverted, this test fails with the exact symptom described in the issue — lat and lon swapped (-122.2592497 != 37.8026126). With the fix applied, it passes.openaddr.tests.conformsuite, discovered that the pre-existingtest_lake_man_gmltest (a GML source that also uses an explicit"srs": "EPSG:4326"tag) had its expected coordinates already swapped — i.e. it had encoded this exact bug as "expected" behavior, unlike every other conform test in the file which expects[lon, lat]GeoJSON order. Corrected that test's assertions to the proper[lon, lat]order as part of this fix.docker run --rm -v "$(pwd)":/usr/local/src/batch-machine -w /usr/local/src/batch-machine batch-machine-test:latest python3 -m unittest openaddr.tests.conform -v— all 66 tests pass.