Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Compare Revisions
3cead695a37f7b91559bacefc1114765fefd0b25...a1a1a997f286af3dec31fc4df75c37c4f98f7858
Commits (2)
Allow to calculate area directly.
· 833c9305
Eric Duminil
authored
Jan 21, 2025
833c9305
Moving to version 0.3.3
· a1a1a997
Eric Duminil
authored
Jan 21, 2025
a1a1a997
Show whitespace changes
Inline
Side-by-side
pom.xml
View file @
a1a1a997
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<groupId>
eu.simstadt
</groupId>
<groupId>
eu.simstadt
</groupId>
<artifactId>
region-chooser
</artifactId>
<artifactId>
region-chooser
</artifactId>
<version>
0.3.
2
-SNAPSHOT
</version>
<version>
0.3.
3
-SNAPSHOT
</version>
<properties>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
...
...
src/main/java/eu/simstadt/regionchooser/fast_xml_parser/ConvexHullCalculator.java
View file @
a1a1a997
...
@@ -52,6 +52,26 @@ private ConvexHullCalculator() {
...
@@ -52,6 +52,26 @@ private ConvexHullCalculator() {
*/
*/
public
static
Geometry
calculateFromCityGML
(
Path
citygmlPath
)
throws
XPathParseException
,
IOException
{
public
static
Geometry
calculateFromCityGML
(
Path
citygmlPath
)
throws
XPathParseException
,
IOException
{
Polygon
originalConvexHull
=
getConvexHull
(
citygmlPath
);
CoordinateReferenceSystem
originalCRS
=
RegionChooserUtils
.
crsFromCityGMLHeader
(
citygmlPath
);
Polygon
convexHull
=
RegionChooserUtils
.
changePolygonCRS
(
originalConvexHull
,
originalCRS
,
RegionChooserUtils
.
WGS84
);
convexHull
.
setUserData
(
originalCRS
.
toString
());
return
convexHull
;
}
/**
* @param citygmlPath
* @return area of convex hull, in the same unit as original file. Hopefully m², but possibly ft² or even °².
* @throws XPathParseException
*/
public
static
double
calculateArea
(
Path
citygmlPath
)
throws
XPathParseException
{
Polygon
originalConvexHull
=
getConvexHull
(
citygmlPath
);
return
originalConvexHull
.
getArea
();
}
private
static
Polygon
getConvexHull
(
Path
citygmlPath
)
throws
XPathParseException
{
GeometryFactory
geometryFactory
=
new
GeometryFactory
();
GeometryFactory
geometryFactory
=
new
GeometryFactory
();
ArrayList
<
Coordinate
>
allPoints
=
new
ArrayList
<>();
ArrayList
<
Coordinate
>
allPoints
=
new
ArrayList
<>();
CityGmlIterator
citygml
=
new
CityGmlIterator
(
citygmlPath
);
CityGmlIterator
citygml
=
new
CityGmlIterator
(
citygmlPath
);
...
@@ -70,12 +90,13 @@ public static Geometry calculateFromCityGML(Path citygmlPath) throws XPathParseE
...
@@ -70,12 +90,13 @@ public static Geometry calculateFromCityGML(Path citygmlPath) throws XPathParseE
// Convert convex hull in original coordinates to WGS84 coordinates.
// Convert convex hull in original coordinates to WGS84 coordinates.
// NOTE: It's faster to convert to WGS84 once the convex hull is calculated, because there are fewer points
// NOTE: It's faster to convert to WGS84 once the convex hull is calculated, because there are fewer points
Polygon
originalConvexHull
=
(
Polygon
)
ch
.
getConvexHull
();
Polygon
originalConvexHull
=
(
Polygon
)
ch
.
getConvexHull
();
return
originalConvexHull
;
}
CoordinateReferenceSystem
originalCRS
=
RegionChooserUtils
.
crsFromCityGMLHeader
(
citygmlPath
);
public
static
Geometry
getArea
(
Path
citygmlPath
)
throws
XPathParseException
,
IOException
{
Polygon
convexHull
=
RegionChooserUtils
.
changePolygonCRS
(
originalConvexHull
,
originalCRS
,
Geometry
geometry
=
calculateFromCityGML
(
citygmlPath
);
RegionChooserUtils
.
WGS84
);
RegionChooserUtils
.
changePolygonCRS
((
Polygon
)
geometry
,
RegionChooserUtils
.
WGS84
,
RegionChooserUtils
.
WGS84
);
convexHull
.
setUserData
(
originalCRS
.
toString
());
return
geometry
;
return
convexHull
;
}
}
/**
/**
...
...
src/test/java/eu/simstadt/regionchooser/fast_xml_parser/ConvexHullCalculatorTests.java
View file @
a1a1a997
...
@@ -4,7 +4,6 @@
...
@@ -4,7 +4,6 @@
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
fail
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
fail
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
...
@@ -46,6 +45,30 @@ public void testExtractConvexHullFromOneSmallRegion() throws IOException, XPathP
...
@@ -46,6 +45,30 @@ public void testExtractConvexHullFromOneSmallRegion() throws IOException, XPathP
assertTrue
(
hull
.
contains
(
somewhereBetweenBuildings
),
"Hull should contain region between buildings"
);
assertTrue
(
hull
.
contains
(
somewhereBetweenBuildings
),
"Hull should contain region between buildings"
);
}
}
@Test
public
void
testAreaFromOneSmallRegion
()
throws
IOException
,
XPathParseException
{
Path
citygmlPath
=
repository
.
resolve
(
"Gruenbuehl.proj/Gruenbuehl_LOD2_ALKIS_1010.gml"
);
double
squareMeters
=
ConvexHullCalculator
.
calculateArea
(
citygmlPath
);
double
hectares
=
squareMeters
/
10000
;
assertEquals
(
19.0
,
hectares
,
0.2
);
citygmlPath
=
repository
.
resolve
(
"NewYork.proj/FamilyCourt_LOD2_with_PLUTO_attributes.gml"
);
squareMeters
=
ConvexHullCalculator
.
calculateArea
(
citygmlPath
);
// Checked with GoogleEarth
assertEquals
(
13000
,
squareMeters
,
1000
);
citygmlPath
=
repository
.
resolve
(
"NewYork.proj/ManhattanSmall.gml"
);
squareMeters
=
ConvexHullCalculator
.
calculateArea
(
citygmlPath
);
// Checked with GoogleEarth
double
squareKilometers
=
squareMeters
/
1000000
;
assertEquals
(
1.0
,
squareKilometers
,
0.1
);
citygmlPath
=
repository
.
resolve
(
"Stuttgart.proj/Stuttgart_LOD0_LOD1_small.gml"
);
squareMeters
=
ConvexHullCalculator
.
calculateArea
(
citygmlPath
);
hectares
=
squareMeters
/
10000
;
assertEquals
(
47.5
,
hectares
,
1
);
}
@Test
@Test
public
void
testExtractConvexHullFromStoeckachNoBuildingPart
()
throws
IOException
,
XPathParseException
{
public
void
testExtractConvexHullFromStoeckachNoBuildingPart
()
throws
IOException
,
XPathParseException
{
Path
citygmlPath
=
repository
.
resolve
(
"Stuttgart.proj/Stöckach_überarbeitete GML-NoBuildingPart.gml"
);
Path
citygmlPath
=
repository
.
resolve
(
"Stuttgart.proj/Stöckach_überarbeitete GML-NoBuildingPart.gml"
);
...
...