Class TransformCommand


final class TransformCommand extends FormattedOutputCommand
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 Details

    • operation

      private org.opengis.referencing.operation.CoordinateOperation operation
      The coordinate operation from the given source CRS to target CRS.
    • toDomainOfValidity

      private org.opengis.referencing.operation.MathTransform toDomainOfValidity
      The transformation from source CRS to the domain of validity CRS, or null if none.
    • resources

      private final Vocabulary resources
      Resources for printHeader(short).
    • outHeader

      private TableAppender outHeader
      Where to write the header before the data.
    • coordinateFormat

      private NumberFormat coordinateFormat
      The format to use for writing coordinate values.
    • coordinateWidth

      private int coordinateWidth
      Width of coordinate values, in number of characters in coordinate String representations.
    • numFractionDigits

      private int[] numFractionDigits
      Suggested number of fraction digits for each coordinate values.
    • thresholdForScientificNotation

      private double[] thresholdForScientificNotation
      We will switch to scientific notation if the coordinate value to format is greater than this value.
    • errorMessage

      private String errorMessage
      The error message to report after we transformed all coordinates, or null.
    • errorCause

      private NumberFormatException errorCause
      The cause of errorMessage, or null if none.
  • Constructor Details

  • Method Details

    • options

      private static EnumSet<Option> 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 - either Option.SOURCE_CRS or Option.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

      public int run() throws Exception
      Transforms coordinates from the files given in argument or from the standard input stream.
      Specified by:
      run in class CommandRunner
      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

      private void printHeader(short key) throws IOException
      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 - a Vocabulary.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

      private void printAccuracy(double accuracy) throws IOException
      Prints the accuracy.
      Throws:
      IOException
    • printDomainOfValidity

      private void printDomainOfValidity(org.opengis.metadata.extent.Extent domain) throws IOException
      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

      private void printDetails() throws IOException
      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

      private void printQuotedText(String text, int fieldWidth, X364 color)
      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

      private List<double[]> readCoordinates(LineNumberReader in, String filename) throws IOException
      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 by transform(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

      private static void warning(Exception e)
      Reports the given exception as an ignorable one. We consider FactoryException or TransformException 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.