diff --git a/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java b/src/main/java/eu/simstadt/regionchooser/RegionChooserCLI.java similarity index 73% rename from src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java rename to src/main/java/eu/simstadt/regionchooser/RegionChooserCLI.java index 9c462faba9d40813e2d2cb5ccc8c80e7d92b749a..7ed10b30eeff7a5c904c87b4eccd074d4f095e0e 100644 --- a/src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java +++ b/src/main/java/eu/simstadt/regionchooser/RegionChooserCLI.java @@ -13,14 +13,34 @@ import picocli.CommandLine.Option; import picocli.CommandLine.Spec; -// Example usage: -// --input /home/ricou/Desktop/CGSC_Repository/Würzburg.proj/LoD2_566_5516_2_BY.gml,/home/ricou/Desktop/CGSC_Repository/Würzburg.proj/LoD2_568_5516_2_BY.gml -// --output /home/ricou/Desktop/output.gml -// --wkt /home/ricou/Desktop/grombuhl.txt + +/** + * Command Line Interface for RegionChooser. Could be useful to extract large regions on server, or automate the process + * from batch/python scripts. + * + */ + +// Usage: region_chooser [-hlV] [-e=31467] -o=output.gml -w=polygon.wkt -i=input. +// gml[,input.gml...] [-i=input.gml[,input.gml...]]... +// Extracts a region from one or more citygmls. +// -i, --input=input.gml[,input.gml...] +// Citygml files to extract from +// -o, --output=output.gml Output file +// -e, --epsg=31467 EPSG id for coordinate reference system +// -l, --local Are WKT coordinates in local CRS? +// -w, --wkt=polygon.wkt File containing WKT polygon, or - for stdin +// -h, --help Show this help message and exit. +// -V, --version Print version information and exit. + + +// Example: +// --input CGSC_Repository/Würzburg.proj/LoD2_566_5516_2_BY.gml,CGSC_Repository/Würzburg.proj/LoD2_568_5516_2_BY.gml +// --output ./output.gml +// --wkt ./grombuhl.txt @Command(name = "region_chooser", mixinStandardHelpOptions = true, version = "regionChooser x.x", description = "Extracts a region from one or more citygmls.", sortOptions = false) -class RegionChooserCommandLineInterface implements Callable<Integer> +class RegionChooserCLI implements Callable<Integer> { @Spec CommandSpec spec; @@ -100,7 +120,7 @@ private static String getInput() { // this example implements Callable, so parsing, error handling and handling user // requests for usage help or version help can be done with one line of code. public static void main(String... args) { - int exitCode = new CommandLine(new RegionChooserCommandLineInterface()).execute(args); + int exitCode = new CommandLine(new RegionChooserCLI()).execute(args); System.exit(exitCode); } } \ No newline at end of file diff --git a/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java b/src/test/java/eu/simstadt/regionchooser/RegionChooserTests.java similarity index 78% rename from src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java rename to src/test/java/eu/simstadt/regionchooser/RegionChooserTests.java index 4fec364f0692948da77cbfb2eaf6b158bedc6928..92d585247e744a04dcc85840d173d6fa1d262076 100644 --- a/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java +++ b/src/test/java/eu/simstadt/regionchooser/RegionChooserTests.java @@ -20,7 +20,7 @@ import picocli.CommandLine; -class RegionChooserCommandLineInterfaceTest +class RegionChooserTests { final PrintStream originalOut = System.out; final PrintStream originalErr = System.err; @@ -52,7 +52,7 @@ public void restore() throws IOException { @Test void testNoInput() { - new CommandLine(new RegionChooserCommandLineInterface()).execute(""); + new CommandLine(new RegionChooserCLI()).execute(""); String expectedErr = "Missing required options: '--input=input.gml', '--output=output.gml', '--wkt=polygon.wkt'"; assertTrue(err.toString().contains(expectedErr), err.toString() + " should contain " + expectedErr); } @@ -67,7 +67,7 @@ void testExtractRegionFromTwoCitygmls() throws IOException { wkt.write(wktPolygon); } assertFalse(Files.exists(outGML)); - new CommandLine(new RegionChooserCommandLineInterface()).execute("--input=" + citygml1 + "," + citygml2, + new CommandLine(new RegionChooserCLI()).execute("--input=" + citygml1 + "," + citygml2, "--output=" + outGML, "--wkt=" + inWKT, "--epsg=31463", "--local"); assertTrue(Files.exists(outGML)); assertTrue(Files.size(outGML) > 600_000); @@ -85,7 +85,7 @@ void testExtractRegionFromTwoCitygmlsInWGS84() throws IOException { wkt.write(wktPolygon); } assertFalse(Files.exists(outGML)); - new CommandLine(new RegionChooserCommandLineInterface()).execute("--input=" + citygml1 + "," + citygml2, + new CommandLine(new RegionChooserCLI()).execute("--input=" + citygml1 + "," + citygml2, "--output=" + outGML, "--wkt=" + inWKT); String expectedLog = "EPSG:31463"; assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); @@ -105,7 +105,7 @@ void testExtractRegionWithStandardInput() throws IOException { InputStream stdin = new ByteArrayInputStream(wktPolygon.getBytes(StandardCharsets.UTF_8)); System.setIn(stdin); assertFalse(Files.exists(outGML)); - new CommandLine(new RegionChooserCommandLineInterface()).execute("--input=" + citygml, "--output=" + outGML, + new CommandLine(new RegionChooserCLI()).execute("--input=" + citygml, "--output=" + outGML, "--wkt=-"); String expectedLog = "EPSG:32118"; assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); @@ -113,21 +113,6 @@ void testExtractRegionWithStandardInput() throws IOException { assertEquals(2, countBuildings(outGML)); } - @Test - void testExtractRegionWithStandardInputAndStandardOutput() throws IOException { - String wktPolygon = "POLYGON((-73.9959209576448 40.73286384885367, -73.996317924579 40.732359794090684, -73.9947515145143 40.7315061442504, -73.99422580154739 40.73214841515045, -73.9959209576448 40.73286384885367))"; - Path citygml = TEST_REPOSITORY.resolve("NewYork.proj/ManhattanSmall.gml"); - InputStream stdin = new ByteArrayInputStream(wktPolygon.getBytes(StandardCharsets.UTF_8)); - System.setIn(stdin); - new CommandLine(new RegionChooserCommandLineInterface()).execute("--input=" + citygml, "--output=-", "--wkt=-"); - String expectedLog = "EPSG:32118"; - assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); - originalOut.println(err.toString()); - originalOut.println("--------------------"); - originalOut.println(out.toString()); - assertFalse(Files.exists(Paths.get("-"))); - } - @Test void testExtractRegionWithMissingInput() throws IOException { String wktPolygon = "POLYGON((-73.9959209576448 40.73286384885367, -73.996317924579 40.732359794090684, -73.9947515145143 40.7315061442504, -73.99422580154739 40.73214841515045, -73.9959209576448 40.73286384885367))"; @@ -136,7 +121,7 @@ void testExtractRegionWithMissingInput() throws IOException { try (BufferedWriter wkt = Files.newBufferedWriter(inWKT)) { wkt.write(wktPolygon); } - new CommandLine(new RegionChooserCommandLineInterface()).execute("--input=" + citygml, "--output=" + outGML, + new CommandLine(new RegionChooserCLI()).execute("--input=" + citygml, "--output=" + outGML, "--wkt=-"); String expectedLog = "EPSG:32118"; assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog);