Skip to content

Commit b2acf0a

Browse files
authored
Merge pull request #51 from SlowMo24/main
Fix processing for unnecessary FeatureCollections
2 parents 2a0c8b2 + 2ff745e commit b2acf0a

6 files changed

+95
-10
lines changed

CONTRIBUTING.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
## Tests
2-
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.
2+
Test your code and make sure it passes.
3+
cram is used for tests.
4+
To install the test suite and run the tests, we recommend using Docker via the provided [Dockerfile](test/Dockerfile).
5+
```shell
6+
# Build image
7+
docker build -f test/Dockerfile --tag ogr2osm-test
8+
```
9+
```shell
10+
# Run tests
11+
docker run -it --rm -v ./:/app ogr2osm-test test/basic_usage.t \
12+
test/osm_output.t \
13+
test/pbf_output.t
14+
```
15+
See the GitHub actions file [test.yml](.github/workflows/test.yml) for more details.
316

417
Changes in speed-critical parts of the code may require profiling.
518

ogr2osm/osm_data.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ def __parse_collection(self, ogrgeometry, tags):
304304
if collection_geom_type in [ ogr.wkbPoint, ogr.wkbPoint25D, \
305305
ogr.wkbMultiPoint, ogr.wkbMultiPoint25D, \
306306
ogr.wkbLineString, ogr.wkbLinearRing, ogr.wkbLineString25D, \
307-
ogr.wkbMultiLineString, ogr.wkbMultiLineString25D ]:
307+
ogr.wkbMultiLineString, ogr.wkbMultiLineString25D ] \
308+
or ogrgeometry.GetGeometryCount() == 1:
308309
osmgeometries.extend(self.__parse_geometry(collection_geom, tags))
309310
elif collection_geom_type in [ ogr.wkbPolygon, ogr.wkbPolygon25D, \
310311
ogr.wkbMultiPolygon, ogr.wkbMultiPolygon25D ]:
@@ -313,14 +314,10 @@ def __parse_collection(self, ogrgeometry, tags):
313314
not any(members)))
314315
else:
315316
# no support for nested collections or other unsupported types
316-
self.logger.warning("Unhandled geometry in collection, type %d", geometry_type)
317-
318-
if len(members) == 1 and len(members[0].nodes) <= self.max_points_in_way:
319-
# only 1 polygon with 1 outer ring
320-
member[0].tags.update(tags)
321-
osmgeometries.append(member[0])
322-
elif len(members) > 1:
323-
osmgeometries.append(\
317+
self.logger.warning("Unhandled geometry in collection, type %d", collection_geom_type)
318+
319+
if len(members) > 1:
320+
osmgeometries.append( \
324321
self.__verify_duplicate_relations(potential_duplicate_relations, members, tags))
325322

326323
return osmgeometries

test/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ RUN apt-get install -y \
2121
RUN pip install cram lxml
2222
RUN pip install --upgrade protobuf
2323

24+
ENTRYPOINT ["cram"]

test/osm_output.t

+25
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,31 @@ collectionduplicate:
167167
Writing file footer
168168
$ xmllint --format collection_duplicate.osm | diff -uNr - $TESTDIR/collection.xml
169169

170+
unnecessary_collection:
171+
$ ogr2osm -f $TESTDIR/shapefiles/unnecessary_collection.geojson
172+
Using default translations
173+
Preparing to convert .* (re)
174+
Detected projection metadata:
175+
GEOGCS["WGS 84",
176+
DATUM["WGS_1984",
177+
SPHEROID["WGS 84",6378137,298.257223563,
178+
AUTHORITY["EPSG","7030"]],
179+
AUTHORITY["EPSG","6326"]],
180+
PRIMEM["Greenwich",0,
181+
AUTHORITY["EPSG","8901"]],
182+
UNIT["degree",0.0174532925199433,
183+
AUTHORITY["EPSG","9122"]],
184+
AXIS["Latitude",NORTH],
185+
AXIS["Longitude",EAST],
186+
AUTHORITY["EPSG","4326"]]
187+
Splitting long ways
188+
Writing file header
189+
Writing nodes
190+
Writing ways
191+
Writing relations
192+
Writing file footer
193+
$ xmllint --format unnecessary_collection.osm | diff -uNr - $TESTDIR/unnecessary_collection.xml
194+
170195
mergetags:
171196
$ ogr2osm -f $TESTDIR/shapefiles/mergetags.geojson
172197
Using default translations
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type" : "FeatureCollection",
3+
"features" : [{
4+
"type" : "Feature",
5+
"geometry" : {
6+
"type" : "GeometryCollection",
7+
"geometries" : [
8+
{
9+
"type" : "Polygon",
10+
"coordinates" : [
11+
[
12+
[
13+
0,
14+
0
15+
],
16+
[
17+
1,
18+
1
19+
],
20+
[
21+
0,
22+
1
23+
],
24+
[
25+
0,
26+
0
27+
]
28+
]
29+
]}
30+
]
31+
},
32+
"properties" : {
33+
"name": "yes"
34+
}
35+
}]
36+
}

test/unnecessary_collection.xml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<osm version="0.6" generator="ogr2osm 1.2.0" upload="false">
3+
<node visible="true" id="-1" lat="0" lon="0"/>
4+
<node visible="true" id="-2" lat="1" lon="1"/>
5+
<node visible="true" id="-3" lat="1" lon="0"/>
6+
<way visible="true" id="-4">
7+
<nd ref="-1"/>
8+
<nd ref="-2"/>
9+
<nd ref="-3"/>
10+
<nd ref="-1"/>
11+
<tag k="name" v="yes"/>
12+
</way>
13+
</osm>

0 commit comments

Comments
 (0)