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

CityObject: Checking if Building or not

parent c49391c1
......@@ -53,7 +53,7 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
int cityObjectsCount = 0;
int foundBuildingsCount = 0;
// int foundVegetationCount = 0;
int foundVegetationCount = 0;
Geometry poly = WKT_READER.read(wktPolygon);
CityGmlIterator citygml = null;
......@@ -71,7 +71,11 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
Coordinate coord = new Coordinate(buildingXmlNode.x, buildingXmlNode.y);
Point point = GEOMETRY_FACTORY.createPoint(coord);
if (point.within(poly)) {
foundBuildingsCount++;
if (buildingXmlNode.isBuilding()) {
foundBuildingsCount++;
} else {
foundVegetationCount++;
}
sb.append(buildingXmlNode.toString());
}
}
......@@ -90,6 +94,9 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
}
LOGGER.info("Buildings found in selected region : " + foundBuildingsCount);
if (foundVegetationCount > 0) {
LOGGER.info("Vegetation found in selected region : " + foundVegetationCount);
}
//NOTE: This could be a problem if header starts with <core:CityModel> and footer ends with </CityModel>
sb.append(citygml.getFooter());
return foundBuildingsCount;
......
......@@ -14,14 +14,11 @@
public class CityObjectMember
{
//TODO: Check it's the only correct possibility.
//FIXME: BuildingPart too!
static final String XPATH_PATTERN = "/CityModel/cityObjectMember[Building or SolitaryVegetationObject or PlantCover]";
private int nodeOffset;
private int nodeLength;
private VTDNav navigator;
private AutoPilot coordinatesFinder;
public Double x;
public Double xMin;
public Double xMax;
......@@ -33,18 +30,28 @@
public CityObjectMember(VTDNav navigator, int nodeOffset, int nodeLength)
throws XPathParseException, XPathEvalException, NavException {
this.navigator = navigator;
this.coordinatesFinder = new AutoPilot(navigator);
this.nodeLength = nodeLength;
this.nodeOffset = nodeOffset;
extractCoordinates();
//TODO: Get Node ID too, in order to avoid duplicates?
//TODO: Now that "Building" can be Vegetation too, define a method to check class?
}
public boolean hasCoordinates() {
return coordinatesCount > 0;
}
public boolean isBuilding() {
try {
this.navigator.push();
AutoPilot checkBuilding = new AutoPilot(this.navigator);
checkBuilding.selectXPath("./Building");
return checkBuilding.evalXPath() != -1;
} catch (XPathEvalException | NavException | XPathParseException ex) {
return false;
} finally {
this.navigator.pop();
}
}
private void extractCoordinates()
throws XPathParseException, XPathEvalException, NavException {
double xTotal = 0;
......@@ -56,6 +63,9 @@ private void extractCoordinates()
double tempYMin = Double.MAX_VALUE;
double tempYMax = Double.MIN_VALUE;
AutoPilot coordinatesFinder = new AutoPilot(navigator);
coordinatesFinder.selectXPath(".//posList|.//pos");
while (coordinatesFinder.evalXPath() != -1) {
long offsetAndLength = navigator.getContentFragment();
......
......@@ -173,7 +173,6 @@ void testExtractBuildingsAndRemoveOld() throws Throwable {
StringWriter gmlWriter = new StringWriter();
int count = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, "EPSG:25832", gmlWriter, citygmlPath);
String oneAachenBuilding = gmlWriter.toString();
System.out.println(oneAachenBuilding);
assertEquals(1, count);
assertEquals(1, countRegexMatches(oneAachenBuilding, CITY_OBJECT_MEMBER_REGEX));
assertTrue(oneAachenBuilding.contains("DENW39AL10003jfi"));
......
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