Skip to content

Commit

Permalink
Crop single elements and check if the result contains multiple elemen…
Browse files Browse the repository at this point in the history
…ts in GeoJSON (#5657)
  • Loading branch information
bmarchant authored May 25, 2023
1 parent 0662dab commit af525ae
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 2 deletions.
25 changes: 25 additions & 0 deletions hoot-core-test/src/test/cpp/hoot/core/io/OsmGeoJsonWriterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OsmGeoJsonWriterTest : public HootTestFixture
CPPUNIT_TEST(runSplitFcodeBostonRoadBuildingTest);
CPPUNIT_TEST(runObjectGeoJsonTest);
CPPUNIT_TEST(runObjectGeoJsonHootTest);
CPPUNIT_TEST(runCroppingTest);
CPPUNIT_TEST_SUITE_END();

public:
Expand Down Expand Up @@ -215,6 +216,30 @@ class OsmGeoJsonWriterTest : public HootTestFixture
runTest(_inputPath + "SampleObjectsWriter.osm", "SampleObjectsWriterHoot.geojson", &s);
}

void runCroppingTest()
{
// The Boston data splits out into 32 different FCODE files
QStringList multi_files({
"ROAD_C",
"BUILDING_S"
});
for (int i = 0; i < multi_files.size(); ++i)
multi_files[i] = QString("CroppingTest/%1.geojson").arg(multi_files[i]);
// Set global settings
conf().set(ConfigOptions::getWriterThematicStructureKey(), false);
conf().set(ConfigOptions::getOgrAddUuidKey(), false);
// Set local settings
Settings s;
s.set(ConfigOptions::getOgrAddUuidKey(), false);
s.set(ConfigOptions::getGeojsonWriteSplitFileStructureKey(), true);
s.set(ConfigOptions::getWriterThematicStructureKey(), false);
s.set(ConfigOptions::getSchemaTranslationScriptKey(), "translations/GGDMv30.js");
s.set(ConfigOptions::getWriterSortTagsByKeyKey(), true);
s.set(ConfigOptions::getWriterCropFeaturesCrossingBoundsKey(), true);
s.set(ConfigOptions::getBoundsKey(), "-76.6197293502900010,39.2858283149899989,-76.6146064976200023,39.2868360346200021");
runTest(_inputPath + "CroppingTest.osm", "CroppingTest.geojson", &s, multi_files);
}

