Commit b2bc8047 authored by Eric Duminil's avatar Eric Duminil
Browse files

Renaming GeoUtils to RegionChooserUtils to avoid conflicts. Remove cache before testing

parent 8b662fb3
......@@ -18,13 +18,13 @@
import org.osgeo.proj4j.ProjCoordinate;
public class GeoUtils
public class RegionChooserUtils
{
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 GeoUtils() {
private RegionChooserUtils() {
// only static use
}
......
......@@ -18,7 +18,7 @@
import org.locationtech.jts.geom.Polygon;
import org.osgeo.proj4j.CoordinateReferenceSystem;
import com.ximpleware.XPathParseException;
import eu.simstadt.geo.GeoUtils;
import eu.simstadt.geo.RegionChooserUtils;
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 = GeoUtils.crsFromCityGMLHeader(citygmlPath);
Polygon convexHull = GeoUtils.changePolygonCRS(originalConvexHull, originalCRS, GeoUtils.WGS84);
CoordinateReferenceSystem originalCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
Polygon convexHull = RegionChooserUtils.changePolygonCRS(originalConvexHull, originalCRS, RegionChooserUtils.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);
GeoUtils.everyCityGML(repository)
RegionChooserUtils.everyCityGML(repository)
.map(gmlPath -> {
LOGGER.fine("Importing " + repository.relativize(gmlPath));
try {
......
......@@ -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.GeoUtils;
import eu.simstadt.geo.RegionChooserUtils;
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\""));
......
......@@ -15,7 +15,7 @@
import com.ximpleware.NavException;
import com.ximpleware.XPathEvalException;
import com.ximpleware.XPathParseException;
import eu.simstadt.geo.GeoUtils;
import eu.simstadt.geo.RegionChooserUtils;
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 = GeoUtils.crsFromCityGMLHeader(citygmlPath);
CoordinateReferenceSystem localCRS = RegionChooserUtils.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 = GeoUtils.crsFromCityGMLHeader(citygmlPath);
String localWktPolygon = WKT_WRITER.write(GeoUtils.changePolygonCRS(wgs84Polygon, GeoUtils.WGS84, localCRS));
CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
String localWktPolygon = WKT_WRITER.write(RegionChooserUtils.changePolygonCRS(wgs84Polygon, RegionChooserUtils.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 = GeoUtils.crsFromCityGMLHeader(citygmlPath);
String localWktPolygon = WKT_WRITER.write(GeoUtils.changePolygonCRS(wgs84Polygon, GeoUtils.WGS84, localCRS));
CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath);
String localWktPolygon = WKT_WRITER.write(RegionChooserUtils.changePolygonCRS(wgs84Polygon, RegionChooserUtils.WGS84, localCRS));
StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon,
localCRS.getName());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment