Commits (4)
*_test.gml
\ No newline at end of file
This diff is collapsed.
...@@ -58,6 +58,9 @@ public class AlkisGreenEnricher ...@@ -58,6 +58,9 @@ public class AlkisGreenEnricher
CityGMLWriteException { CityGMLWriteException {
System.out.println("Reading CityGML file"); System.out.println("Reading CityGML file");
Path inFile = Paths.get(args[0]); Path inFile = Paths.get(args[0]);
Path alkisDataPath = Paths.get(args[1]); // shp, shx and dbf should be present.
Path baumKatasterPath = Paths.get(args[2]);
String outputSuffix = args[3];
CityModel cityModel = GreenEnricher.readCityGml(inFile); CityModel cityModel = GreenEnricher.readCityGml(inFile);
GreenEnricher.createTransformers(cityModel); GreenEnricher.createTransformers(cityModel);
...@@ -79,7 +82,7 @@ public class AlkisGreenEnricher ...@@ -79,7 +82,7 @@ public class AlkisGreenEnricher
// ignore green areas from osm // ignore green areas from osm
osmData.getGreenAreas().clear(); osmData.getGreenAreas().clear();
parseAlkisData(osmData); parseAlkisData(osmData, alkisDataPath);
System.out.println("Fit data in bounding box"); System.out.println("Fit data in bounding box");
...@@ -90,14 +93,14 @@ public class AlkisGreenEnricher ...@@ -90,14 +93,14 @@ public class AlkisGreenEnricher
GreenEnricher.convertRoadAreasToCityGML(cityModel, osmData); GreenEnricher.convertRoadAreasToCityGML(cityModel, osmData);
GreenEnricher.converLandUseAreasToCityGML(cityModel, osmData); GreenEnricher.converLandUseAreasToCityGML(cityModel, osmData);
TreeUtils.insertTrees(cityModel, osmData); TreeUtils.insertTrees(cityModel, osmData, baumKatasterPath);
GreenEnricher.clampToGround(cityModel); GreenEnricher.clampToGround(cityModel);
String inputString = inFile.getFileName().toString(); String inputString = inFile.getFileName().toString();
String inputPathWithoutFileEnding = inputString.substring(0, inputString.lastIndexOf('.')); String inputPathWithoutFileEnding = inputString.substring(0, inputString.lastIndexOf('.'));
Path outputPath = Paths.get("data", inputPathWithoutFileEnding + "_with_alkis_greens_realistic.gml"); Path outputPath = Paths.get("data", inputPathWithoutFileEnding + "_" + outputSuffix + ".gml");
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");
...@@ -105,8 +108,7 @@ public class AlkisGreenEnricher ...@@ -105,8 +108,7 @@ public class AlkisGreenEnricher
} }
private static void parseAlkisData(OsmData osmData) throws MalformedURLException, IOException { private static void parseAlkisData(OsmData osmData, Path alkisDataPath) throws MalformedURLException, IOException {
Path alkisDataPath = Paths.get("data", "tn_09663", "Nutzung.shp");
Map<String, Object> readParameters = new HashMap<>(); Map<String, Object> readParameters = new HashMap<>();
readParameters.put("url", alkisDataPath.toUri().toURL()); readParameters.put("url", alkisDataPath.toUri().toURL());
......
...@@ -116,16 +116,22 @@ public class GreenEnricher ...@@ -116,16 +116,22 @@ public class GreenEnricher
InterruptedException, ParserConfigurationException, CityGMLWriteException, JAXBException { InterruptedException, ParserConfigurationException, CityGMLWriteException, JAXBException {
System.out.println("Reading CityGML file"); System.out.println("Reading CityGML file");
Path inFile = Paths.get(args[0]); Path inFile = Paths.get(args[0]);
Path baumKatasterPath = Paths.get(args[1]);
String outputSuffix = args[2];
CityModel cityModel = readCityGml(inFile); CityModel cityModel = readCityGml(inFile);
createTransformers(cityModel); createTransformers(cityModel);
OsmData osmData = new OsmData(); OsmData osmData = new OsmData();
String boundingBoxString = extractAndConvertBoundingBox(cityModel, osmData); String boundingBoxString = GreenEnricher.extractAndConvertBoundingBox(cityModel, osmData);
// HttpResponse<String> response = getOsmData(boundingBoxString); String boundingBoxBasename = boundingBoxString.replace(",", "__").replace('.', '_');
// Files.write(Path.of("osm_response.xml"), response.body().getBytes(StandardCharsets.UTF_8)); Path osmCache = Paths.get("data", "cache", "osm_response_" + boundingBoxBasename + ".xml");
// String osmResponse = response.body(); if (!Files.exists(osmCache)) {
String osmResponse = Files.readString(Paths.get("data", "osm_response.xml")); 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"); System.out.println("Parsing OSM response");
parseOsmResponse(osmResponse, osmData); parseOsmResponse(osmResponse, osmData);
...@@ -141,13 +147,13 @@ public class GreenEnricher ...@@ -141,13 +147,13 @@ public class GreenEnricher
convertWaterAreasToCityGML(cityModel, osmData); convertWaterAreasToCityGML(cityModel, osmData);
// trees // trees
TreeUtils.insertTrees(cityModel, osmData); TreeUtils.insertTrees(cityModel, osmData, baumKatasterPath);
clampToGround(cityModel); clampToGround(cityModel);
String inputString = inFile.getFileName().toString(); String inputString = inFile.getFileName().toString();
String inputPathWithoutFileEnding = inputString.substring(0, inputString.lastIndexOf('.')); String inputPathWithoutFileEnding = inputString.substring(0, inputString.lastIndexOf('.'));
Path outputPath = Paths.get("data", inputPathWithoutFileEnding + "_with_osm_greens.gml"); Path outputPath = Paths.get("data", inputPathWithoutFileEnding + "_" + outputSuffix + ".gml");
System.out.println("Writing output file."); System.out.println("Writing output file.");
writeCityGML(cityModel, outputPath); writeCityGML(cityModel, outputPath);
System.out.println("Done"); System.out.println("Done");
......
package de.hft.stuttgart.citygml.green.osm; package de.hft.stuttgart.citygml.green.osm;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Paths; import java.nio.file.Path;
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;
...@@ -16,9 +16,8 @@ import org.xmlobjects.gml.model.geometry.aggregates.MultiSurfaceProperty; ...@@ -16,9 +16,8 @@ import org.xmlobjects.gml.model.geometry.aggregates.MultiSurfaceProperty;
public class TreeUtils public class TreeUtils
{ {
public static void insertTrees(CityModel cityModel, OsmData osmData) throws IOException { public static void insertTrees(CityModel cityModel, OsmData osmData, Path baumKatasterPath) throws IOException {
TreeKatasterData katasterData = TreeKatasterData TreeKatasterData katasterData = TreeKatasterData.parseTreeKatasterData(baumKatasterPath);
.parseTreeKatasterData(Paths.get("data", "Trees", "Trees_realisticScenario_20240201.shp"));
generateTreesFromKataster(cityModel, katasterData); generateTreesFromKataster(cityModel, katasterData);
// TreeKatasterData katasterData2 = TreeKatasterData.parseTreeKatasterData(Paths.get("data", "Trees_realistic_20240201.shp")); // TreeKatasterData katasterData2 = TreeKatasterData.parseTreeKatasterData(Paths.get("data", "Trees_realistic_20240201.shp"));
......
package de.hft.stuttgart.citygml.green.alkis; 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 org.junit.jupiter.api.Test;
import de.hft.stuttgart.citygml.green.osm.GreenEnricher;
class AlkisGreenEnricherTest class AlkisGreenEnricherTest
{ {
@Test @Test
void testAlkisGreen() throws Exception { void testAlkisGreen() throws Exception {
String[] args = new String[] { "data/Grombühl_v4_case_study.gml" }; //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); 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
};
GreenEnricher.main(args);
assertTrue(Files.exists(outputGML));
}
} }