From 3507a704e6f2e36e2bed46e3a68e8f2be56cf598 Mon Sep 17 00:00:00 2001 From: roelderickx Date: Sun, 10 Sep 2023 18:21:44 +0200 Subject: [PATCH] #31 add more specific output about filtered out layers --- ogr2osm/ogr_datasource.py | 61 ++++++++++++++++++++------------------- ogr2osm/osm_data.py | 2 +- test/osm_output.t | 1 + test/pbf_output.t | 1 + 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/ogr2osm/ogr_datasource.py b/ogr2osm/ogr_datasource.py index 8eb9679..ea4527e 100644 --- a/ogr2osm/ogr_datasource.py +++ b/ogr2osm/ogr_datasource.py @@ -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 diff --git a/ogr2osm/osm_data.py b/ogr2osm/osm_data.py index ff73bbf..87dc3b7 100644 --- a/ogr2osm/osm_data.py +++ b/ogr2osm/osm_data.py @@ -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 diff --git a/test/osm_output.t b/test/osm_output.t index 10c2895..d11a428 100644 --- a/test/osm_output.t +++ b/test/osm_output.t @@ -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 diff --git a/test/pbf_output.t b/test/pbf_output.t index 9fdd62d..e5338ee 100644 --- a/test/pbf_output.t +++ b/test/pbf_output.t @@ -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