diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c52f7ac..59f3319 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,18 @@ ## Tests -Test your code and make sure it passes. cram is used for tests. See [test.yml](.github/workflows/test.yml) for instructions on how to install and run them. +Test your code and make sure it passes. +cram is used for tests. +To install the test suite and run the tests, we recommend using Docker via the provided [Dockerfile](test/Dockerfile). +```shell +# Build image +docker build -f test/Dockerfile --tag ogr2osm-test +``` +```shell +# Run tests +docker run -it --rm -v ./:/app ogr2osm-test test/basic_usage.t \ + test/osm_output.t \ + test/pbf_output.t +``` +See the GitHub actions file [test.yml](.github/workflows/test.yml) for more details. Changes in speed-critical parts of the code may require profiling. diff --git a/ogr2osm/osm_data.py b/ogr2osm/osm_data.py index 15f4f52..112b95f 100644 --- a/ogr2osm/osm_data.py +++ b/ogr2osm/osm_data.py @@ -304,7 +304,8 @@ def __parse_collection(self, ogrgeometry, tags): if collection_geom_type in [ ogr.wkbPoint, ogr.wkbPoint25D, \ ogr.wkbMultiPoint, ogr.wkbMultiPoint25D, \ ogr.wkbLineString, ogr.wkbLinearRing, ogr.wkbLineString25D, \ - ogr.wkbMultiLineString, ogr.wkbMultiLineString25D ]: + ogr.wkbMultiLineString, ogr.wkbMultiLineString25D ] \ + or ogrgeometry.GetGeometryCount() == 1: osmgeometries.extend(self.__parse_geometry(collection_geom, tags)) elif collection_geom_type in [ ogr.wkbPolygon, ogr.wkbPolygon25D, \ ogr.wkbMultiPolygon, ogr.wkbMultiPolygon25D ]: @@ -313,14 +314,10 @@ def __parse_collection(self, ogrgeometry, tags): not any(members))) else: # no support for nested collections or other unsupported types - self.logger.warning("Unhandled geometry in collection, type %d", geometry_type) - - if len(members) == 1 and len(members[0].nodes) <= self.max_points_in_way: - # only 1 polygon with 1 outer ring - member[0].tags.update(tags) - osmgeometries.append(member[0]) - elif len(members) > 1: - osmgeometries.append(\ + self.logger.warning("Unhandled geometry in collection, type %d", collection_geom_type) + + if len(members) > 1: + osmgeometries.append( \ self.__verify_duplicate_relations(potential_duplicate_relations, members, tags)) return osmgeometries diff --git a/test/Dockerfile b/test/Dockerfile index 94968f4..e289069 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -21,3 +21,4 @@ RUN apt-get install -y \ RUN pip install cram lxml RUN pip install --upgrade protobuf +ENTRYPOINT ["cram"] \ No newline at end of file diff --git a/test/osm_output.t b/test/osm_output.t index a2adc97..56599d0 100644 --- a/test/osm_output.t +++ b/test/osm_output.t @@ -167,6 +167,31 @@ collectionduplicate: Writing file footer $ xmllint --format collection_duplicate.osm | diff -uNr - $TESTDIR/collection.xml +unnecessary_collection: + $ ogr2osm -f $TESTDIR/shapefiles/unnecessary_collection.geojson + Using default translations + Preparing to convert .* (re) + Detected projection metadata: + GEOGCS["WGS 84", + DATUM["WGS_1984", + SPHEROID["WGS 84",6378137,298.257223563, + AUTHORITY["EPSG","7030"]], + AUTHORITY["EPSG","6326"]], + PRIMEM["Greenwich",0, + AUTHORITY["EPSG","8901"]], + UNIT["degree",0.0174532925199433, + AUTHORITY["EPSG","9122"]], + AXIS["Latitude",NORTH], + AXIS["Longitude",EAST], + AUTHORITY["EPSG","4326"]] + Splitting long ways + Writing file header + Writing nodes + Writing ways + Writing relations + Writing file footer + $ xmllint --format unnecessary_collection.osm | diff -uNr - $TESTDIR/unnecessary_collection.xml + mergetags: $ ogr2osm -f $TESTDIR/shapefiles/mergetags.geojson Using default translations diff --git a/test/shapefiles/unnecessary_collection.geojson b/test/shapefiles/unnecessary_collection.geojson new file mode 100644 index 0000000..e7853c6 --- /dev/null +++ b/test/shapefiles/unnecessary_collection.geojson @@ -0,0 +1,36 @@ +{ + "type" : "FeatureCollection", + "features" : [{ + "type" : "Feature", + "geometry" : { + "type" : "GeometryCollection", + "geometries" : [ + { + "type" : "Polygon", + "coordinates" : [ + [ + [ + 0, + 0 + ], + [ + 1, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 0 + ] + ] + ]} + ] + }, + "properties" : { + "name": "yes" + } + }] +} \ No newline at end of file diff --git a/test/unnecessary_collection.xml b/test/unnecessary_collection.xml new file mode 100644 index 0000000..e529dff --- /dev/null +++ b/test/unnecessary_collection.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + +