From 3096e1c7efb15fc4889a15998291ab4da53ded0f Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Fri, 7 Oct 2022 17:32:12 +0200 Subject: [PATCH] Allow local coordinates --- .../RegionChooserCommandLineInterface.java | 19 +++++++++++++------ .../regionchooser/RegionChooserUtils.java | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java b/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java index 111371a..fb6469c 100644 --- a/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java +++ b/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java @@ -6,6 +6,7 @@ import java.nio.file.Paths; import java.util.Scanner; import java.util.concurrent.Callable; +import org.osgeo.proj4j.CoordinateReferenceSystem; import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Option; @@ -25,7 +26,9 @@ class RegionChooserCommandLineInterface implements Callable<Integer> @Option(names = { "-e", "--epsg" }, description = "EPSG id for coordinate reference system", paramLabel = "31467") Integer espgId; - //TODO: Add possibility to choose wgs84 or local_crs + @Option(names = { "-l", + "--local" }, description = "Are WKT coordinates in local CRS?", paramLabel = "local_coordinates?") + boolean localCoordinates; @Option(names = { "-w", "--wkt" }, description = "File containing WKT polygon, or - for stdin", paramLabel = "polygon.wkt") @@ -33,15 +36,15 @@ class RegionChooserCommandLineInterface implements Callable<Integer> @Override public Integer call() throws Exception { - String srsName; + CoordinateReferenceSystem localCRS; if (espgId == null) { - srsName = RegionChooserUtils.crsFromCityGMLHeader(citygmls[0]).toString(); + localCRS = RegionChooserUtils.crsFromCityGMLHeader(citygmls[0]); } else { - srsName = "EPSG:" + espgId; + localCRS = RegionChooserUtils.crsFromSrsName("EPSG:" + espgId); } - String wktPolygon = "unknown"; + String wktPolygon; if (wktFile.equals("-")) { if (System.in.available() == 0) { @@ -56,9 +59,13 @@ public Integer call() throws Exception { } } + if (!localCoordinates) { + // WKT coordinates are in WGS84, so should be first converted to srsName + } + System.out.println("WKT Polygon : " + wktPolygon); - StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, srsName, citygmls); + StringBuilder sb = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, localCRS.toString(), citygmls); RegionChooserUtils.writeStringBuilderToFile(sb, outputCityGML); diff --git a/src/main/java/eu/simstadt/regionchooser/RegionChooserUtils.java b/src/main/java/eu/simstadt/regionchooser/RegionChooserUtils.java index 54c54bf..71e87b4 100644 --- a/src/main/java/eu/simstadt/regionchooser/RegionChooserUtils.java +++ b/src/main/java/eu/simstadt/regionchooser/RegionChooserUtils.java @@ -47,7 +47,7 @@ private RegionChooserUtils() { * @param srsName * @return CoordinateReferenceSystem */ - private static CoordinateReferenceSystem crsFromSrsName(String srsName) { + public static CoordinateReferenceSystem crsFromSrsName(String srsName) { // EPSG:31467 Pattern pEPSG = Pattern.compile("^(EPSG:\\d+)$"); Matcher mEPSG = pEPSG.matcher(srsName); -- GitLab