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
Commits
833c9305
Commit
833c9305
authored
3 months ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Allow to calculate area directly.
parent
3cead695
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/eu/simstadt/regionchooser/fast_xml_parser/ConvexHullCalculator.java
+26
-5
...t/regionchooser/fast_xml_parser/ConvexHullCalculator.java
src/test/java/eu/simstadt/regionchooser/fast_xml_parser/ConvexHullCalculatorTests.java
+24
-1
...ionchooser/fast_xml_parser/ConvexHullCalculatorTests.java
with
50 additions
and
6 deletions
+50
-6
src/main/java/eu/simstadt/regionchooser/fast_xml_parser/ConvexHullCalculator.java
+
26
-
5
View file @
833c9305
...
@@ -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
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/test/java/eu/simstadt/regionchooser/fast_xml_parser/ConvexHullCalculatorTests.java
+
24
-
1
View file @
833c9305
...
@@ -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"
);
...
...
This diff is collapsed.
Click to expand it.
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