Skip to content

Commit

Permalink
#31 add more specific output about filtered out layers
Browse files Browse the repository at this point in the history
  • Loading branch information
roelderickx committed Sep 10, 2023
1 parent 3346d6b commit 3507a70
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
61 changes: 31 additions & 30 deletions ogr2osm/ogr_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,42 +100,43 @@ def set_query(self, query):


def __get_source_reprojection_func(self, layer):
layer_spatial_ref = layer.GetSpatialRef() if layer else None

spatial_ref = None
if self.source_proj4:
spatial_ref = osr.SpatialReference()
if self.gisorder:
spatial_ref.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
spatial_ref.ImportFromProj4(self.source_proj4)
elif self.source_epsg:
spatial_ref = osr.SpatialReference()
if self.gisorder:
spatial_ref.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
spatial_ref.ImportFromEPSG(self.source_epsg)
elif not layer:
self.logger.info("Skipping filtered out layer")
elif layer_spatial_ref:
spatial_ref = layer_spatial_ref
self.logger.info("Detected projection metadata:\n%s", str(layer_spatial_ref))
else:
self.logger.info("Layer has no projection metadata, falling back to EPSG:4326")
if not self.gisorder:
spatial_ref = osr.SpatialReference()
spatial_ref.ImportFromEPSG(4326)

# No source proj specified yet? Then default to do no reprojection.
# Some python magic: skip reprojection altogether by using a dummy
# lamdba funcion. Otherwise, the lambda will be a call to the OGR
# reprojection stuff.
reproject = lambda geometry: None

if layer:
layer_spatial_ref = layer.GetSpatialRef()

spatial_ref = None
if self.source_proj4:
spatial_ref = osr.SpatialReference()
if self.gisorder:
spatial_ref.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
spatial_ref.ImportFromProj4(self.source_proj4)
elif self.source_epsg:
spatial_ref = osr.SpatialReference()
if self.gisorder:
spatial_ref.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
spatial_ref.ImportFromEPSG(self.source_epsg)
elif layer_spatial_ref:
spatial_ref = layer_spatial_ref
self.logger.info("Detected projection metadata:\n%s", str(layer_spatial_ref))
else:
self.logger.info("Layer has no projection metadata, falling back to EPSG:4326")
if not self.gisorder:
spatial_ref = osr.SpatialReference()
spatial_ref.ImportFromEPSG(4326)

if spatial_ref:
# Destionation projection will *always* be EPSG:4326, WGS84 lat-lon
dest_spatial_ref = osr.SpatialReference()
dest_spatial_ref.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
dest_spatial_ref.ImportFromEPSG(4326)
coord_trans = osr.CoordinateTransformation(spatial_ref, dest_spatial_ref)
reproject = lambda geometry: geometry.Transform(coord_trans)
if spatial_ref:
# Destionation projection will *always* be EPSG:4326, WGS84 lat-lon
dest_spatial_ref = osr.SpatialReference()
dest_spatial_ref.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
dest_spatial_ref.ImportFromEPSG(4326)
coord_trans = osr.CoordinateTransformation(spatial_ref, dest_spatial_ref)
reproject = lambda geometry: geometry.Transform(coord_trans)

return reproject

Expand Down
2 changes: 1 addition & 1 deletion ogr2osm/osm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def __parse_linestring(self, ogrgeometry, tags):
potential_duplicate_ways = []
for i in range(ogrgeometry.GetPointCount()):
(x, y, z) = ogrgeometry.GetPoint(i)
node = self.__add_node(x, y, z, { }, True)
node = self.__add_node(x, y, z, {}, True)
if previous_node_id is None or previous_node_id != node.id:
if previous_node_id is None:
# first node: add all parent ways as potential duplicates
Expand Down
1 change: 1 addition & 0 deletions test/osm_output.t
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ basicgeometriesfilterlayer:
$ ogr2osm -t $TESTDIR/translations/filterlayer-translation.py -f $TESTDIR/shapefiles/basic_geometries.kml
Found valid translation class FilterLayerTranslation
Preparing to convert .* (re)
Skipping filtered out layer
Splitting long ways
Writing file header
Writing nodes
Expand Down
1 change: 1 addition & 0 deletions test/pbf_output.t
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ basicgeometriesfilterlayer:
$ ogr2osm --pbf -t $TESTDIR/translations/filterlayer-translation.py -f $TESTDIR/shapefiles/basic_geometries.kml
Found valid translation class FilterLayerTranslation
Preparing to convert .* (re)
Skipping filtered out layer
Splitting long ways
Writing file header
Writing nodes
Expand Down

0 comments on commit 3507a70

Please sign in to comment.