Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
2e12ddb8
Commit
2e12ddb8
authored
2 years ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
It's hard to test private static final LOGGER. :-/
parent
533e5299
master
develop
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java
+11
-4
...tadt/regionchooser/RegionChooserCommandLineInterface.java
src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java
+16
-8
.../regionchooser/RegionChooserCommandLineInterfaceTest.java
with
27 additions
and
12 deletions
+27
-12
src/main/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterface.java
+
11
-
4
View file @
2e12ddb8
...
...
@@ -6,11 +6,12 @@
import
java.nio.file.Paths
;
import
java.util.Scanner
;
import
java.util.concurrent.Callable
;
import
java.util.logging.Logger
;
import
org.osgeo.proj4j.CoordinateReferenceSystem
;
import
picocli.CommandLine
;
import
picocli.CommandLine.Command
;
import
picocli.CommandLine.Model.CommandSpec
;
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
...
...
@@ -21,8 +22,10 @@
@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
>
{
@Spec
CommandSpec
spec
;
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
RegionChooserCommandLineInterface
.
class
.
getName
());
//TODO: Add --gui?
@Option
(
names
=
{
"-i"
,
"--input"
},
required
=
true
,
split
=
","
,
description
=
"Citygml files to extract from"
,
paramLabel
=
"input.gml"
)
...
...
@@ -53,7 +56,7 @@ public Integer call() throws Exception {
}
else
{
localCRS
=
RegionChooserUtils
.
crsFromSrsName
(
"EPSG:"
+
espgId
);
}
LOGGER
.
i
nfo
(
"Coordinate system: "
+
localCRS
);
logI
nfo
(
"Coordinate system: "
+
localCRS
);
String
wktPolygon
;
...
...
@@ -75,7 +78,7 @@ public Integer call() throws Exception {
wktPolygon
=
RegionChooserUtils
.
wktPolygonToLocalCRS
(
wktPolygon
,
localCRS
);
}
LOGGER
.
i
nfo
(
"WKT Polygon expressed in local coordinates: "
+
wktPolygon
);
logI
nfo
(
"WKT Polygon expressed in local coordinates: "
+
wktPolygon
);
StringBuilder
sb
=
RegionExtractor
.
selectRegionDirectlyFromCityGML
(
wktPolygon
,
localCRS
.
toString
(),
citygmls
);
...
...
@@ -84,6 +87,10 @@ public Integer call() throws Exception {
return
0
;
}
private
void
logInfo
(
String
message
)
{
spec
.
commandLine
().
getErr
().
println
(
message
);
}
private
static
String
getInput
()
{
try
(
Scanner
myObj
=
new
Scanner
(
System
.
in
))
{
return
myObj
.
nextLine
();
...
...
This diff is collapsed.
Click to expand it.
src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java
+
16
-
8
View file @
2e12ddb8
package
eu.simstadt.regionchooser
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
java.io.BufferedWriter
;
import
java.io.ByteArrayInputStream
;
...
...
@@ -43,7 +45,6 @@ public void restoreStreams() {
@Test
void
testNoInput
()
{
new
CommandLine
(
new
RegionChooserCommandLineInterface
()).
execute
(
""
);
// originalOut.println(err.toString());
String
expectedErr
=
"Missing required options: '--input=input.gml', '--output=output.gml', '--wkt=polygon.wkt'"
;
assertTrue
(
err
.
toString
().
contains
(
expectedErr
),
err
.
toString
()
+
" should contain "
+
expectedErr
);
}
...
...
@@ -58,11 +59,12 @@ void testExtractRegionFromTwoCitygmls() throws IOException {
try
(
BufferedWriter
wkt
=
Files
.
newBufferedWriter
(
inWKT
))
{
wkt
.
write
(
wktPolygon
);
}
assertFalse
(
Files
.
exists
(
outGML
));
new
CommandLine
(
new
RegionChooserCommandLineInterface
()).
execute
(
"--input="
+
citygml1
+
","
+
citygml2
,
"--output="
+
outGML
,
"--wkt="
+
inWKT
,
"--epsg=31463"
,
"--local"
);
String
expectedLog
=
"Buildings found in selected region 20"
;
assertTrue
(
err
.
toString
().
contains
(
expectedLog
),
err
.
toString
()
+
" should contain "
+
expectedLog
);
assertTrue
(
Files
.
exists
(
outGML
));
assertTrue
(
Files
.
size
(
outGML
)
>
600_000
);
assertEquals
(
20
,
countBuildings
(
outGML
));
}
...
...
@@ -76,13 +78,18 @@ void testExtractRegionFromTwoCitygmlsInWGS84() throws IOException {
try
(
BufferedWriter
wkt
=
Files
.
newBufferedWriter
(
inWKT
))
{
wkt
.
write
(
wktPolygon
);
}
assertFalse
(
Files
.
exists
(
outGML
));
new
CommandLine
(
new
RegionChooserCommandLineInterface
()).
execute
(
"--input="
+
citygml1
+
","
+
citygml2
,
"--output="
+
outGML
,
"--wkt="
+
inWKT
);
String
expectedLog
=
"EPSG:31463"
;
assertTrue
(
err
.
toString
().
contains
(
expectedLog
),
err
.
toString
()
+
" should contain "
+
expectedLog
);
expectedLog
=
"Buildings found in selected region 22"
;
assertTrue
(
err
.
toString
().
contains
(
expectedLog
),
err
.
toString
()
+
" should contain "
+
expectedLog
);
assertTrue
(
Files
.
exists
(
outGML
));
assertTrue
(
Files
.
size
(
outGML
)
>
300_000
);
assertEquals
(
22
,
countBuildings
(
outGML
));
}
private
long
countBuildings
(
Path
outGML
)
throws
IOException
{
return
Files
.
readAllLines
(
outGML
).
stream
().
filter
(
line
->
line
.
contains
(
"bldg:Building gml:id="
)).
count
();
}
@Test
...
...
@@ -92,13 +99,13 @@ void testExtractRegionWithStandardInput() throws IOException {
Path
outGML
=
Files
.
createTempFile
(
"output"
,
".gml"
);
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
,
"--wkt=-"
);
String
expectedLog
=
"EPSG:32118"
;
originalOut
.
println
(
err
.
toString
());
assertTrue
(
err
.
toString
().
contains
(
expectedLog
),
err
.
toString
()
+
" should contain "
+
expectedLog
);
expectedLog
=
"Buildings found in selected region 2"
;
assertTrue
(
err
.
toString
().
contains
(
expectedLog
),
err
.
toString
()
+
" should contain "
+
expectedLog
);
assertTrue
(
Files
.
exists
(
outGML
));
assertEquals
(
2
,
countBuildings
(
outGML
));
}
@Test
...
...
@@ -116,6 +123,7 @@ void testExtractRegionWithMissingInput() throws IOException {
assertTrue
(
err
.
toString
().
contains
(
expectedLog
),
err
.
toString
()
+
" should contain "
+
expectedLog
);
expectedLog
=
"Please provide \"POLYGON((x1 y1, x2 y2, ...))\" to standard input."
;
assertTrue
(
err
.
toString
().
contains
(
expectedLog
),
err
.
toString
()
+
" should contain "
+
expectedLog
);
assertFalse
(
Files
.
exists
(
outGML
));
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets