Package org.apache.sis.console
Class TransformCommand
java.lang.Object
org.apache.sis.console.CommandRunner
org.apache.sis.console.FormattedOutputCommand
org.apache.sis.console.TransformCommand
The "transform" subcommand.
The output is a comma separated values (CSV) file, with
'#'
as the first character of comment lines.- Since:
- 0.7
- Version:
- 0.8
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate NumberFormat
The format to use for writing coordinate values.private int
Width of coordinate values, in number of characters in coordinateString
representations.private NumberFormatException
The cause oferrorMessage
, ornull
if none.private String
The error message to report after we transformed all coordinates, ornull
.private int[]
Suggested number of fraction digits for each coordinate values.private org.opengis.referencing.operation.CoordinateOperation
The coordinate operation from the given source CRS to target CRS.private TableAppender
Where to write the header before the data.private final Vocabulary
Resources forprintHeader(short)
.private double[]
We will switch to scientific notation if the coordinate value to format is greater than this value.private org.opengis.referencing.operation.MathTransform
The transformation from source CRS to the domain of validity CRS, ornull
if none.Fields inherited from class org.apache.sis.console.FormattedOutputCommand
convention, hasUnexpectedFileCount
Fields inherited from class org.apache.sis.console.CommandRunner
colors, commandName, debug, encoding, err, files, instance, locale, options, out, outputBuffer, TEST, timezone
-
Constructor Summary
ConstructorsConstructorDescriptionTransformCommand
(int commandIndex, String... args) Creates the"transform"
sub-command. -
Method Summary
Modifier and TypeMethodDescriptionprivate org.opengis.metadata.extent.GeographicBoundingBox
computeAreaOfInterest
(List<double[]> points) Computes the geographic area of interest from the given points.private void
computeNumFractionDigits
(org.opengis.referencing.cs.CoordinateSystem cs) Computes the suggested precision for printing values in the given units.private org.opengis.referencing.crs.CoordinateReferenceSystem
Fetches the source or target coordinate reference system from the value given to the specified option.options()
Returns valid options for the"transform"
commands.private void
printAccuracy
(double accuracy) Prints the accuracy.private void
printAxes
(org.opengis.referencing.cs.CoordinateSystem cs) private void
Prints the character for commented lines.private void
Prints the coordinate operation or math transform in Well Known Text format.private void
printDomainOfValidity
(org.opengis.metadata.extent.Extent domain) Prints a textual description of the domain of validity.private void
printHeader
(short key) Prints the given string after the prefix comment.private boolean
printNameAndIdentifier
(org.opengis.referencing.IdentifiedObject object, boolean idRequired) Prints the name and authority code (if any) of the given object.private void
printOperations
(org.opengis.referencing.operation.CoordinateOperation step, boolean isNext) Prints a summary of the given coordinate operation as a sequence of steps.private void
printQuotedText
(String text, int fieldWidth, X364 color) Prints a quoted text in the given color.private List
<double[]> readCoordinates
(LineNumberReader in, String filename) Reads all coordinates.int
run()
Transforms coordinates from the files given in argument or from the standard input stream.private void
Transforms the given coordinates.private static void
Reports the given exception as an ignorable one.Methods inherited from class org.apache.sis.console.FormattedOutputCommand
format, getNodeFilter, readMetadataOrCRS
Methods inherited from class org.apache.sis.console.CommandRunner
canNotOpen, error, hasContradictoryOptions, hasUnexpectedFileCount, help, useStandardInput
-
Field Details
-
operation
private org.opengis.referencing.operation.CoordinateOperation operationThe coordinate operation from the given source CRS to target CRS. -
toDomainOfValidity
private org.opengis.referencing.operation.MathTransform toDomainOfValidityThe transformation from source CRS to the domain of validity CRS, ornull
if none. -
resources
Resources forprintHeader(short)
. -
outHeader
Where to write the header before the data. -
coordinateFormat
The format to use for writing coordinate values. -
coordinateWidth
private int coordinateWidthWidth of coordinate values, in number of characters in coordinateString
representations. -
numFractionDigits
private int[] numFractionDigitsSuggested number of fraction digits for each coordinate values. -
thresholdForScientificNotation
private double[] thresholdForScientificNotationWe will switch to scientific notation if the coordinate value to format is greater than this value. -
errorMessage
The error message to report after we transformed all coordinates, ornull
. -
errorCause
The cause oferrorMessage
, ornull
if none.
-
-
Constructor Details
-
TransformCommand
TransformCommand(int commandIndex, String... args) throws InvalidOptionException Creates the"transform"
sub-command.- Throws:
InvalidOptionException
-
-
Method Details
-
options
Returns valid options for the"transform"
commands. -
fetchCRS
private org.opengis.referencing.crs.CoordinateReferenceSystem fetchCRS(Option option) throws InvalidOptionException, org.opengis.util.FactoryException, DataStoreException Fetches the source or target coordinate reference system from the value given to the specified option.- Parameters:
option
- eitherOption.SOURCE_CRS
orOption.TARGET_CRS
.- Returns:
- the coordinate reference system for the given option.
- Throws:
InvalidOptionException
- if the given option is missing or have an invalid value.org.opengis.util.FactoryException
- if the operation failed for another reason.DataStoreException
-
run
Transforms coordinates from the files given in argument or from the standard input stream.- Specified by:
run
in classCommandRunner
- Returns:
- 0 on success, or an exit code if the command failed for a reason other than an uncaught Java exception.
- Throws:
Exception
- if an error occurred while executing the sub-command.
-
printCommentLinePrefix
private void printCommentLinePrefix()Prints the character for commented lines. -
printHeader
Prints the given string after the prefix comment. This is used for formatting some metadata in the header before to print transformed coordinates.- Parameters:
key
- aVocabulary.Keys
constant for the header to print.- Throws:
IOException
-
printNameAndIdentifier
private boolean printNameAndIdentifier(org.opengis.referencing.IdentifiedObject object, boolean idRequired) Prints the name and authority code (if any) of the given object.- Parameters:
object
- the object for which to print name and identifier.idRequired
-true
for printing the name only if an identifier is present.- Returns:
- whether this method has printed something.
-
printOperations
private void printOperations(org.opengis.referencing.operation.CoordinateOperation step, boolean isNext) Prints a summary of the given coordinate operation as a sequence of steps. If the operations is specified by EPSG, prints the EPSG name and code. Otherwise prints only the operation method names, since the coordinate operation names generated by SIS are not very meaningful.- Parameters:
step
- the coordinate operation to print as a sequence of steps.
-
printAccuracy
Prints the accuracy.- Throws:
IOException
-
printDomainOfValidity
Prints a textual description of the domain of validity. This method tries to reduce the string length by the use of some heuristic rules based on the syntax used in EPSG dataset. For example the following string:Canada - onshore and offshore - Alberta; British Columbia (BC); Manitoba; New Brunswick (NB); Newfoundland and Labrador; Northwest Territories (NWT); Nova Scotia (NS); Nunavut; Ontario; Prince Edward Island (PEI); Quebec; Saskatchewan; Yukon.
is replaced by:Canada - onshore and offshore
- Throws:
IOException
-
printDetails
Prints the coordinate operation or math transform in Well Known Text format. This information is printed only if the--verbose
option was specified.- Throws:
IOException
-
printQuotedText
Prints a quoted text in the given color. If the given text contains the quote character, it will be escaped. -
printAxes
private void printAxes(org.opengis.referencing.cs.CoordinateSystem cs) -
computeNumFractionDigits
private void computeNumFractionDigits(org.opengis.referencing.cs.CoordinateSystem cs) throws javax.measure.IncommensurableException Computes the suggested precision for printing values in the given units.- Throws:
javax.measure.IncommensurableException
- should never happen.
-
readCoordinates
Reads all coordinates. This method ignores empty and comment lines.- Parameters:
in
- the stream from where to read coordinates.filename
- the filename, for error reporting only.- Returns:
- the coordinate values.
- Throws:
IOException
-
computeAreaOfInterest
private org.opengis.metadata.extent.GeographicBoundingBox computeAreaOfInterest(List<double[]> points) Computes the geographic area of interest from the given points. This method ignores the points having an unexpected number of dimensions since it is not this method's job to report those issues (they will be reported bytransform(List)
instead. -
transform
private void transform(List<double[]> points) throws org.opengis.referencing.operation.TransformException Transforms the given coordinates.- Throws:
org.opengis.referencing.operation.TransformException
-
warning
Reports the given exception as an ignorable one. We considerFactoryException
orTransformException
as ignorable exceptions only if they occurred while computing whether a point is inside the domain of validity. Failure to answer that question is considered as an indication that the point is outside the domain of validity.
-