Commit 2ad61a3f authored by Eric Duminil's avatar Eric Duminil
Browse files

Compares bounding box and polygon

Not just center of mass
Tests are broken. RegionChooser now extracts more buildings for a given region
parent d07007bc
......@@ -54,7 +54,7 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
int cityObjectsCount = 0;
int foundBuildingsCount = 0;
int foundVegetationCount = 0;
Geometry poly = WKT_READER.read(wktPolygon);
Geometry polygon = WKT_READER.read(wktPolygon);
CityGmlIterator citygml = null;
for (int i = 0; i < citygmlPaths.length; i++) {
......@@ -64,13 +64,11 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
citygml = new CityGmlIterator(citygmlPath);
for (CityObjectMember cityObjectNode : citygml) {
if (cityObjectsCount == 0) {
sb.append(replaceEnvelopeInHeader(citygml.getHeader(), poly.getEnvelopeInternal(), srsName));
sb.append(replaceEnvelopeInHeader(citygml.getHeader(), polygon.getEnvelopeInternal(), srsName));
}
cityObjectsCount += 1;
if (cityObjectNode.hasCoordinates()) {
Coordinate coord = new Coordinate(cityObjectNode.x, cityObjectNode.y);
Point point = GEOMETRY_FACTORY.createPoint(coord);
if (point.within(poly)) {
if (isBoundingBoxTouching(cityObjectNode, polygon)) {
if (cityObjectNode.isBuilding()) {
foundBuildingsCount++;
} else {
......@@ -102,6 +100,21 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
return foundBuildingsCount;
}
/**
* Returns true if bounding box of cityObjectNode intersects the polygon.
*/
private static boolean isBoundingBoxTouching(CityObjectMember cityObjectNode, Geometry polygon) {
return point(cityObjectNode.xMax, cityObjectNode.yMax).within(polygon) ||
point(cityObjectNode.xMax, cityObjectNode.yMin).within(polygon) ||
point(cityObjectNode.xMin, cityObjectNode.yMin).within(polygon) ||
point(cityObjectNode.xMin, cityObjectNode.yMax).within(polygon);
}
private static Point point(Double x, Double y) {
Coordinate coord = new Coordinate(x, y);
return GEOMETRY_FACTORY.createPoint(coord);
}
/**
* Some Citygml files include an envelope (bounding box), defined at the very beginning of the file. If the extracted
* region comes from a huge file (e.g. from NYC), it might inherit this header with a huge envelope. Some methods
......
Markdown is supported
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