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

Changes, for Marieke & CGSC.

parent c88c9734
......@@ -8,7 +8,6 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
......@@ -122,32 +121,32 @@ public class GreenEnricher
createTransformers(cityModel);
OsmData osmData = new OsmData();
String boundingBoxString = GreenEnricher.extractAndConvertBoundingBox(cityModel, osmData);
String boundingBoxBasename = boundingBoxString.replace(",", "__").replace('.', '_');
Path osmCache = Paths.get("data", "cache", "osm_response_" + boundingBoxBasename + ".xml");
if (!Files.exists(osmCache)) {
System.out.println("Downloading OSM data for " + boundingBoxString);
HttpResponse<String> response = GreenEnricher.getOsmData(boundingBoxString);
Files.write(osmCache, response.body().getBytes(StandardCharsets.UTF_8));
}
String osmResponse = Files.readString(osmCache);
System.out.println("Parsing OSM response");
parseOsmResponse(osmResponse, osmData);
System.out.println("Fit data in bounding box");
fitToBoundingBox(osmData);
System.out.println("Filter intersecting areas");
List<GreenArea> greenAreas = osmData.getGreenAreas();
removeDuplicateAreas(greenAreas);
convertGreenAreasToCityGML(cityModel, greenAreas);
convertWaterAreasToCityGML(cityModel, osmData);
// OsmData osmData = new OsmData();
// String boundingBoxString = GreenEnricher.extractAndConvertBoundingBox(cityModel, osmData);
// String boundingBoxBasename = boundingBoxString.replace(",", "__").replace('.', '_');
// Path osmCache = Paths.get("data", "cache", "osm_response_" + boundingBoxBasename + ".xml");
// if (!Files.exists(osmCache)) {
// System.out.println("Downloading OSM data for " + boundingBoxString);
// HttpResponse<String> response = GreenEnricher.getOsmData(boundingBoxString);
// Files.write(osmCache, response.body().getBytes(StandardCharsets.UTF_8));
// }
// String osmResponse = Files.readString(osmCache);
//
// System.out.println("Parsing OSM response");
// parseOsmResponse(osmResponse, osmData);
//
// System.out.println("Fit data in bounding box");
// fitToBoundingBox(osmData);
//
// System.out.println("Filter intersecting areas");
// List<GreenArea> greenAreas = osmData.getGreenAreas();
// removeDuplicateAreas(greenAreas);
//
// convertGreenAreasToCityGML(cityModel, greenAreas);
// convertWaterAreasToCityGML(cityModel, osmData);
// trees
TreeUtils.insertTrees(cityModel, osmData, baumKatasterPath);
TreeUtils.insertTrees(cityModel, null, baumKatasterPath);
clampToGround(cityModel);
......
......@@ -7,7 +7,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
......@@ -17,7 +16,9 @@ import org.locationtech.jts.geom.Point;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
public class TreeKatasterData {
public class TreeKatasterData
{
public static final double TRUNK_PERCENTAGE = 0.2;
public static final double CROWN_PERCENTAGE = 1 - TRUNK_PERCENTAGE;
......@@ -50,7 +51,7 @@ public class TreeKatasterData {
if (treeHeightObject == null) {
continue;
}
int treeHeight = Integer.parseInt(treeHeightObject.toString());
float treeHeight = Float.parseFloat(treeHeightObject.toString());
double crownHeight = CROWN_PERCENTAGE * treeHeight;
double trunkHeight = TRUNK_PERCENTAGE * treeHeight;
tree.setCrownHeight(crownHeight);
......@@ -61,14 +62,7 @@ public class TreeKatasterData {
continue;
}
tree.setCrownRadius(Float.parseFloat(crownWidth.toString()) / 2);
Object trunkCirc = feature.getAttribute("Stammumfan");
if (trunkCirc == null) {
continue;
}
int circInCm = Integer.parseInt(trunkCirc.toString());
if (circInCm == 0) {
circInCm = 89;
}
int circInCm = 50;
tree.setTrunkRadius(circInCm / (2 * Math.PI) / 100);
result.getTrees().add(tree);
}
......
......@@ -25,10 +25,10 @@ public class TreeUtils
// generateTreesFromKataster(cityModel, katasterData2);
// All kataster trees are taken, osm trees are removed
filterDuplicateTreesFromOSM(osmData, katasterData);
// filterDuplicateTreesFromOSM(osmData, katasterData);
// filterDuplicateTreesFromOSM(osmData, katasterData2);
generateTreesFromOSM(cityModel, osmData);
// generateTreesFromOSM(cityModel, osmData);
}
......
package de.hft.stuttgart.citygml.green.alkis;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
import de.hft.stuttgart.citygml.green.osm.GreenEnricher;
class AlkisGreenEnricherTest
{
@Test
void testAlkisGreen() throws Exception {
//NOTE: From https://transfer.hft-stuttgart.de/gitlab/circulargreensimcity/circulargreensimcity/-/wikis/Fallstudien/Gromb%C3%BChl
Path outputGML = Paths.get("data/Grombühl_v4_case_study_alkis_test.gml");
Files.deleteIfExists(outputGML);
assertFalse(Files.exists(outputGML));
String[] args = new String[] { "data/Grombühl_v4_case_study.gml", // Input GML
"data/tn_09663/Nutzung.shp", // ALKIS Data
//NOTE: From https://transfer.hft-stuttgart.de/gitlab/circulargreensimcity/circulargreensimcity/-/issues/26#note_6544
"data/Trees/Trees_realisticScenario_20240201.shp", // Added trees, in Baumkatasterformat,
"alkis_test" // Output GML suffix
};
AlkisGreenEnricher.main(args);
assertTrue(Files.exists(outputGML));
}
// @Test
// void testAlkisGreen() throws Exception {
// //NOTE: From https://transfer.hft-stuttgart.de/gitlab/circulargreensimcity/circulargreensimcity/-/wikis/Fallstudien/Gromb%C3%BChl
// Path outputGML = Paths.get("data/Grombühl_v4_case_study_alkis_test.gml");
// Files.deleteIfExists(outputGML);
// assertFalse(Files.exists(outputGML));
// String[] args = new String[] { "data/Grombühl_BA_IST.gml", // Input GML
// "data/tn_09663/Nutzung.shp", // ALKIS Data
// //NOTE: From https://transfer.hft-stuttgart.de/gitlab/circulargreensimcity/circulargreensimcity/-/issues/26#note_6544
// "data/Trees/Trees_realisticScenario_20240201.shp", // Added trees, in Baumkatasterformat,
// "alkis_test" // Output GML suffix
// };
// AlkisGreenEnricher.main(args);
// assertTrue(Files.exists(outputGML));
// }
@Test
void testGreen() throws Exception {
Path outputGML = Paths.get("data/Grombühl_v4_case_study_enrich_test.gml");
Files.deleteIfExists(outputGML);
assertFalse(Files.exists(outputGML));
String[] args = new String[] { "data/Grombühl_v4_case_study.gml", // Input GML
"data/Trees/Trees_realisticScenario_20240201.shp", // Added trees, in Baumkatasterformat,
"enrich_test" // Output GML suffix
// Path outputGML = Paths.get("data/Grombühl_BA_IST_.gml");
// Files.deleteIfExists(outputGML);
// assertFalse(Files.exists(outputGML));
String[] args = new String[] { "data/Grafenbühl_IST.gml", // Input GML
"data/Baum_Grafenbühl_Ist.shp", // Added trees, in Baumkatasterformat,
// "data/Trees/Trees_realisticScenario_20240201.shp", // Added trees, in Baumkatasterformat,
"plus_trees" // Output GML suffix
};
GreenEnricher.main(args);
assertTrue(Files.exists(outputGML));
// args = new String[] { "data/Grombühl_BA_IST_plus_private.gml", // Input GML
// "data/Baum_oeffentlich_Neu_Ist.shp", // Added trees, in Baumkatasterformat,
// // "data/Trees/Trees_realisticScenario_20240201.shp", // Added trees, in Baumkatasterformat,
// "plus_public" // Output GML suffix
// };
// GreenEnricher.main(args);
// assertTrue(Files.exists(outputGML));
}
}
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