Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mayer
CircularGreenSimCity
Commits
bf8478d7
Commit
bf8478d7
authored
May 06, 2024
by
Eric Duminil
Browse files
Changes, for Marieke & CGSC.
parent
c88c9734
Changes
4
Show whitespace changes
Inline
Side-by-side
enrich-citygml-with-greenarea/src/main/java/de/hft/stuttgart/citygml/green/osm/GreenEnricher.java
View file @
bf8478d7
...
...
@@ -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
);
...
...
enrich-citygml-with-greenarea/src/main/java/de/hft/stuttgart/citygml/green/osm/TreeKatasterData.java
View file @
bf8478d7
...
...
@@ -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
;
}
in
t
treeHeight
=
Integer
.
parse
In
t
(
treeHeightObject
.
toString
());
floa
t
treeHeight
=
Float
.
parse
Floa
t
(
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
);
}
...
...
enrich-citygml-with-greenarea/src/main/java/de/hft/stuttgart/citygml/green/osm/TreeUtils.java
View file @
bf8478d7
...
...
@@ -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);
}
...
...
enrich-citygml-with-greenarea/src/test/java/de/hft/stuttgart/citygml/green/alkis/AlkisGreenEnricherTest.java
View file @
bf8478d7
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));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment