Skip to content

Commit

Permalink
Merge pull request #51 from SlowMo24/main
Browse files Browse the repository at this point in the history
Fix processing for unnecessary FeatureCollections
  • Loading branch information
roelderickx authored Oct 20, 2024
2 parents 2a0c8b2 + 2ff745e commit b2acf0a
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 10 deletions.
15 changes: 14 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
15 changes: 6 additions & 9 deletions ogr2osm/osm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ RUN apt-get install -y \
RUN pip install cram lxml
RUN pip install --upgrade protobuf

ENTRYPOINT ["cram"]
25 changes: 25 additions & 0 deletions test/osm_output.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions test/shapefiles/unnecessary_collection.geojson
Original file line number Diff line number Diff line change
@@ -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"
}
}]
}
13 changes: 13 additions & 0 deletions test/unnecessary_collection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="ogr2osm 1.2.0" upload="false">
<node visible="true" id="-1" lat="0" lon="0"/>
<node visible="true" id="-2" lat="1" lon="1"/>
<node visible="true" id="-3" lat="1" lon="0"/>
<way visible="true" id="-4">
<nd ref="-1"/>
<nd ref="-2"/>
<nd ref="-3"/>
<nd ref="-1"/>
<tag k="name" v="yes"/>
</way>
</osm>

0 comments on commit b2acf0a

Please sign in to comment.