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
b2bc8047
Commit
b2bc8047
authored
Nov 08, 2019
by
Eric Duminil
Browse files
Renaming GeoUtils to RegionChooserUtils to avoid conflicts. Remove cache before testing
parent
8b662fb3
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/eu/simstadt/geo/
Geo
Utils.java
→
src/main/java/eu/simstadt/geo/
RegionChooser
Utils.java
View file @
b2bc8047
...
...
@@ -18,13 +18,13 @@
import
org.osgeo.proj4j.ProjCoordinate
;
public
class
Geo
Utils
public
class
RegionChooser
Utils
{
private
static
final
CRSFactory
CRS_FACTORY
=
new
CRSFactory
();
public
static
final
CoordinateReferenceSystem
WGS84
=
CRS_FACTORY
.
createFromName
(
"EPSG:4326"
);
private
static
final
Pattern
srsNamePattern
=
Pattern
.
compile
(
"(?i)(?<=srsName=[\"'])[^\"']+(?=[\"'])"
);
private
Geo
Utils
()
{
private
RegionChooser
Utils
()
{
// only static use
}
...
...
src/main/java/eu/simstadt/geo/fast_xml_parser/ConvexHullCalculator.java
View file @
b2bc8047
...
...
@@ -18,7 +18,7 @@
import
org.locationtech.jts.geom.Polygon
;
import
org.osgeo.proj4j.CoordinateReferenceSystem
;
import
com.ximpleware.XPathParseException
;
import
eu.simstadt.geo.
Geo
Utils
;
import
eu.simstadt.geo.
RegionChooser
Utils
;
public
class
ConvexHullCalculator
...
...
@@ -67,8 +67,8 @@ public static Geometry calculateFromCityGML(Path citygmlPath) throws XPathParseE
// NOTE: It's faster to convert to WGS84 once the convex hull is calculated, because there are fewer points
Polygon
originalConvexHull
=
(
Polygon
)
ch
.
getConvexHull
();
CoordinateReferenceSystem
originalCRS
=
Geo
Utils
.
crsFromCityGMLHeader
(
citygmlPath
);
Polygon
convexHull
=
Geo
Utils
.
changePolygonCRS
(
originalConvexHull
,
originalCRS
,
Geo
Utils
.
WGS84
);
CoordinateReferenceSystem
originalCRS
=
RegionChooser
Utils
.
crsFromCityGMLHeader
(
citygmlPath
);
Polygon
convexHull
=
RegionChooser
Utils
.
changePolygonCRS
(
originalConvexHull
,
originalCRS
,
RegionChooser
Utils
.
WGS84
);
convexHull
.
setUserData
(
originalCRS
.
toString
());
return
convexHull
;
}
...
...
@@ -85,7 +85,7 @@ public static Geometry calculateFromCityGML(Path citygmlPath) throws XPathParseE
*/
public
static
void
extractHullsForEveryCityGML
(
Path
repository
,
Consumer
<
String
>
callback
)
throws
IOException
{
LOGGER
.
info
(
"Parsing "
+
repository
);
Geo
Utils
.
everyCityGML
(
repository
)
RegionChooser
Utils
.
everyCityGML
(
repository
)
.
map
(
gmlPath
->
{
LOGGER
.
fine
(
"Importing "
+
repository
.
relativize
(
gmlPath
));
try
{
...
...
src/test/java/eu/simstadt/geo/fast_xml_parser/ConvexHullCalculatorTests.java
View file @
b2bc8047
...
...
@@ -2,9 +2,12 @@
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.Comparator
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.junit.Test
;
import
org.locationtech.jts.geom.Coordinate
;
...
...
@@ -12,7 +15,7 @@
import
org.locationtech.jts.geom.GeometryFactory
;
import
org.locationtech.jts.geom.Point
;
import
com.ximpleware.XPathParseException
;
import
eu.simstadt.geo.
Geo
Utils
;
import
eu.simstadt.geo.
RegionChooser
Utils
;
public
class
ConvexHullCalculatorTests
...
...
@@ -51,9 +54,13 @@ public void testExtractConvexHullFromStoeckachNoBuildingPart() throws IOExceptio
@Test
public
void
testExtractConvexHullFromEveryCitygmlInRepository
()
throws
IOException
{
int
minHullCount
=
6
;
//NOTE: Should cache be deleted first?
// Files.walk(repository.resolve(".cache/hulls"), 1).forEach(System.out::println);
long
gmlCount
=
GeoUtils
.
everyCityGML
(
repository
).
count
();
Path
cachePath
=
repository
.
resolve
(
".cache/hulls"
);
if
(
Files
.
exists
(
cachePath
))
{
// In order to make sure that hulls are calculated during the test, not just read from Cache
Files
.
walk
(
cachePath
).
sorted
(
Comparator
.
reverseOrder
()).
map
(
Path:
:
toFile
).
forEach
(
File:
:
delete
);
}
long
gmlCount
=
RegionChooserUtils
.
everyCityGML
(
repository
).
count
();
AtomicInteger
hullCount
=
new
AtomicInteger
(
0
);
ConvexHullCalculator
.
extractHullsForEveryCityGML
(
repository
,
kmlHull
->
{
assertTrue
(
"KML hull should contain project name"
,
kmlHull
.
contains
(
"Data name=\"project\""
));
...
...
src/test/java/eu/simstadt/regionchooser/RegionExtractorWithDifferentInputTests.java
View file @
b2bc8047
...
...
@@ -15,7 +15,7 @@
import
com.ximpleware.NavException
;
import
com.ximpleware.XPathEvalException
;
import
com.ximpleware.XPathParseException
;
import
eu.simstadt.geo.
Geo
Utils
;
import
eu.simstadt.geo.
RegionChooser
Utils
;
public
class
RegionExtractorWithDifferentInputTests
...
...
@@ -34,7 +34,7 @@ public void testExtractRegionWithLocalCRS()
String
wktPolygon
=
"POLYGON ((307475.5578835043 70804.63316765877, 307236.984333501 70360.67156492763, 307650.1509142817 70061.64902227426, 307964.8070375744 70462.43265268637, 307627.75063951925 70710.99549733262, 307475.5578835043 70804.63316765877))"
;
Path
citygmlPath
=
project
.
resolve
(
citygml
);
CoordinateReferenceSystem
localCRS
=
Geo
Utils
.
crsFromCityGMLHeader
(
citygmlPath
);
CoordinateReferenceSystem
localCRS
=
RegionChooser
Utils
.
crsFromCityGMLHeader
(
citygmlPath
);
StringBuilder
sb
=
RegionExtractor
.
selectRegionDirectlyFromCityGML
(
citygmlPath
,
wktPolygon
,
localCRS
.
getName
());
assertTrue
(
"One weird shaped roof should be inside the region"
,
sb
.
toString
().
contains
(
"gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"
));
...
...
@@ -51,8 +51,8 @@ public void testExtractRegionWithWGS84()
Path
citygmlPath
=
project
.
resolve
(
citygml
);
Polygon
wgs84Polygon
=
(
Polygon
)
WKT_READER
.
read
(
wgs84WktPolygon
);
CoordinateReferenceSystem
localCRS
=
Geo
Utils
.
crsFromCityGMLHeader
(
citygmlPath
);
String
localWktPolygon
=
WKT_WRITER
.
write
(
Geo
Utils
.
changePolygonCRS
(
wgs84Polygon
,
Geo
Utils
.
WGS84
,
localCRS
));
CoordinateReferenceSystem
localCRS
=
RegionChooser
Utils
.
crsFromCityGMLHeader
(
citygmlPath
);
String
localWktPolygon
=
WKT_WRITER
.
write
(
RegionChooser
Utils
.
changePolygonCRS
(
wgs84Polygon
,
RegionChooser
Utils
.
WGS84
,
localCRS
));
StringBuilder
sb
=
RegionExtractor
.
selectRegionDirectlyFromCityGML
(
citygmlPath
,
localWktPolygon
,
localCRS
.
getName
());
assertTrue
(
"One weird shaped roof should be inside the region"
,
...
...
@@ -99,8 +99,8 @@ public void testExtractRegionWithOldCoordinates()
Path
citygmlPath
=
project
.
resolve
(
citygml
);
Polygon
wgs84Polygon
=
(
Polygon
)
WKT_READER
.
read
(
wgs84WktPolygon
);
CoordinateReferenceSystem
localCRS
=
Geo
Utils
.
crsFromCityGMLHeader
(
citygmlPath
);
String
localWktPolygon
=
WKT_WRITER
.
write
(
Geo
Utils
.
changePolygonCRS
(
wgs84Polygon
,
Geo
Utils
.
WGS84
,
localCRS
));
CoordinateReferenceSystem
localCRS
=
RegionChooser
Utils
.
crsFromCityGMLHeader
(
citygmlPath
);
String
localWktPolygon
=
WKT_WRITER
.
write
(
RegionChooser
Utils
.
changePolygonCRS
(
wgs84Polygon
,
RegionChooser
Utils
.
WGS84
,
localCRS
));
StringBuilder
sb
=
RegionExtractor
.
selectRegionDirectlyFromCityGML
(
citygmlPath
,
localWktPolygon
,
localCRS
.
getName
());
...
...
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