Commit 0711c3e9 authored by Eric Duminil's avatar Eric Duminil
Browse files

Try stdout anyway.

Not sure it works.
parent 19ac5537
package eu.simstadt.regionchooser; package eu.simstadt.regionchooser;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
...@@ -102,11 +103,21 @@ public Integer call() throws Exception { ...@@ -102,11 +103,21 @@ public Integer call() throws Exception {
logInfo("WKT Polygon expressed in local coordinates: " + wktPolygon); logInfo("WKT Polygon expressed in local coordinates: " + wktPolygon);
try (BufferedWriter gmlWriter = Files.newBufferedWriter(outputCityGML)) { int count;
int count = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, localCRS.toString(), gmlWriter, citygmls);
logInfo("Found buildings : " + count); if (outputCityGML.toString().equals("-")) {
logInfo("CityGML written to stdout.");
PrintWriter stdOut = spec.commandLine().getOut();
count = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, localCRS.toString(), stdOut, citygmls);
} else {
try (BufferedWriter gmlWriter = Files.newBufferedWriter(outputCityGML)) {
count = RegionExtractor.selectRegionDirectlyFromCityGML(wktPolygon, localCRS.toString(), gmlWriter,
citygmls);
}
} }
logInfo("Found buildings : " + count);
return 0; return 0;
} }
......
...@@ -109,6 +109,24 @@ void testExtractRegionWithStandardInput() throws IOException { ...@@ -109,6 +109,24 @@ void testExtractRegionWithStandardInput() throws IOException {
assertEquals(2, countBuildings(outGML)); assertEquals(2, countBuildings(outGML));
} }
@Test
void testExtractRegionWithStandardInputAndStandardOutput() throws IOException {
String wktPolygon = "POLYGON((-73.99325421344473 40.730897087489666, -73.99359753619864 40.7304702545556, -73.99287870418264 40.7300800049056, -73.99244955074026 40.730592207101864, -73.99325421344473 40.730897087489666))";
Path citygml = TEST_REPOSITORY.resolve("NewYork.proj/ManhattanSmall.gml");
InputStream stdin = new ByteArrayInputStream(wktPolygon.getBytes(StandardCharsets.UTF_8));
System.setIn(stdin);
Path noOutput = Paths.get("-");
Files.deleteIfExists(noOutput);
assertFalse(Files.exists(noOutput));
new CommandLine(new RegionChooserCLI()).execute("--input=" + citygml, "--output=-", "--wkt=-");
String expectedLog = "EPSG:32118";
assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog);
String expectedBuilding = "uuid_0547df65-ae80-459e-bb15-c839c1a2e566";
assertTrue(out.toString().contains(expectedBuilding), out.toString() + " should contain " + expectedBuilding);
//TODO: Check if footer is here too
assertFalse(Files.exists(noOutput));
}
@Test @Test
void testExtractRegionWithMissingInput() throws IOException { 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))"; String wktPolygon = "POLYGON((-73.9959209576448 40.73286384885367, -73.996317924579 40.732359794090684, -73.9947515145143 40.7315061442504, -73.99422580154739 40.73214841515045, -73.9959209576448 40.73286384885367))";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment