package eu.simstadt.regionchooser; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.file.Path; import java.nio.file.Paths; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.jupiter.api.Test; class RegionExtractorTests { private static final String EPSG_32118 = "EPSG:32118"; private static final String CITY_OBJECT_MEMBER_REGEX = "<(core:)?cityObjectMember"; private static final String CITY_MODEL_HEADER = ""), "The exported CityGML should contain a new envelope with the correct EPSG"); assertTrue(churchGMLString.contains("3515829.0815150724 5415766.204935087 "), "The exported CityGML should contain a new envelope"); assertTrue(churchGMLString.contains("3515876.489172751 5415823.108586172 "), "The exported CityGML should contain a new envelope"); } @Test void testExtractBuildingsWithCommentsInBetween() throws Throwable { String wktPolygon = "POLYGON((300259.78663489706 62835.835907766595,300230.33294975647 62792.0482567884,300213.5667431851 62770.83143720031,300183.6592861123 62730.20347659383,300252.9947486632 62676.938468840905,300273.3862256562 62701.767105345614,300257.5250407747 62715.760413539596,300308.2754543957 62805.14198211394,300259.78663489706 62835.835907766595))"; Path citygmlPath = TEST_REPOSITORY.resolve("NewYork.proj/ManhattanSmall.gml"); String archGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath) .toString(); assertEquals(countRegexMatches(archGMLString, CITY_OBJECT_MEMBER_REGEX), 2); assertTrue(archGMLString.contains("WASHINGTON SQUARE")); assertTrue(archGMLString.contains("uuid_c0980a6e-05ea-4d09-bc83-efab226945a1")); assertTrue(archGMLString.contains("uuid_0985cebb-922d-4b3e-95e5-15dc6089cd28")); assertTrue(archGMLString.contains(CITY_MODEL_HEADER)); assertTrue(archGMLString.contains(CITY_MODEL_FOOTER)); } @Test void testExtractBuildingsAndChangeEnvelope() throws Throwable { String wktPolygon = "POLYGON((299761.8123557725 61122.68126771413,299721.46983062755 61058.11626595352,299780.84627343423 61021.99295737501,299823.9079725632 61083.3979344517,299761.8123557725 61122.68126771413))"; Path citygmlPath = TEST_REPOSITORY.resolve("NewYork.proj/FamilyCourt_LOD2_with_PLUTO_attributes.gml"); String familyCourtBuilding = RegionExtractor .selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath).toString(); assertEquals(1, countRegexMatches(familyCourtBuilding, CITY_OBJECT_MEMBER_REGEX)); assertTrue(familyCourtBuilding.contains("Bldg_12210021066")); assertFalse( familyCourtBuilding.contains( "298393.46959639067 59277.34021543693 -11.892070104139751"), "The exported CityGML shouldn't contain the original envelope"); assertFalse( familyCourtBuilding.contains( "305641.79529639013 67101.44881543722 547.7591871983744"), "The exported CityGML shouldn't contain the original envelope"); assertTrue(familyCourtBuilding.contains("299721.46983062755 61021.99295737501 -11.89"), "The exported CityGML should contain a new envelope with the original altitudes"); assertTrue(familyCourtBuilding.contains("299823.9079725632 61122.68126771413 547.75"), "The exported CityGML should contain a new envelope with the original altitudes"); assertTrue(familyCourtBuilding.contains(""), "The exported CityGML should contain a new envelope with the correct EPSG"); } @Test void testExtract0BuildingsWithWrongCoordinates() throws Throwable { //NOTE: Small region, far away from NYC String wktPolygon = "POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))"; Path citygmlPath = TEST_REPOSITORY.resolve("NewYork.proj/ManhattanSmall.gml"); String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath) .toString(); assertEquals(0, countRegexMatches(emptyGMLString, CITY_OBJECT_MEMBER_REGEX)); assertTrue(emptyGMLString.contains(CITY_MODEL_HEADER)); assertTrue(emptyGMLString.contains(CITY_MODEL_FOOTER)); } @Test void testExtract0BuildingsFromEmptyGML() throws Throwable { //NOTE: Small region, with too many spaces between coordinates String wktPolygon = "POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))"; Path citygmlPath = TEST_REPOSITORY.resolve("NewYork.proj/empty_model.gml"); String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath) .toString(); assertEquals(0, countRegexMatches(emptyGMLString, CITY_OBJECT_MEMBER_REGEX)); assertTrue(emptyGMLString.contains(CORE_CITY_MODEL_HEADER)); assertTrue(emptyGMLString.contains(CORE_CITY_MODEL_FOOTER)); } @Test void testExtract0BuildingsFromWeirdGML() throws Throwable { //NOTE: Small region, with too many spaces between coordinates String wktPolygon = "POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))"; Path citygmlPath = TEST_REPOSITORY.resolve("NewYork.proj/broken_nyc_lod2.gml"); String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath) .toString(); assertEquals(0, countRegexMatches(emptyGMLString, CITY_OBJECT_MEMBER_REGEX)); assertTrue(emptyGMLString.contains(CORE_CITY_MODEL_HEADER)); assertTrue(emptyGMLString.contains(CORE_CITY_MODEL_FOOTER)); } @Test void testExtractBuildingsFromCitygmlWithoutZinEnvelope() throws Throwable { String wktPolygon = "POLYGON((3512683.1280912133 5404783.732132129,3512719.1608604863 5404714.627650777,3512831.40076119 5404768.344155442,3512790.239106708 5404838.614891164,3512683.1280912133 5404783.732132129))"; Path citygmlPath = TEST_REPOSITORY.resolve("Stuttgart.proj/Stuttgart_LOD0_LOD1_small.gml"); String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, "EPSG:31463", citygmlPath) .toString(); assertEquals(2, countRegexMatches(emptyGMLString, "