Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
84404739
Commit
84404739
authored
Dec 19, 2023
by
Eric Duminil
Browse files
Different logic for building and other objects.
Tests pass again
parent
d1ad9518
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/eu/simstadt/regionchooser/RegionExtractor.java
View file @
84404739
...
...
@@ -53,7 +53,7 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
int
cityObjectsCount
=
0
;
int
foundBuildingsCount
=
0
;
int
foundVegetation
Count
=
0
;
int
otherObjects
Count
=
0
;
Geometry
polygon
=
WKT_READER
.
read
(
wktPolygon
);
CityGmlIterator
citygml
=
null
;
...
...
@@ -68,11 +68,14 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
}
cityObjectsCount
+=
1
;
if
(
cityObjectNode
.
hasCoordinates
())
{
if
(
isBoundingBoxTouching
(
cityObjectNode
,
polygon
))
{
if
(
cityObjectNode
.
isBuilding
())
{
boolean
isBuilding
=
cityObjectNode
.
isBuilding
();
boolean
shouldBeIncluded
=
isBuilding
?
isBuildingCenterInPolygon
(
cityObjectNode
,
polygon
)
:
isBoundingBoxTouching
(
cityObjectNode
,
polygon
);
if
(
shouldBeIncluded
)
{
if
(
isBuilding
)
{
foundBuildingsCount
++;
}
else
{
foundVegetation
Count
++;
otherObjects
Count
++;
}
sb
.
append
(
cityObjectNode
.
toString
());
}
...
...
@@ -92,8 +95,8 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
}
LOGGER
.
info
(
"Buildings found in selected region : "
+
foundBuildingsCount
);
if
(
foundVegetation
Count
>
0
)
{
LOGGER
.
info
(
"
Vegetation
found in selected region : "
+
foundVegetation
Count
);
if
(
otherObjects
Count
>
0
)
{
LOGGER
.
info
(
"
Other objects
found in selected region : "
+
otherObjects
Count
);
}
//NOTE: This could be a problem if header starts with <core:CityModel> and footer ends with </CityModel>
sb
.
append
(
citygml
.
getFooter
());
...
...
@@ -105,13 +108,17 @@ static int selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Wr
* which might be desirable for roads or landuse.
*/
private
static
boolean
isBoundingBoxTouching
(
CityObjectMember
cityObjectNode
,
Geometry
polygon
)
{
return
point
(
cityObjectNode
.
x
,
cityObjectNode
.
y
).
within
(
polygon
)
||
point
(
cityObjectNode
.
xMax
,
cityObjectNode
.
yMax
).
within
(
polygon
)
||
return
point
(
cityObjectNode
.
xMax
,
cityObjectNode
.
yMax
).
within
(
polygon
)
||
point
(
cityObjectNode
.
xMax
,
cityObjectNode
.
yMin
).
within
(
polygon
)
||
point
(
cityObjectNode
.
xMin
,
cityObjectNode
.
yMin
).
within
(
polygon
)
||
point
(
cityObjectNode
.
xMin
,
cityObjectNode
.
yMax
).
within
(
polygon
);
}
private
static
boolean
isBuildingCenterInPolygon
(
CityObjectMember
cityObjectNode
,
Geometry
polygon
)
{
return
point
(
cityObjectNode
.
x
,
cityObjectNode
.
y
).
within
(
polygon
);
}
private
static
Point
point
(
Double
x
,
Double
y
)
{
Coordinate
coord
=
new
Coordinate
(
x
,
y
);
return
GEOMETRY_FACTORY
.
createPoint
(
coord
);
...
...
src/test/java/eu/simstadt/regionchooser/RegionExtractorTests.java
View file @
84404739
...
...
@@ -178,7 +178,7 @@ void testExtractBuildingsAndTrees() throws Throwable {
assertEquals
(
4
,
count
);
assertEquals
(
4
,
countRegexMatches
(
gmlWithSomeBuildingAndTrees
,
"<bldg:Building gml:id"
));
assertEquals
(
1
,
countRegexMatches
(
gmlWithSomeBuildingAndTrees
,
"<veg:PlantCover gml:id"
));
assertEquals
(
3
,
countRegexMatches
(
gmlWithSomeBuildingAndTrees
,
"<veg:SolitaryVegetationObject gml:id"
));
assertEquals
(
7
,
countRegexMatches
(
gmlWithSomeBuildingAndTrees
,
"<veg:SolitaryVegetationObject gml:id"
));
assertFalse
(
gmlWithSomeBuildingAndTrees
.
contains
(
"DEBY_LOD2_605230"
),
"Building in another corner should not be included"
);
...
...
@@ -190,6 +190,8 @@ void testExtractBuildingsAndTrees() throws Throwable {
assertTrue
(
gmlWithSomeBuildingAndTrees
.
contains
(
"DEBY_LOD2_605227"
),
"Building in corner should be included"
);
}
//TODO: Check Roads and LandUse too.
@Test
void
testExtractBuildingsAndRemoveOld
()
throws
Throwable
{
String
wktPolygon
=
"POLYGON((293229.6831819388 5623753.072371232,293681.22751166753 5623744.274551504,293668.8482257676 5623469.512992135,293197.09954629745 5623504.821467172,293229.6831819388 5623753.072371232))"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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