From 3a9b7c9d56078336a22933b41da64ea22ded3175 Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Thu, 29 Sep 2022 10:20:24 +0200 Subject: [PATCH] Small refactor. --- .../regionchooser/RegionChooserBrowser.java | 4 ++-- .../eu/simstadt/regionchooser/RegionExtractor.java | 12 ++++++------ .../regionchooser/RegionExtractorTests.java | 14 +++++++------- .../RegionExtractorWithDifferentInputTests.java | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/eu/simstadt/regionchooser/RegionChooserBrowser.java b/src/main/java/eu/simstadt/regionchooser/RegionChooserBrowser.java index ae6f025..ae17d79 100644 --- a/src/main/java/eu/simstadt/regionchooser/RegionChooserBrowser.java +++ b/src/main/java/eu/simstadt/regionchooser/RegionChooserBrowser.java @@ -71,8 +71,8 @@ public Void call() throws IOException { public void downloadRegionFromCityGML(String wktPolygon, String project, String citygml, String srsName) throws IOException, ParseException, XPathParseException, NavException, XPathEvalException { - StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath(project, citygml), wktPolygon, - srsName); + StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, srsName, + citygmlPath(project, citygml)); File buildingIdsFile = selectSaveFileWithDialog(project, citygml, "selected_region"); if (buildingIdsFile != null) { diff --git a/src/main/java/eu/simstadt/regionchooser/RegionExtractor.java b/src/main/java/eu/simstadt/regionchooser/RegionExtractor.java index b1da076..47378a7 100644 --- a/src/main/java/eu/simstadt/regionchooser/RegionExtractor.java +++ b/src/main/java/eu/simstadt/regionchooser/RegionExtractor.java @@ -31,11 +31,11 @@ * same coordinate system as the CityGML), it iterates over each Building and checks if the building is inside the * geometry. It only works with CityGML files smaller than 2GB. It uses VTD-XML parser instead of a whole * Simstadt/Citydoctor/Citygml model. - * - * - * @param citygmlPath * @param wktPolygon + * @param citygmlPath * @param string + * + * * @return a StringBuffer, full with the extracted Citygml, including header, buildings and footer. * @throws ParseException * @throws IOException @@ -44,9 +44,9 @@ * @throws XPathParseException * @throws NumberFormatException */ - static StringBuilder selectRegionDirectlyFromCityGML(Path citygmlPath, String wktPolygon, String srsName) - throws ParseException, XPathParseException, NavException, XPathEvalException, - IOException { + //TODO: Try with multiple paths + static StringBuilder selectRegionDirectlyFromCityGML(String wktPolygon, String srsName, Path citygmlPath) + throws ParseException, XPathParseException, NavException, IOException { int buildingsCount = 0; int foundBuildingsCount = 0; diff --git a/src/test/java/eu/simstadt/regionchooser/RegionExtractorTests.java b/src/test/java/eu/simstadt/regionchooser/RegionExtractorTests.java index fbe5ed6..29a2dbb 100644 --- a/src/test/java/eu/simstadt/regionchooser/RegionExtractorTests.java +++ b/src/test/java/eu/simstadt/regionchooser/RegionExtractorTests.java @@ -35,7 +35,7 @@ public void testExtract3BuildingsFromGSK3Model() throws Throwable { //NOTE: Small region around Martinskirche in Grünbühl String wktPolygon = "POLYGON((3515848.896028535 5415823.108586172,3515848.9512289143 5415803.590347393,3515829.0815150724 5415803.338023346,3515830.9784850604 5415793.437034622,3515842.0946056456 5415793.272282251,3515843.3515515197 5415766.204935087,3515864.1064344468 5415766.557899496,3515876.489172751 5415805.433782301,3515876.343844858 5415822.009293416,3515848.896028535 5415823.108586172))"; Path citygmlPath = TEST_REPOSITORY.resolve("Gruenbuehl.proj/20140218_Gruenbuehl_LOD2.gml"); - String churchGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, "EPSG:31467") + String churchGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, "EPSG:31467", citygmlPath) .toString(); assertEquals(3, countRegexMatches(churchGMLString, CITY_OBJECT_MEMBER_REGEX)); assertTrue(churchGMLString.contains("Donaustr")); @@ -57,7 +57,7 @@ public void testExtractBuildingsWithoutCommentsInBetween() throws Throwable { //NOTE: Small region around WashingtonSquare 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(citygmlPath, wktPolygon, EPSG_32118) + String archGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath) .toString(); assertEquals(countRegexMatches(archGMLString, CITY_OBJECT_MEMBER_REGEX), 2); assertTrue(archGMLString.contains("WASHINGTON SQUARE")); @@ -76,7 +76,7 @@ public 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(citygmlPath, wktPolygon, EPSG_32118).toString(); + .selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath).toString(); assertEquals(1, countRegexMatches(familyCourtBuilding, CITY_OBJECT_MEMBER_REGEX)); assertTrue(familyCourtBuilding.contains("Bldg_12210021066")); assertFalse( @@ -100,7 +100,7 @@ public 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(citygmlPath, wktPolygon, EPSG_32118) + String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath) .toString(); assertEquals(0, countRegexMatches(emptyGMLString, CITY_OBJECT_MEMBER_REGEX)); assertTrue(emptyGMLString.contains(CITY_MODEL_HEADER)); @@ -112,7 +112,7 @@ public 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(citygmlPath, wktPolygon, EPSG_32118) + String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath) .toString(); assertEquals(0, countRegexMatches(emptyGMLString, CITY_OBJECT_MEMBER_REGEX)); assertTrue(emptyGMLString.contains(CORE_CITY_MODEL_HEADER)); @@ -124,7 +124,7 @@ public 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(citygmlPath, wktPolygon, EPSG_32118) + String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, EPSG_32118, citygmlPath) .toString(); assertEquals(0, countRegexMatches(emptyGMLString, CITY_OBJECT_MEMBER_REGEX)); assertTrue(emptyGMLString.contains(CORE_CITY_MODEL_HEADER)); @@ -135,7 +135,7 @@ public void testExtract0BuildingsFromWeirdGML() throws Throwable { public 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(citygmlPath, wktPolygon, "EPSG:31463") + String emptyGMLString = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, "EPSG:31463", citygmlPath) .toString(); assertEquals(2, countRegexMatches(emptyGMLString, "<bldg:Building gml:id")); } diff --git a/src/test/java/eu/simstadt/regionchooser/RegionExtractorWithDifferentInputTests.java b/src/test/java/eu/simstadt/regionchooser/RegionExtractorWithDifferentInputTests.java index 08379e4..47bd647 100644 --- a/src/test/java/eu/simstadt/regionchooser/RegionExtractorWithDifferentInputTests.java +++ b/src/test/java/eu/simstadt/regionchooser/RegionExtractorWithDifferentInputTests.java @@ -34,7 +34,7 @@ public void testExtractRegionWithLocalCRS() Path citygmlPath = project.resolve(citygml); CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath); - StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, wktPolygon, localCRS.getName()); + StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, localCRS.getName(), citygmlPath); assertTrue(sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"), "One weird shaped roof should be inside the region"); } @@ -53,8 +53,8 @@ public void testExtractRegionWithWGS84() CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath); String localWktPolygon = WKT_WRITER .write(RegionChooserUtils.changePolygonCRS(wgs84Polygon, RegionChooserUtils.WGS84, localCRS)); - StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon, - localCRS.getName()); + StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(localWktPolygon, localCRS.getName(), + citygmlPath); assertTrue(sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"), "One weird shaped roof should be inside the region"); } @@ -102,8 +102,8 @@ public void testExtractRegionWithOldCoordinates() CoordinateReferenceSystem localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmlPath); String localWktPolygon = WKT_WRITER .write(RegionChooserUtils.changePolygonCRS(wgs84Polygon, RegionChooserUtils.WGS84, localCRS)); - StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(citygmlPath, localWktPolygon, - localCRS.getName()); + StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(localWktPolygon, localCRS.getName(), + citygmlPath); assertTrue(sb.toString().contains("gml_ZVHMQQ6BZGRT0O3Q6RGXF12BDOV49QIZ58XB"), "One weird shaped roof should be inside the region"); -- GitLab