Commit 0b3a4414 authored by Matthias Betz's avatar Matthias Betz
Browse files

fix AlkisGreenEnricher not working with polygon

parent f704c6b4
...@@ -102,7 +102,7 @@ public class AlkisGreenEnricher ...@@ -102,7 +102,7 @@ public class AlkisGreenEnricher
GreenEnricher.createTransformers(cityModel); GreenEnricher.createTransformers(cityModel);
OsmData osmData = new OsmData(); OsmData osmData = new OsmData();
// String boundingBoxString = GreenEnricher.extractAndConvertBoundingBox(cityModel, osmData); String boundingBoxString = GreenEnricher.extractAndConvertBoundingBox(cityModel, osmData);
// String boundingBoxBasename = boundingBoxString.replace(",", "__").replace('.', '_'); // String boundingBoxBasename = boundingBoxString.replace(",", "__").replace('.', '_');
// Path osmCache = Paths.get("data", "cache", "osm_response_" + boundingBoxBasename + ".xml"); // Path osmCache = Paths.get("data", "cache", "osm_response_" + boundingBoxBasename + ".xml");
// if (!Files.exists(osmCache)) { // if (!Files.exists(osmCache)) {
...@@ -144,8 +144,6 @@ public class AlkisGreenEnricher ...@@ -144,8 +144,6 @@ public class AlkisGreenEnricher
System.out.println("Writing output file."); System.out.println("Writing output file.");
GreenEnricher.writeCityGML(cityModel, outputPath); GreenEnricher.writeCityGML(cityModel, outputPath);
System.out.println("Done"); System.out.println("Done");
} }
private static void parseAlkisData(OsmData osmData, Path alkisDataPath) throws MalformedURLException, IOException { private static void parseAlkisData(OsmData osmData, Path alkisDataPath) throws MalformedURLException, IOException {
......
...@@ -50,7 +50,7 @@ public class TreeKatasterData { ...@@ -50,7 +50,7 @@ public class TreeKatasterData {
if (treeHeightObject == null) { if (treeHeightObject == null) {
continue; continue;
} }
int treeHeight = Integer.parseInt(treeHeightObject.toString()); double treeHeight = Double.parseDouble(treeHeightObject.toString());
double crownHeight = CROWN_PERCENTAGE * treeHeight; double crownHeight = CROWN_PERCENTAGE * treeHeight;
double trunkHeight = TRUNK_PERCENTAGE * treeHeight; double trunkHeight = TRUNK_PERCENTAGE * treeHeight;
tree.setCrownHeight(crownHeight); tree.setCrownHeight(crownHeight);
...@@ -65,8 +65,8 @@ public class TreeKatasterData { ...@@ -65,8 +65,8 @@ public class TreeKatasterData {
if (trunkCirc == null) { if (trunkCirc == null) {
continue; continue;
} }
int circInCm = Integer.parseInt(trunkCirc.toString()); double circInCm = Double.parseDouble(trunkCirc.toString());
if (circInCm == 0) { if (circInCm <= 0.1) {
circInCm = 89; circInCm = 89;
} }
tree.setTrunkRadius(circInCm / (2 * Math.PI) / 100); tree.setTrunkRadius(circInCm / (2 * Math.PI) / 100);
......
...@@ -2,6 +2,7 @@ package de.hft.stuttgart.citygml.green.osm; ...@@ -2,6 +2,7 @@ package de.hft.stuttgart.citygml.green.osm;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
import org.citygml4j.core.model.core.AbstractCityObjectProperty; import org.citygml4j.core.model.core.AbstractCityObjectProperty;
...@@ -9,6 +10,7 @@ import org.citygml4j.core.model.core.CityModel; ...@@ -9,6 +10,7 @@ import org.citygml4j.core.model.core.CityModel;
import org.citygml4j.core.model.vegetation.SolitaryVegetationObject; import org.citygml4j.core.model.vegetation.SolitaryVegetationObject;
import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.geom.Polygon;
import org.xmlobjects.gml.model.basictypes.Code; import org.xmlobjects.gml.model.basictypes.Code;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurface; import org.xmlobjects.gml.model.geometry.aggregates.MultiSurface;
...@@ -24,6 +26,10 @@ public class TreeUtils { ...@@ -24,6 +26,10 @@ public class TreeUtils {
TreeKatasterData katasterData = TreeKatasterData.parseTreeKatasterData(baumKatasterPath); TreeKatasterData katasterData = TreeKatasterData.parseTreeKatasterData(baumKatasterPath);
generateTreesFromKataster(cityModel, katasterData, osmData, wktPolygon); generateTreesFromKataster(cityModel, katasterData, osmData, wktPolygon);
// TreeKatasterData added = TreeKatasterData.parseTreeKatasterData(baumKatasterPath);
// filterDuplicateTrees(katasterData, added);
// generateTreesFromKataster(cityModel, added, osmData, wktPolygon);
// TreeKatasterData katasterData2 = // TreeKatasterData katasterData2 =
// TreeKatasterData.parseTreeKatasterData(Paths.get("data", // TreeKatasterData.parseTreeKatasterData(Paths.get("data",
// "Trees_realistic_20240201.shp")); // "Trees_realistic_20240201.shp"));
...@@ -37,6 +43,19 @@ public class TreeUtils { ...@@ -37,6 +43,19 @@ public class TreeUtils {
} }
private static void filterDuplicateTrees(TreeKatasterData truth, TreeKatasterData added) {
for (Iterator<Tree> iterator = added.getTrees().iterator(); iterator.hasNext();) {
Tree tp = iterator.next();
// if another tree from kataster is within 1m ignore it
for (Tree tree : truth.getTrees()) {
if (tp.getPoint().distance(tree.getPoint()) < 1) {
iterator.remove();
break;
}
}
}
}
private static void filterDuplicateTreesFromOSM(OsmData osmData, TreeKatasterData katasterData) { private static void filterDuplicateTreesFromOSM(OsmData osmData, TreeKatasterData katasterData) {
for (Iterator<TreePoint> iterator = osmData.getTreePoints().iterator(); iterator.hasNext();) { for (Iterator<TreePoint> iterator = osmData.getTreePoints().iterator(); iterator.hasNext();) {
TreePoint tp = iterator.next(); TreePoint tp = iterator.next();
...@@ -80,8 +99,9 @@ public class TreeUtils { ...@@ -80,8 +99,9 @@ public class TreeUtils {
for (Tree tree : katasterData.getTrees()) { for (Tree tree : katasterData.getTrees()) {
// check if tree is in area // check if tree is in area
Coordinate coordinate = tree.getPoint().getCoordinate(); Coordinate coordinate = tree.getPoint().getCoordinate();
if ((wktPolygon != null && !wktPolygon.contains(FACTORY.createPoint(coordinate))) Point point = FACTORY.createPoint(coordinate);
|| !osmData.getBoundingBox().contains(FACTORY.createPoint(coordinate))) { if ((wktPolygon != null && !wktPolygon.contains(point))
|| (wktPolygon == null && !osmData.getBoundingBox().contains(point))) {
continue; continue;
} }
......
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