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