Class MathTransformParser

java.lang.Object
org.apache.sis.io.wkt.AbstractParser
org.apache.sis.io.wkt.MathTransformParser
All Implemented Interfaces:
Parser
Direct Known Subclasses:
GeodeticObjectParser

class MathTransformParser extends AbstractParser
Well Known Text (WKT) parser for math transforms. Note that while this base class is restricted to math transforms, subclasses may parse a wider range of objects.
Since:
0.6
Version:
1.0
See Also:
  • Field Details

    • ID_KEYWORDS

      static final String[] ID_KEYWORDS
      The keywords for ID or AUTHORITY elements, as a static array because frequently used.
    • UNIT_KEYWORDS

      private static final String[] UNIT_KEYWORDS
      The keywords of unit elements. Most frequently used keywords should be first.
    • BASE_UNITS

      private static final javax.measure.Unit<?>[] BASE_UNITS
      The base units associated to the UNIT_KEYWORDS, ignoring WKTKeywords.Unit. For each UNIT_KEYWORDS[i] element, the associated base unit is BASE_UNIT[i-1].
    • CONVERSION_FACTORS

      private static final double[][] CONVERSION_FACTORS
      Some conversion factors applied to UNIT_KEYWORDS for which rounding errors are found in practice. Some Well Known Texts define factors with low accuracy, as in ANGLEUNIT["degree", 0.01745329252]. This causes the parser to fail to recognize that the unit is degree and to convert angles with that factor. This may result in surprising behavior like SIS-377. This array is a workaround for that problem, adding the missing accuracy to factors. This workaround should be removed in a future version if we fix SIS-433.

      Values in each array must be sorted in ascending order.

      See Also:
    • factories

      final ReferencingFactoryContainer factories
      The factories to use for creating math transforms and geodetic objects.
    • classification

      private transient String classification
      The classification of the last math transform or projection parsed, or null if none.
    • lastMethod

      private transient org.opengis.referencing.operation.OperationMethod lastMethod
      The method for the last math transform passed, or null if none.
      See Also:
  • Constructor Details

    • MathTransformParser

      public MathTransformParser(org.opengis.referencing.operation.MathTransformFactory mtFactory)
      Creates a parser for the given factory.

      Maintenance note: this constructor is invoked through reflection by DefaultMathTransformFactory.createFromWKT(String). Do not change the method signature even if it doesn't break the compilation, unless the reflection code is also updated.

      Parameters:
      mtFactory - the factory to use for creating MathTransform objects.
    • MathTransformParser

      MathTransformParser(Symbols symbols, Map<String,StoredTree> fragments, NumberFormat numberFormat, DateFormat dateFormat, UnitFormat unitFormat, ReferencingFactoryContainer factories, Locale errorLocale)
      Creates a parser using the specified set of symbols and factories.
      Parameters:
      symbols - the set of symbols to use.
      fragments - reference to the WKTFormat.fragments map, or an empty map if none.
      numberFormat - the number format provided by WKTFormat, or null for a default format.
      dateFormat - the date format provided by WKTFormat, or null for a default format.
      unitFormat - the unit format provided by WKTFormat, or null for a default format.
      factories - the factories to use for creating math transforms and geodetic objects.
      errorLocale - the locale for error messages (not for parsing), or null for the system default.
  • Method Details

    • getPublicFacade

      String getPublicFacade()
      Returns the name of the class providing the publicly-accessible createFromWKT(String) method. This information is used for logging purpose only.
      Specified by:
      getPublicFacade in class AbstractParser
    • buildFromTree

      Object buildFromTree(Element element) throws ParseException
      Parses the next element in the specified Well Know Text (WKT) tree.
      Specified by:
      buildFromTree in class AbstractParser
      Parameters:
      element - the element to be parsed.
      Returns:
      the parsed object, or null if the element is not recognized.
      Throws:
      ParseException - if the element cannot be parsed.
    • parseMathTransform

      final org.opengis.referencing.operation.MathTransform parseMathTransform(Element element, boolean mandatory) throws ParseException
      Parses the next MathTransform in the specified Well Know Text (WKT) tree.
      Parameters:
      element - the parent element.
      mandatory - true if a math transform must be present, or false if optional.
      Returns:
      the next element as a MathTransform object, or null.
      Throws:
      ParseException - if the next element cannot be parsed.
    • parseUnitID

      final javax.measure.Unit<?> parseUnitID(Element parent) throws ParseException
      Parses the ID["authority", "code"] element inside a UNIT element. If such element is found, the authority is "EPSG" and the code is one of the codes known to the Units.valueOfEPSG(int), then that unit is returned. Otherwise this method returns null.
      Note: this method is a slight departure of ISO 19162, which said "Should any attributes or values given in the cited identifier be in conflict with attributes or values given explicitly in the WKT description, the WKT values shall prevail." But some units can hardly be expressed by the UNIT element, because the latter can contain only a conversion factor. For example, sexagesimal units (EPSG:9108, 9110 and 9111) can hardly be expressed in another way than by their EPSG code. Thankfully, identifiers in UNIT elements are rare, so risk of conflicts should be low.
      Parameters:
      parent - the parent "UNIT" element.
      Returns:
      the unit from the identifier code, or null if none.
      Throws:
      ParseException - if the "ID" cannot be parsed.
    • parseUnit

      final javax.measure.Unit<?> parseUnit(Element parent) throws ParseException
      Parses an optional "UNIT" element of unknown dimension. This method tries to infer the quantity dimension from the unit keyword.
      Parameters:
      parent - the parent element.
      Returns:
      the "UNIT" element, or null if none.
      Throws:
      ParseException - if the "UNIT" cannot be parsed.
      See Also:
    • completeUnitFactor

      private static double completeUnitFactor(double[] predefined, double factor)
      If the unit conversion factor specified in the Well Known Text is missing some fraction digits, tries to complete them. The main use case is to replace 0.01745329252 by 0.017453292519943295 in degree units.
      Parameters:
      predefined - some known conversion factors, in ascending order.
      factor - the conversion factor specified in the Well Known Text element.
      Returns:
      the conversion factor to use.
    • completeUnitFactor

      static double completeUnitFactor(javax.measure.Unit<?> baseUnit, double factor)
      If the unit conversion factor specified in the Well Known Text is missing some fraction digits, tries to complete them. The main use case is to replace 0.01745329252 by 0.017453292519943295 in degree units.
      Parameters:
      baseUnit - the base unit for which to complete the conversion factor.
      factor - the conversion factor specified in the Well Known Text element.
      Returns:
      the conversion factor to use.
    • parseParameters

      final void parseParameters(Element element, org.opengis.parameter.ParameterValueGroup parameters, javax.measure.Unit<?> defaultUnit, javax.measure.Unit<javax.measure.quantity.Angle> defaultAngularUnit) throws ParseException
      Parses a sequence of "PARAMETER" elements.
      Parameters:
      element - the parent element containing the parameters to parse.
      parameters - the group where to store the parameter values.
      defaultUnit - the default unit (for arbitrary quantity, including angular), or null.
      defaultAngularUnit - the default angular unit, or null if none. This is determined by the context, especially when GeodeticObjectParser parses a ProjectedCRS element.
      Throws:
      ParseException - if the "PARAMETER" element cannot be parsed.
    • parseParamMT

      private org.opengis.referencing.operation.MathTransform parseParamMT(Element parent) throws ParseException
      Parses a "PARAM_MT" element. This element has the following pattern:
      Parameters:
      parent - the parent element.
      Returns:
      the "PARAM_MT" element as an MathTransform object.
      Throws:
      ParseException - if the "PARAM_MT" element cannot be parsed.
    • parseInverseMT

      private org.opengis.referencing.operation.MathTransform parseInverseMT(Element parent) throws ParseException
      Parses an "INVERSE_MT" element. This element has the following pattern:
      Parameters:
      parent - the parent element.
      Returns:
      the "INVERSE_MT" element as an MathTransform object.
      Throws:
      ParseException - if the "INVERSE_MT" element cannot be parsed.
    • parsePassThroughMT

      private org.opengis.referencing.operation.MathTransform parsePassThroughMT(Element parent) throws ParseException
      Parses a "PASSTHROUGH_MT" element. This element has the following pattern:
      Parameters:
      parent - the parent element.
      Returns:
      the "PASSTHROUGH_MT" element as an MathTransform object.
      Throws:
      ParseException - if the "PASSTHROUGH_MT" element cannot be parsed.
    • parseConcatMT

      private org.opengis.referencing.operation.MathTransform parseConcatMT(Element parent) throws ParseException
      Parses a "CONCAT_MT" element. This element has the following pattern:
      Parameters:
      parent - the parent element.
      Returns:
      the "CONCAT_MT" element as an MathTransform object.
      Throws:
      ParseException - if the "CONCAT_MT" element cannot be parsed.
    • getOperationMethod

      final org.opengis.referencing.operation.OperationMethod getOperationMethod()
      Returns the operation method for the last math transform parsed. This is used by GeodeticObjectParser in order to built DerivedCRS.