Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openaddr/conform.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ def ogr_source_to_csv(source_config, source_path, dest_path):
_L.debug("SRS tag found specifying %s", srs)
inSpatialRef = osr.SpatialReference()
inSpatialRef.ImportFromEPSG(int(srs[5:]))

if int(osgeo.__version__[0]) >= 3:
# GDAL 3 changes axis order: https://github.com/OSGeo/gdal/issues/1546
inSpatialRef.SetAxisMappingStrategy(osgeo.osr.OAMS_TRADITIONAL_GIS_ORDER)
else:
# OGR is capable of doing more than EPSG, but so far we don't need it.
raise Exception("Bad SRS. Can only handle EPSG, the SRS tag is %s", srs)
Expand Down
25 changes: 23 additions & 2 deletions openaddr/tests/conform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,24 @@ def test_lake_man_shp_noprj_epsg26943(self):
self.assertAlmostEqual(-122.2592497, rows[0]['geometry']['coordinates'][0], places=4)
self.assertAlmostEqual(37.8026126, rows[0]['geometry']['coordinates'][1], places=4)

def test_lake_man_shp_epsg4269_axis_order(self):
# Regression test for https://github.com/openaddresses/batch-machine/issues/26
# A shapefile with an explicit geographic "srs" tag (here EPSG:4269, NAD83)
# must not have its coordinates flipped by GDAL 3's authority-compliant
# (lat, lon) axis order. The underlying shapefile geometry is stored in
# ordinary (lon, lat) order, same coordinates as the plain lake-man.shp
# fixture used by test_lake_man, so the expected output here matches that
# test's expected values. Before the fix, this source's coordinates come
# out as (lat, lon) instead of (lon, lat).
rc, dest_path = self._run_conform_on_source('lake-man-epsg4269', 'shp')
self.assertEqual(0, rc)

with open(dest_path) as fp:
rows = list(map(json.loads, list(fp)))
self.assertEqual('Point', rows[0]['geometry']['type'])
self.assertAlmostEqual(-122.2592497, rows[0]['geometry']['coordinates'][0], places=4)
self.assertAlmostEqual(37.8026126, rows[0]['geometry']['coordinates'][1], places=4)

# TODO: add tests for non-ESRI GeoJSON sources

def test_lake_man_split2(self):
Expand Down Expand Up @@ -1973,8 +1991,11 @@ def test_lake_man_gml(self):
with open(dest_path) as fp:
rows = list(map(json.loads, list(fp)))
self.assertEqual(6, len(rows))
self.assertAlmostEqual(37.8026126, rows[0]['geometry']['coordinates'][0], places=4)
self.assertAlmostEqual(-122.2592497, rows[0]['geometry']['coordinates'][1], places=4)
# GeoJSON coordinates are always [lon, lat]. This source has an
# explicit "srs": "EPSG:4326" tag; see
# https://github.com/openaddresses/batch-machine/issues/26.
self.assertAlmostEqual(-122.2592497, rows[0]['geometry']['coordinates'][0], places=4)
self.assertAlmostEqual(37.8026126, rows[0]['geometry']['coordinates'][1], places=4)
self.assertEqual(rows[0]['properties']['number'], '5115')
self.assertEqual(rows[0]['properties']['street'], 'FRUITED PLAINS LN')

Expand Down
Binary file added openaddr/tests/conforms/lake-man-epsg4269.dbf
Binary file not shown.
20 changes: 20 additions & 0 deletions openaddr/tests/conforms/lake-man-epsg4269.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"schema": 2,
"layers": {
"addresses": [{
"name": "default",
"data": "http://fake-web/lake-man-epsg4269.zip",
"cache": "http://fake-cache/lake-man-epsg4269.zip",
"protocol": "http",
"compression": "zip",
"conform": {
"lon": "X",
"lat": "Y",
"number": "NUMBER",
"street": "STRNAME",
"format": "shapefile",
"srs": "EPSG:4269"
}
}]
}
}
Binary file added openaddr/tests/conforms/lake-man-epsg4269.shp
Binary file not shown.
Binary file added openaddr/tests/conforms/lake-man-epsg4269.shx
Binary file not shown.
Loading