Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
476042e0
Commit
476042e0
authored
Oct 11, 2022
by
Eric Duminil
Browse files
No stdout for now.
parent
4a460949
Pipeline
#6951
failed with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/eu/simstadt/regionchooser/RegionChooserC
ommandLineInterface
.java
→
src/main/java/eu/simstadt/regionchooser/RegionChooserC
LI
.java
View file @
476042e0
...
...
@@ -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
RegionChooserC
ommandLineInterface
implements
Callable
<
Integer
>
class
RegionChooserC
LI
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
RegionChooserC
ommandLineInterface
()).
execute
(
args
);
int
exitCode
=
new
CommandLine
(
new
RegionChooserC
LI
()).
execute
(
args
);
System
.
exit
(
exitCode
);
}
}
\ No newline at end of file
src/test/java/eu/simstadt/regionchooser/RegionChooser
CommandLineInterface
Test.java
→
src/test/java/eu/simstadt/regionchooser/RegionChooserTest
s
.java
View file @
476042e0
...
...
@@ -20,7 +20,7 @@
import
picocli.CommandLine
;
class
RegionChooser
CommandLineInterface
Test
class
RegionChooserTest
s
{
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
RegionChooserC
ommandLineInterface
()).
execute
(
""
);
new
CommandLine
(
new
RegionChooserC
LI
()).
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
RegionChooserC
ommandLineInterface
()).
execute
(
"--input="
+
citygml1
+
","
+
citygml2
,
new
CommandLine
(
new
RegionChooserC
LI
()).
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
RegionChooserC
ommandLineInterface
()).
execute
(
"--input="
+
citygml1
+
","
+
citygml2
,
new
CommandLine
(
new
RegionChooserC
LI
()).
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
RegionChooserC
ommandLineInterface
()).
execute
(
"--input="
+
citygml
,
"--output="
+
outGML
,
new
CommandLine
(
new
RegionChooserC
LI
()).
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
RegionChooserC
ommandLineInterface
()).
execute
(
"--input="
+
citygml
,
"--output="
+
outGML
,
new
CommandLine
(
new
RegionChooserC
LI
()).
execute
(
"--input="
+
citygml
,
"--output="
+
outGML
,
"--wkt=-"
);
String
expectedLog
=
"EPSG:32118"
;
assertTrue
(
err
.
toString
().
contains
(
expectedLog
),
err
.
toString
()
+
" should contain "
+
expectedLog
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment