package eu.simstadt.geo.fast_xml_parser; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Point; import eu.simstadt.geo.GeoUtils; public class ConvexHullCalculatorTests { private static final GeometryFactory gf = new GeometryFactory(); private static final Path repository = Paths.get("../RegionChooser/test/testdata"); @Test public void testExtractConvexHullFromOneBuilding() throws Throwable { Path citygmlPath = repository.resolve("20140218_Gruenbuehl_LOD2_1building.gml"); Geometry hull = ConvexHullCalculator.calculateFromCityGML(citygmlPath); assertEquals(hull.getCoordinates().length, 4 + 1); // Convex hull of a building should be a closed rectangle Point someBuildingPoint = gf.createPoint(new Coordinate(9.216845, 48.878196)); // WGS84 assertTrue("Hull should contain every building point", hull.contains(someBuildingPoint)); } @Test public void testExtractConvexHullFromOneSmallRegion() throws Throwable { Path citygmlPath = repository.resolve("Gruenbuehl_LOD2_ALKIS_1010.gml"); Geometry hull = ConvexHullCalculator.calculateFromCityGML(citygmlPath); assertTrue(hull.getCoordinates().length > 4); // Convex hull should have at least 4 corners // Point somewhereBetweenBuildings = gf.createPoint(new Coordinate(3515883.6668538367, 5415843.300640578)); // Original coordinates, GSK3 Point somewhereBetweenBuildings = gf.createPoint(new Coordinate(9.21552249084, 48.87980446)); // WGS84 assertTrue("Hull should contain region between buildings", hull.contains(somewhereBetweenBuildings)); } @Test public void testExtractConvexHullFromStoeckachNoBuildingPart() throws Throwable { Path citygmlPath = repository.resolve("Stöckach_überarbeitete GML-NoBuildingPart.gml"); Geometry hull = ConvexHullCalculator.calculateFromCityGML(citygmlPath); assertTrue(hull.getCoordinates().length > 4); // Convex hull should have at least 4 corners Point somewhereBetweenBuildings = gf.createPoint(new Coordinate(9.195212, 48.789062)); // WGS84 assertTrue("Hull should contain region between buildings", hull.contains(somewhereBetweenBuildings)); } @Test public void testExtractConvexHullFromEveryCitygmlInRepository() throws Throwable { int minHullCount = 7; //NOTE: Should cache be deleted first? // Files.walk(repository.resolve(".cache/hulls"), 1).forEach(System.out::println); long gmlCount = GeoUtils.everyCityGML(repository).count(); AtomicInteger hullCount = new AtomicInteger(0); ConvexHullCalculator.extractHullsForEveryCityGML(repository, kmlHull -> { assertTrue("KML hull should contain project name", kmlHull.contains("Data name=\"project\"")); assertTrue("KML hull should contain srs name", kmlHull.contains("Data name=\"srsName\"")); assertTrue("KML hull should contain epsg id", kmlHull.contains("EPSG:")); assertTrue("KML hull should contain coordinates", kmlHull.contains("")); hullCount.getAndIncrement(); }); assertTrue("At least " + minHullCount + " citygmls should be present in repository", gmlCount >= minHullCount); assertTrue("At least " + minHullCount + " hulls should have been calculated", hullCount.get() >= minHullCount); } }