Commit 84404739 authored by Eric Duminil's avatar Eric Duminil
Browse files

Different logic for building and other objects.

Tests pass again
parent d1ad9518
No related merge requests found
Showing with 18 additions and 9 deletions
+18 -9
...@@ -53,7 +53,7 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr ...@@ -53,7 +53,7 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
int cityObjectsCount = 0; int cityObjectsCount = 0;
int foundBuildingsCount = 0; int foundBuildingsCount = 0;
int foundVegetationCount = 0; int otherObjectsCount = 0;
Geometry polygon = WKT_READER.read(wktPolygon); Geometry polygon = WKT_READER.read(wktPolygon);
CityGmlIterator citygml = null; CityGmlIterator citygml = null;
...@@ -68,11 +68,14 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr ...@@ -68,11 +68,14 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
} }
cityObjectsCount += 1; cityObjectsCount += 1;
if (cityObjectNode.hasCoordinates()) { if (cityObjectNode.hasCoordinates()) {
if (isBoundingBoxTouching(cityObjectNode, polygon)) { boolean isBuilding = cityObjectNode.isBuilding();
if (cityObjectNode.isBuilding()) { boolean shouldBeIncluded = isBuilding ? isBuildingCenterInPolygon(cityObjectNode, polygon)
: isBoundingBoxTouching(cityObjectNode, polygon);
if (shouldBeIncluded) {
if (isBuilding) {
foundBuildingsCount++; foundBuildingsCount++;
} else { } else {
foundVegetationCount++; otherObjectsCount++;
} }
sb.append(cityObjectNode.toString()); sb.append(cityObjectNode.toString());
} }
...@@ -92,8 +95,8 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr ...@@ -92,8 +95,8 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
} }
LOGGER.info("Buildings found in selected region : " + foundBuildingsCount); LOGGER.info("Buildings found in selected region : " + foundBuildingsCount);
if (foundVegetationCount > 0) { if (otherObjectsCount > 0) {
LOGGER.info("Vegetation found in selected region : " + foundVegetationCount); LOGGER.info("Other objects found in selected region : " + otherObjectsCount);
} }
//NOTE: This could be a problem if header starts with <core:CityModel> and footer ends with </CityModel> //NOTE: This could be a problem if header starts with <core:CityModel> and footer ends with </CityModel>
sb.append(citygml.getFooter()); sb.append(citygml.getFooter());
...@@ -105,13 +108,17 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr ...@@ -105,13 +108,17 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
* which might be desirable for roads or landuse. * which might be desirable for roads or landuse.
*/ */
private static boolean isBoundingBoxTouching(CityObjectMember cityObjectNode, Geometry polygon) { private static boolean isBoundingBoxTouching(CityObjectMember cityObjectNode, Geometry polygon) {
return point(cityObjectNode.x, cityObjectNode.y).within(polygon) || return point(cityObjectNode.xMax, cityObjectNode.yMax).within(polygon) ||
point(cityObjectNode.xMax, cityObjectNode.yMax).within(polygon) ||
point(cityObjectNode.xMax, cityObjectNode.yMin).within(polygon) || point(cityObjectNode.xMax, cityObjectNode.yMin).within(polygon) ||
point(cityObjectNode.xMin, cityObjectNode.yMin).within(polygon) || point(cityObjectNode.xMin, cityObjectNode.yMin).within(polygon) ||
point(cityObjectNode.xMin, cityObjectNode.yMax).within(polygon); point(cityObjectNode.xMin, cityObjectNode.yMax).within(polygon);
} }
private static boolean isBuildingCenterInPolygon(CityObjectMember cityObjectNode, Geometry polygon) {
return point(cityObjectNode.x, cityObjectNode.y).within(polygon);
}
private static Point point(Double x, Double y) { private static Point point(Double x, Double y) {
Coordinate coord = new Coordinate(x, y); Coordinate coord = new Coordinate(x, y);
return GEOMETRY_FACTORY.createPoint(coord); return GEOMETRY_FACTORY.createPoint(coord);
......
...@@ -178,7 +178,7 @@ void testExtractBuildingsAndTrees() throws Throwable { ...@@ -178,7 +178,7 @@ void testExtractBuildingsAndTrees() throws Throwable {
assertEquals(4, count); assertEquals(4, count);
assertEquals(4, countRegexMatches(gmlWithSomeBuildingAndTrees, "<bldg:Building gml:id")); assertEquals(4, countRegexMatches(gmlWithSomeBuildingAndTrees, "<bldg:Building gml:id"));
assertEquals(1, countRegexMatches(gmlWithSomeBuildingAndTrees, "<veg:PlantCover gml:id")); assertEquals(1, countRegexMatches(gmlWithSomeBuildingAndTrees, "<veg:PlantCover gml:id"));
assertEquals(3, countRegexMatches(gmlWithSomeBuildingAndTrees, "<veg:SolitaryVegetationObject gml:id")); assertEquals(7, countRegexMatches(gmlWithSomeBuildingAndTrees, "<veg:SolitaryVegetationObject gml:id"));
assertFalse(gmlWithSomeBuildingAndTrees.contains("DEBY_LOD2_605230"), assertFalse(gmlWithSomeBuildingAndTrees.contains("DEBY_LOD2_605230"),
"Building in another corner should not be included"); "Building in another corner should not be included");
...@@ -190,6 +190,8 @@ void testExtractBuildingsAndTrees() throws Throwable { ...@@ -190,6 +190,8 @@ void testExtractBuildingsAndTrees() throws Throwable {
assertTrue(gmlWithSomeBuildingAndTrees.contains("DEBY_LOD2_605227"), "Building in corner should be included"); assertTrue(gmlWithSomeBuildingAndTrees.contains("DEBY_LOD2_605227"), "Building in corner should be included");
} }
//TODO: Check Roads and LandUse too.
@Test @Test
void testExtractBuildingsAndRemoveOld() throws Throwable { void testExtractBuildingsAndRemoveOld() throws Throwable {
String wktPolygon = "POLYGON((293229.6831819388 5623753.072371232,293681.22751166753 5623744.274551504,293668.8482257676 5623469.512992135,293197.09954629745 5623504.821467172,293229.6831819388 5623753.072371232))"; String wktPolygon = "POLYGON((293229.6831819388 5623753.072371232,293681.22751166753 5623744.274551504,293668.8482257676 5623469.512992135,293197.09954629745 5623504.821467172,293229.6831819388 5623753.072371232))";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment