Package org.apache.sis.io.wkt
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
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final javax.measure.Unit<?>[]The base units associated to theUNIT_KEYWORDS, ignoringWKTKeywords.Unit.private StringThe classification of the last math transform or projection parsed, ornullif none.private static final double[][]Some conversion factors applied toUNIT_KEYWORDSfor which rounding errors are found in practice.(package private) final ReferencingFactoryContainerThe factories to use for creating math transforms and geodetic objects.(package private) static final String[]The keywords forIDorAUTHORITYelements, as a static array because frequently used.private org.opengis.referencing.operation.OperationMethodThe method for the last math transform passed, ornullif none.private static final String[]The keywords of unit elements.Fields inherited from class org.apache.sis.io.wkt.AbstractParser
errorLocale, FIRST, fragments, ignoredElements, MANDATORY, OPTIONAL, symbols -
Constructor Summary
ConstructorsConstructorDescriptionMathTransformParser(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.MathTransformParser(org.opengis.referencing.operation.MathTransformFactory mtFactory) Creates a parser for the given factory. -
Method Summary
Modifier and TypeMethodDescription(package private) ObjectbuildFromTree(Element element) Parses the next element in the specified Well Know Text (WKT) tree.private static doublecompleteUnitFactor(double[] predefined, double factor) If the unit conversion factor specified in the Well Known Text is missing some fraction digits, tries to complete them.(package private) static doublecompleteUnitFactor(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.(package private) final org.opengis.referencing.operation.OperationMethodReturns the operation method for the last math transform parsed.(package private) StringReturns the name of the class providing the publicly-accessiblecreateFromWKT(String)method.private org.opengis.referencing.operation.MathTransformparseConcatMT(Element parent) Parses a"CONCAT_MT"element.private org.opengis.referencing.operation.MathTransformparseInverseMT(Element parent) Parses an"INVERSE_MT"element.(package private) final org.opengis.referencing.operation.MathTransformparseMathTransform(Element element, boolean mandatory) Parses the nextMathTransformin the specified Well Know Text (WKT) tree.(package private) final voidparseParameters(Element element, org.opengis.parameter.ParameterValueGroup parameters, javax.measure.Unit<?> defaultUnit, javax.measure.Unit<javax.measure.quantity.Angle> defaultAngularUnit) Parses a sequence of"PARAMETER"elements.private org.opengis.referencing.operation.MathTransformparseParamMT(Element parent) Parses a"PARAM_MT"element.private org.opengis.referencing.operation.MathTransformparsePassThroughMT(Element parent) Parses a"PASSTHROUGH_MT"element.(package private) final javax.measure.Unit<?>Parses an optional"UNIT"element of unknown dimension.(package private) final javax.measure.Unit<?>parseUnitID(Element parent) Parses theID["authority", "code"]element inside aUNITelement.Methods inherited from class org.apache.sis.io.wkt.AbstractParser
createFromWKT, createFromWKT, endOfFragmentName, getAndClearWarnings, getFacadeMethod, log, parseDate, parseNumber, parseUnit, textToTree, warning, warning
-
Field Details
-
ID_KEYWORDS
The keywords forIDorAUTHORITYelements, as a static array because frequently used. -
UNIT_KEYWORDS
The keywords of unit elements. Most frequently used keywords should be first. -
BASE_UNITS
private static final javax.measure.Unit<?>[] BASE_UNITSThe base units associated to theUNIT_KEYWORDS, ignoringWKTKeywords.Unit. For eachUNIT_KEYWORDS[i]element, the associated base unit isBASE_UNIT[i-1]. -
CONVERSION_FACTORS
private static final double[][] CONVERSION_FACTORSSome conversion factors applied toUNIT_KEYWORDSfor which rounding errors are found in practice. Some Well Known Texts define factors with low accuracy, as inANGLEUNIT["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.
-
factories
The factories to use for creating math transforms and geodetic objects. -
classification
The classification of the last math transform or projection parsed, ornullif none. -
lastMethod
private transient org.opengis.referencing.operation.OperationMethod lastMethodThe method for the last math transform passed, ornullif 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 creatingMathTransformobjects.
-
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 theWKTFormat.fragmentsmap, or an empty map if none.numberFormat- the number format provided byWKTFormat, ornullfor a default format.dateFormat- the date format provided byWKTFormat, ornullfor a default format.unitFormat- the unit format provided byWKTFormat, ornullfor a default format.factories- the factories to use for creating math transforms and geodetic objects.errorLocale- the locale for error messages (not for parsing), ornullfor the system default.
-
-
Method Details
-
getPublicFacade
String getPublicFacade()Returns the name of the class providing the publicly-accessiblecreateFromWKT(String)method. This information is used for logging purpose only.- Specified by:
getPublicFacadein classAbstractParser
-
buildFromTree
Parses the next element in the specified Well Know Text (WKT) tree.- Specified by:
buildFromTreein classAbstractParser- Parameters:
element- the element to be parsed.- Returns:
- the parsed object, or
nullif 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 nextMathTransformin the specified Well Know Text (WKT) tree.- Parameters:
element- the parent element.mandatory-trueif a math transform must be present, orfalseif optional.- Returns:
- the next element as a
MathTransformobject, ornull. - Throws:
ParseException- if the next element cannot be parsed.
-
parseUnitID
Parses theID["authority", "code"]element inside aUNITelement. If such element is found, the authority is"EPSG"and the code is one of the codes known to theUnits.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 theUNITelement, 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 inUNITelements are rare, so risk of conflicts should be low.- Parameters:
parent- the parent"UNIT"element.- Returns:
- the unit from the identifier code, or
nullif none. - Throws:
ParseException- if the"ID"cannot be parsed.
-
parseUnit
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, ornullif 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), ornull.defaultAngularUnit- the default angular unit, ornullif none. This is determined by the context, especially whenGeodeticObjectParserparses aProjectedCRSelement.- 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 anMathTransformobject. - 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 anMathTransformobject. - 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 anMathTransformobject. - 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 anMathTransformobject. - 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 byGeodeticObjectParserin order to builtDerivedCRS.
-