/** * If the unit conversion factor specified in the Well Known Text is missing some fraction digits, * try to complete them. The main use case is to replace 0.01745329252 by 0.017453292519943295 in * degree units. * * @param baseUnit the base unit for which to complete the conversion factor. * @param factor the conversion factor specified in the Well Known Text element. * @return the conversion factor to use. */ static double completeUnitFactor(final Unit<?> baseUnit, final double factor) { for (int i=CONVERSION_FACTORS.length; --i>=0;) { if (BASE_UNITS[i] == baseUnit) { return completeUnitFactor(CONVERSION_FACTORS[i], factor); } } return factor; }
/** * Parses the next {@code MathTransform} in the specified <cite>Well Know Text</cite> (WKT) tree. * * @param element the parent element. * @param mandatory {@code true} if a math transform must be present, or {@code false} if optional. * @return the next element as a {@code MathTransform} object, or {@code null}. * @throws ParseException if the next element can not be parsed. */ final MathTransform parseMathTransform(final Element element, final boolean mandatory) throws ParseException { lastMethod = null; classification = null; MathTransform tr; if ((tr = parseParamMT (element)) == null && (tr = parseConcatMT (element)) == null && (tr = parseInverseMT (element)) == null && (tr = parsePassThroughMT (element)) == null) { if (mandatory) { throw element.missingOrUnknownComponent(WKTKeywords.Param_MT); } } return tr; }
/** * Parses the next element in the specified <cite>Well Know Text</cite> (WKT) tree. * * @param element the element to be parsed. * @return the parsed object, or {@code null} if the element is not recognized. * @throws ParseException if the element can not be parsed. */ @Override Object parseObject(final Element element) throws ParseException { return parseMathTransform(element, true); }
/** * Parses the given text. * * @throws ParseException if an error occurred during the parsing. */ private MathTransform parse(final String text) throws ParseException { if (parser == null) { parser = new MathTransformParser(DefaultFactories.forBuildin(MathTransformFactory.class)); assertEquals(DefaultMathTransformFactory.class.getCanonicalName(), parser.getPublicFacade()); } final ParsePosition position = new ParsePosition(0); final MathTransform mt = (MathTransform) parser.parseObject(text, position); assertEquals("errorIndex", -1, position.getErrorIndex()); assertEquals("index", text.length(), position.getIndex()); return mt; }
double factor = element.pullDouble("factor"); final int index = element.getKeywordIndex() - 1; final Unit<?> unit = parseUnitID(element); element.close(ignoredElements); if (unit != null) { factor = completeUnitFactor(CONVERSION_FACTORS[index], factor); return parseUnit(name); } catch (ParserException e) { throw new UnparsableObjectException(errorLocale, Errors.Keys.UnknownUnit_1,
final Object object; try { object = super.parseObject(text, position);
parseParameters(element, parameters, null, null); element.close(ignoredElements);
final Object object; try { object = super.parseObject(text, position);
parseParameters(element, parameters, null, null); element.close(ignoredElements);
/** * Parses the next {@code MathTransform} in the specified <cite>Well Know Text</cite> (WKT) tree. * * @param element the parent element. * @param mandatory {@code true} if a math transform must be present, or {@code false} if optional. * @return the next element as a {@code MathTransform} object, or {@code null}. * @throws ParseException if the next element can not be parsed. */ final MathTransform parseMathTransform(final Element element, final boolean mandatory) throws ParseException { lastMethod = null; classification = null; MathTransform tr; if ((tr = parseParamMT (element)) == null && (tr = parseConcatMT (element)) == null && (tr = parseInverseMT (element)) == null && (tr = parsePassThroughMT (element)) == null) { if (mandatory) { throw element.missingOrUnknownComponent(WKTKeywords.Param_MT); } } return tr; }
/** * Parses the next element in the specified <cite>Well Know Text</cite> (WKT) tree. * * @param element the element to be parsed. * @return the parsed object, or {@code null} if the element is not recognized. * @throws ParseException if the element can not be parsed. */ @Override Object parseObject(final Element element) throws ParseException { return parseMathTransform(element, true); }
/** * Parses a {@code "CONCAT_MT"} element. This element has the following pattern: * * {@preformat text * CONCAT_MT[<math transform> {,<math transform>}*] * } * * @param parent the parent element. * @return the {@code "CONCAT_MT"} element as an {@link MathTransform} object. * @throws ParseException if the {@code "CONCAT_MT"} element can not be parsed. */ private MathTransform parseConcatMT(final Element parent) throws ParseException { final Element element = parent.pullElement(FIRST, WKTKeywords.Concat_MT); if (element == null) { return null; } MathTransform transform = parseMathTransform(element, true); MathTransform optionalTransform; while ((optionalTransform = parseMathTransform(element, false)) != null) { try { transform = mtFactory.createConcatenatedTransform(transform, optionalTransform); } catch (FactoryException exception) { throw element.parseFailed(exception); } } element.close(ignoredElements); return transform; }
/** * Parses a {@code "CONCAT_MT"} element. This element has the following pattern: * * {@preformat text * CONCAT_MT[<math transform> {,<math transform>}*] * } * * @param parent the parent element. * @return the {@code "CONCAT_MT"} element as an {@link MathTransform} object. * @throws ParseException if the {@code "CONCAT_MT"} element can not be parsed. */ private MathTransform parseConcatMT(final Element parent) throws ParseException { final Element element = parent.pullElement(FIRST, WKTKeywords.Concat_MT); if (element == null) { return null; } MathTransform transform = parseMathTransform(element, true); MathTransform optionalTransform; while ((optionalTransform = parseMathTransform(element, false)) != null) { try { transform = mtFactory.createConcatenatedTransform(transform, optionalTransform); } catch (FactoryException exception) { throw element.parseFailed(exception); } } element.close(ignoredElements); return transform; }
/** * Parses an {@code "INVERSE_MT"} element. This element has the following pattern: * * {@preformat text * INVERSE_MT[<math transform>] * } * * @param parent the parent element. * @return the {@code "INVERSE_MT"} element as an {@link MathTransform} object. * @throws ParseException if the {@code "INVERSE_MT"} element can not be parsed. */ private MathTransform parseInverseMT(final Element parent) throws ParseException { final Element element = parent.pullElement(FIRST, WKTKeywords.Inverse_MT); if (element == null) { return null; } MathTransform transform = parseMathTransform(element, true); try { transform = transform.inverse(); } catch (NoninvertibleTransformException exception) { throw element.parseFailed(exception); } element.close(ignoredElements); return transform; }
/** * Parses an {@code "INVERSE_MT"} element. This element has the following pattern: * * {@preformat text * INVERSE_MT[<math transform>] * } * * @param parent the parent element. * @return the {@code "INVERSE_MT"} element as an {@link MathTransform} object. * @throws ParseException if the {@code "INVERSE_MT"} element can not be parsed. */ private MathTransform parseInverseMT(final Element parent) throws ParseException { final Element element = parent.pullElement(FIRST, WKTKeywords.Inverse_MT); if (element == null) { return null; } MathTransform transform = parseMathTransform(element, true); try { transform = transform.inverse(); } catch (NoninvertibleTransformException exception) { throw element.parseFailed(exception); } element.close(ignoredElements); return transform; }
/** * Parses a {@code "PASSTHROUGH_MT"} element. This element has the following pattern: * * {@preformat text * PASSTHROUGH_MT[<integer>, <math transform>] * } * * @param parent the parent element. * @return the {@code "PASSTHROUGH_MT"} element as an {@link MathTransform} object. * @throws ParseException if the {@code "PASSTHROUGH_MT"} element can not be parsed. */ private MathTransform parsePassThroughMT(final Element parent) throws ParseException { final Element element = parent.pullElement(FIRST, WKTKeywords.PassThrough_MT); if (element == null) { return null; } final int firstAffectedOrdinate = parent.pullInteger("firstAffectedOrdinate"); final MathTransform transform = parseMathTransform(element, true); element.close(ignoredElements); try { return mtFactory.createPassThroughTransform(firstAffectedOrdinate, transform, 0); } catch (FactoryException exception) { throw element.parseFailed(exception); } }
/** * Parses a {@code "PASSTHROUGH_MT"} element. This element has the following pattern: * * {@preformat text * PASSTHROUGH_MT[<integer>, <math transform>] * } * * @param parent the parent element. * @return the {@code "PASSTHROUGH_MT"} element as an {@link MathTransform} object. * @throws ParseException if the {@code "PASSTHROUGH_MT"} element can not be parsed. */ private MathTransform parsePassThroughMT(final Element parent) throws ParseException { final Element element = parent.pullElement(FIRST, WKTKeywords.PassThrough_MT); if (element == null) { return null; } final int firstAffectedOrdinate = parent.pullInteger("firstAffectedOrdinate"); final MathTransform transform = parseMathTransform(element, true); element.close(ignoredElements); try { return mtFactory.createPassThroughTransform(firstAffectedOrdinate, transform, 0); } catch (FactoryException exception) { throw element.parseFailed(exception); } }