From 81639c5ff9b87ebfb98b1b745b37a52abb15b9b9 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Thu, 14 Mar 2024 11:23:31 -0700 Subject: [PATCH] Change JTSOp to require -q flag for no output --- .../jtstest/cmd/CommandOptions.java | 16 ++++++---- .../locationtech/jtstest/cmd/JTSOpCmd.java | 31 +++++++++++++------ .../locationtech/jtstest/cmd/JTSOpRunner.java | 9 ++++-- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/modules/app/src/main/java/org/locationtech/jtstest/cmd/CommandOptions.java b/modules/app/src/main/java/org/locationtech/jtstest/cmd/CommandOptions.java index 3c4c400675..887c1004f5 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/cmd/CommandOptions.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/cmd/CommandOptions.java @@ -30,19 +30,23 @@ public class CommandOptions { public static final String EACHA = "eacha"; public static final String EACHB = "eachb"; public static final String ARGS = "args"; - public static final String VALIDATE = "validate"; public static final String INDEX = "index"; + public static final String TIME = "time"; + public static final String LIMIT = "limit"; + public static final String OFFSET = "offset"; + public static final String QUIET = "q"; + public static final String VALIDATE = "validate"; + public static final String WHERE = "where"; + + public static final String SOURCE_STDIN = "stdin"; - public static final String STDIN = "stdin"; public static final String FORMAT_GML = "gml"; public static final String FORMAT_WKB = "wkb"; public static final String FORMAT_TXT = "txt"; public static final String FORMAT_WKT = "wkt"; public static final String FORMAT_GEOJSON = "geojson"; public static final String FORMAT_SVG = "svg"; - public static final String TIME = "time"; - public static final String LIMIT = "limit"; - public static final String OFFSET = "offset"; - public static final String WHERE = "where"; + + } diff --git a/modules/app/src/main/java/org/locationtech/jtstest/cmd/JTSOpCmd.java b/modules/app/src/main/java/org/locationtech/jtstest/cmd/JTSOpCmd.java index 29df546c81..31ba6a307e 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/cmd/JTSOpCmd.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/cmd/JTSOpCmd.java @@ -38,31 +38,35 @@ * *
  * --- Compute the area of a WKT geometry, output it
- * jtsop -a some-file-with-geom.wkt -f txt area 
+ * jtsop -a some-file-with-geom.wkt area 
  * 
  * --- Validate geometries from a WKT file using limit and offset
- * jtsop -a some-file-with-geom.wkt -limit 100 -offset 40 -f txt isValid 
+ * jtsop -a some-file-with-geom.wkt -limit 100 -offset 40 isValid 
  * 
  * --- Compute the unary union of a WKT geometry, output as WKB
  * jtsop -a some-file-with-geom.wkt -f wkb Overlay.unaryUnion 
  * 
  * --- Compute the union of two geometries in WKT and WKB, output as WKT
- * jtsop -a some-file-with-geom.wkt -b some-other-geom.wkb -f wkt Overlay.Union
+ * jtsop -a some-file-with-geom.wkt -b some-other-geom.wkb Overlay.Union
  * 
  * --- Compute the buffer of distance 10 of a WKT geometry, output as GeoJSON
  * jtsop -a some-file-with-geom.wkt -f geojson Buffer.buffer 10
  * 
  * --- Compute the buffer of a literal geometry, output as WKT
- * jtsop -a "POINT (10 10)" -f wkt Buffer.buffer 10
+ * jtsop -a "POINT (10 10)" Buffer.buffer 10
  * 
  * --- Compute buffers of multiple sizes
- * jtsop -a "POINT (10 10)" -f wkt Buffer.buffer 1,10,100
+ * jtsop -a "POINT (10 10)" Buffer.buffer 1,10,100
  * 
  * --- Run op for each A 
- * jtsop -a "MULTIPOINT ((10 10), (20 20))" -eacha -f wkt Buffer.buffer
+ * jtsop -a "MULTIPOINT ((10 10), (20 20))" -eacha Buffer.buffer
  * 
  * --- Output a literal geometry as GeoJSON
  * jtsop -a "POINT (10 10)" -f geojson
+ * 
+ * --- Run op but don't output result (quiet mode) 
+ * jtsop -a "MULTIPOINT ((10 10), (20 20))" -q Buffer.buffer
+
  * 