void runTest(const QString& input, const QString& output, Settings* settings = nullptr, const QStringList& multiOutput = QStringList())
{
OsmXmlReader reader;
Expand Down
24 changes: 22 additions & 2 deletions hoot-core/src/main/cpp/hoot/core/io/OsmGeoJsonWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,32 @@ void OsmGeoJsonWriter::_writePointGeometry(const geos::geom::Geometry* geometry)

void OsmGeoJsonWriter::_writeLineStringGeometry(const geos::geom::Geometry* geometry)
{
_writeGeometry(geometry, GeometryTypeId::GEOS_LINESTRING);
GeometryTypeId type = geometry->getGeometryTypeId();
switch (type)
{
default:
case GEOS_LINESTRING:
_writeGeometry(geometry, type);
break;
case GEOS_MULTILINESTRING:
_writeMultiGeometry(geometry, type);
break;
}
}

void OsmGeoJsonWriter::_writePolygonGeometry(const geos::geom::Geometry* geometry)
{
_writeGeometry(geometry, GeometryTypeId::GEOS_POLYGON);
GeometryTypeId type = geometry->getGeometryTypeId();
switch (type)
{
default:
case GEOS_POLYGON:
_writeGeometry(geometry, type);
break;
case GEOS_MULTIPOLYGON:
_writeMultiGeometry(geometry, type);
break;
}
}

void OsmGeoJsonWriter::_writeGeometry(const geos::geom::Geometry* geometry, geos::geom::GeometryTypeId type)
Expand Down
67 changes: 67 additions & 0 deletions test-files/io/GeoJson/CroppingTest.osm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="hootenanny" srs="+epsg:4326">
<bounds minlat="39.28404126798" minlon="-76.62073374867001" maxlat="39.28654912082" maxlon="-76.61352397084001"/>
<node visible="true" id="1" version="1" lat="39.2855567795900029" lon="-76.6172710087899986"/>
<node visible="true" id="2" version="1" lat="39.2860944691299991" lon="-76.6180542138200025"/>
<node visible="true" id="3" version="1" lat="39.2848799907400021" lon="-76.6178879168599991"/>
<node visible="true" id="4" version="1" lat="39.2862501761900020" lon="-76.6192531692999950"/>
<node visible="true" id="5" version="1" lat="39.2851104318500006" lon="-76.6172039535599936"/>
<node visible="true" id="6" version="1" lat="39.2863415142900010" lon="-76.6160291460199971"/>
<node visible="true" id="7" version="1" lat="39.2862314858800019" lon="-76.6180676248699939"/>
<node visible="true" id="8" version="1" lat="39.2860467208000017" lon="-76.6190305379000023"/>
<node visible="true" id="9" version="1" lat="39.2852142338999997" lon="-76.6174963143500065"/>
<node visible="true" id="10" version="1" lat="39.2840412679800011" lon="-76.6190815079200007"/>
<node visible="true" id="11" version="1" lat="39.2865491208199984" lon="-76.6135239708400064"/>
<node visible="true" id="12" version="1" lat="39.2860695569600011" lon="-76.6160023239300045"/>
<node visible="true" id="13" version="1" lat="39.2855484754700015" lon="-76.6175928738699952"/>
<node visible="true" id="14" version="1" lat="39.2843090748200012" lon="-76.6188937452400012"/>
<node visible="true" id="15" version="1" lat="39.2851913974599967" lon="-76.6153317716700002"/>
<node visible="true" id="16" version="1" lat="39.2861110772299966" lon="-76.6176250603800071"/>
<node visible="true" id="17" version="1" lat="39.2862044977599965" lon="-76.6187569525800001"/>
<node visible="true" id="18" version="1" lat="39.2843505961299968" lon="-76.6178503659400008"/>
<node visible="true" id="19" version="1" lat="39.2861754398299965" lon="-76.6207337486700055"/>
<node visible="true" id="20" version="1" lat="39.2842820921799998" lon="-76.6146934139700022"/>
<node visible="true" id="21" version="1" lat="39.2863643503600031" lon="-76.6154229667800024"/>
<node visible="true" id="22" version="1" lat="39.2860238846400023" lon="-76.6173005130900009"/>
<node visible="true" id="23" version="1" lat="39.2860571008800008" lon="-76.6187462237499943"/>
<node visible="true" id="24" version="1" lat="39.2864660807800021" lon="-76.6149294483700061"/>
<node visible="true" id="25" version="1" lat="39.2852308422200025" lon="-76.6172066357700032"/>
<way visible="true" id="1" version="1">
<nd ref="8"/>
<nd ref="14"/>
<nd ref="18"/>
<nd ref="3"/>
<nd ref="9"/>
<nd ref="25"/>
<nd ref="5"/>
<nd ref="15"/>
<nd ref="21"/>
<nd ref="6"/>
<nd ref="12"/>
<nd ref="22"/>
<nd ref="1"/>
<nd ref="13"/>
<nd ref="16"/>
<nd ref="2"/>
<nd ref="7"/>
<nd ref="17"/>
<nd ref="23"/>
<nd ref="8"/>
<tag k="building" v="yes"/>
<tag k="error:circular" v="15"/>
<tag k="feature_area" v="41183.0"/>
<tag k="name" v="Building Test"/>
</way>
<way visible="true" id="2" version="1">
<nd ref="19"/>
<nd ref="4"/>
<nd ref="10"/>
<nd ref="20"/>
<nd ref="24"/>
<nd ref="11"/>
<tag k="error:circular" v="15"/>
<tag k="highway" v="primary"/>
<tag k="length" v="1118.6"/>
<tag k="name" v="Highway Test"/>
</way>
</osm>
3 changes: 3 additions & 0 deletions test-files/io/GeoJson/CroppingTest/BUILDING_S.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"generator":"Hootenanny","type":"FeatureCollection","bbox":[-76.621, 39.284, -76.614, 39.287],"features": [
{"type":"Feature","properties":{"ARA":"41183.0","FCSUBTYPE":"100083","F_CODE":"AL013","ZI005_FNA":"Building Test","ZI026_CTUC":"5"},"geometry": {"type":"MultiPolygon","coordinates": [[[[-76.6190305379, 39.2860467208],[-76.61874622374999, 39.28605710088],[-76.61875695258, 39.28620449776],[-76.61806762486999, 39.28623148588],[-76.61805421382, 39.28609446913],[-76.61762506038001, 39.28611107723],[-76.61760888352043, 39.28582831499],[-76.61901334434501, 39.28582831499],[-76.6190305379, 39.2860467208]]],[[[-76.61730051309, 39.28602388464],[-76.61600232393, 39.28606955696],[-76.61602914602, 39.28634151429],[-76.61542296678, 39.28636435036],[-76.61538129093391, 39.28582831499],[-76.61728816009655, 39.28582831499],[-76.61730051309, 39.28602388464]]]]}}]
}
3 changes: 3 additions & 0 deletions test-files/io/GeoJson/CroppingTest/ROAD_C.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"generator":"Hootenanny","type":"FeatureCollection","bbox":[-76.621, 39.284, -76.614, 39.287],"features": [
{"type":"Feature","properties":{"FCSUBTYPE":"100152","F_CODE":"AP030","LZN":"1118.6","OSMTAGS":{"highway":"primary"},"RIN_ROI":"3","RMWC":"5","RTY":"3","SGCC":"5","ZI005_FNA":"Highway Test","ZI016_WTC":"1","ZI026_CTUC":"5"},"geometry": {"type":"MultiLineString","coordinates": [[[-76.61972935029, 39.28622613963066],[-76.61925316929999, 39.28625017619],[-76.61922038510578, 39.28582831499]],[[-76.6148605218813, 39.28582831499],[-76.61492944837001, 39.28646608078],[-76.61460649762, 39.28648516172767]]]}}]
}

0 comments on commit af525ae

Please sign in to comment.