Skip to content

Commit

Permalink
Change JTSOp to require -q flag for no output
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Mar 14, 2024
1 parent 608dcd6 commit 81639c5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";



}
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,35 @@
*
* <pre>
* --- 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
* </pre>
*
* @author Martin Davis
Expand Down Expand Up @@ -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))
Expand All @@ -145,6 +150,7 @@ private static CommandLine createCmdLine() {
" [ -explode",
" [ -srid SRID ]",
" [ -f ( txt | wkt | wkb | geojson | gml | svg ) ]",
" [ -q",
" [ -time ]",
" [ -v, -verbose ]",
" [ -help ]",
Expand All @@ -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",
Expand Down Expand Up @@ -331,14 +338,18 @@ 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)
: -1;

cmdArgs.isIndexed = commandLine.hasOption(CommandOptions.INDEX);

cmdArgs.isQuiet = commandLine.hasOption(CommandOptions.QUIET);

cmdArgs.repeat = commandLine.hasOption(CommandOptions.REPEAT)
? commandLine.getOptionArgAsInt(CommandOptions.REPEAT, 0)
: 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -430,7 +433,7 @@ private List<Geometry> 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);
}

Expand Down

0 comments on commit 81639c5

Please sign in to comment.