* * @author Martin Davis @@ -120,6 +124,7 @@ private static CommandLine createCmdLine() { .addOptionSpec(new OptionSpec(CommandOptions.LIMIT, 1)) .addOptionSpec(new OptionSpec(CommandOptions.OFFSET, 1)) .addOptionSpec(new OptionSpec(CommandOptions.REPEAT, 1)) + .addOptionSpec(new OptionSpec(CommandOptions.QUIET, 0)) .addOptionSpec(new OptionSpec(CommandOptions.SRID, 1)) .addOptionSpec(new OptionSpec(CommandOptions.WHERE, 2)) .addOptionSpec(new OptionSpec(CommandOptions.VALIDATE, 0)) @@ -145,6 +150,7 @@ private static CommandLine createCmdLine() { " [ -explode", " [ -srid SRID ]", " [ -f ( txt | wkt | wkb | geojson | gml | svg ) ]", + " [ -q", " [ -time ]", " [ -v, -verbose ]", " [ -help ]", @@ -167,14 +173,15 @@ private static CommandLine createCmdLine() { " -index index the B geometries", " -repeat repeat the operation N times", " -where op v output geometry where operation result matches predicate op and value.", - " Predicates ops are: eq,ne,ge,gt,le,lt", + " Predicates ops are: eq, ne, ge, gt, le, lt", " -validate validate the result of each operation", " -geomfunc specifies class providing geometry operations", " -op separator to delineate operation arguments", "===== Output options:", - " -srid Sets the SRID on output geometries", + " -srid sets the SRID on output geometries", " -explode output atomic geometries", - " -f output format to use. If omitted output is silent", + " -f output format to use. Default is txt/wkt", + " -q quiet mode - result is not output", "===== Logging options:", " -time display execution time", " -v, -verbose display information about execution", @@ -331,7 +338,9 @@ JTSOpRunner.OpParams parseArgs(String[] args) throws ParseException, ClassNotFou ? commandLine.getOptionArgAsInt(CommandOptions.OFFSET, 0) : 0; - cmdArgs.format = commandLine.getOptionArg(CommandOptions.FORMAT, 0); + cmdArgs.format = commandLine.hasOption(CommandOptions.FORMAT) + ? commandLine.getOptionArg(CommandOptions.FORMAT, 0) + : CommandOptions.FORMAT_TXT; cmdArgs.srid = commandLine.hasOption(CommandOptions.SRID) ? commandLine.getOptionArgAsInt(CommandOptions.SRID, 0) @@ -339,6 +348,8 @@ JTSOpRunner.OpParams parseArgs(String[] args) throws ParseException, ClassNotFou cmdArgs.isIndexed = commandLine.hasOption(CommandOptions.INDEX); + cmdArgs.isQuiet = commandLine.hasOption(CommandOptions.QUIET); + cmdArgs.repeat = commandLine.hasOption(CommandOptions.REPEAT) ? commandLine.getOptionArgAsInt(CommandOptions.REPEAT, 0) : 1; diff --git a/modules/app/src/main/java/org/locationtech/jtstest/cmd/JTSOpRunner.java b/modules/app/src/main/java/org/locationtech/jtstest/cmd/JTSOpRunner.java index 76723c6c3e..cf82f216a7 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/cmd/JTSOpRunner.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/cmd/JTSOpRunner.java @@ -95,7 +95,8 @@ static class OpParams { public boolean isGeomAB = false; public boolean isCollect = false; - String format = null; + public boolean isQuiet = false; + public String format = null; public Integer repeat; public boolean eachA = false; public boolean eachB = false; @@ -361,7 +362,9 @@ private Object executeFunctionOnce(Geometry geomA, GeometryFunction func, Object if (param.validate) { validate(result); } - outputResult(result, param.isExplode, param.format); + if (! param.isQuiet) { + outputResult(result, param.isExplode, param.format); + } return result; } @@ -430,7 +433,7 @@ private List readGeometry(String geomLabel, String filename, String ge if (filename == null) return null; // must be a filename - if (filename.equalsIgnoreCase(CommandOptions.STDIN)){ + if (filename.equalsIgnoreCase(CommandOptions.SOURCE_STDIN)){ return readStdin(limit, offset); }