use of org.opengis.util.FactoryException in project sis by apache.
the class GeodeticObjectParser method parseDatum.
/**
* Parses a {@code "Datum"} (WKT 2) element. The syntax is given by
* <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#54">WKT 2 specification §8.2.4</a>.
*
* The legacy WKT 1 pattern was:
*
* {@preformat wkt
* DATUM["<name>", <spheroid> {,<to wgs84>} {,<authority>}]
* }
*
* @param mode {@link #FIRST}, {@link #OPTIONAL} or {@link #MANDATORY}.
* @param parent the parent element.
* @param meridian the prime meridian, or {@code null} for Greenwich.
* @return the {@code "Datum"} element as a {@link GeodeticDatum} object.
* @throws ParseException if the {@code "Datum"} element can not be parsed.
*
* @see org.apache.sis.referencing.datum.DefaultGeodeticDatum#formatTo(Formatter)
*/
private GeodeticDatum parseDatum(final int mode, final Element parent, PrimeMeridian meridian) throws ParseException {
final Element element = parent.pullElement(mode, WKTKeywords.Datum, WKTKeywords.GeodeticDatum);
if (element == null) {
return null;
}
final String name = element.pullString("name");
final Ellipsoid ellipsoid = parseEllipsoid(MANDATORY, element);
final Object toWGS84 = parseToWGS84(OPTIONAL, element);
final Map<String, Object> properties = parseAnchorAndClose(element, name);
if (meridian == null) {
meridian = referencing.getGreenwich();
}
if (toWGS84 != null) {
properties.put(ReferencingServices.BURSA_WOLF_KEY, toWGS84);
}
try {
return datumFactory.createGeodeticDatum(properties, ellipsoid, meridian);
} catch (FactoryException exception) {
throw element.parseFailed(exception);
}
}
use of org.opengis.util.FactoryException in project sis by apache.
the class GeodeticObjectParser method parseTimeDatum.
/**
* Parses a {@code "TimeDatum"} element. This element has the following pattern:
*
* {@preformat wkt
* TimeDatum["<name>", TimeOrigin[<time origin>] {,<authority>}]
* }
*
* @param mode {@link #FIRST}, {@link #OPTIONAL} or {@link #MANDATORY}.
* @param parent the parent element.
* @return the {@code "TimeDatum"} element as a {@link TemporalDatum} object.
* @throws ParseException if the {@code "TimeDatum"} element can not be parsed.
*/
private TemporalDatum parseTimeDatum(final int mode, final Element parent) throws ParseException {
final Element element = parent.pullElement(mode, WKTKeywords.TimeDatum, WKTKeywords.TDatum);
if (element == null) {
return null;
}
final String name = element.pullString("name");
final Element origin = element.pullElement(MANDATORY, WKTKeywords.TimeOrigin);
final Date epoch = origin.pullDate("origin");
origin.close(ignoredElements);
try {
return datumFactory.createTemporalDatum(parseAnchorAndClose(element, name), epoch);
} catch (FactoryException exception) {
throw element.parseFailed(exception);
}
}
use of org.opengis.util.FactoryException in project sis by apache.
the class GeodeticObjectParser method parseOperation.
/**
* Parses a {@code "CoordinateOperation"} element. The syntax is given by
* <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#113">WKT 2 specification §17</a>.
*
* @param mode {@link #FIRST}, {@link #OPTIONAL} or {@link #MANDATORY}.
* @param parent the parent element.
* @return the {@code "CoordinateOperation"} element as a {@link CoordinateOperation} object.
* @throws ParseException if the {@code "CoordinateOperation"} element can not be parsed.
*/
private CoordinateOperation parseOperation(final int mode, final Element parent) throws ParseException {
final Element element = parent.pullElement(mode, WKTKeywords.CoordinateOperation);
if (element == null) {
return null;
}
final String name = element.pullString("name");
final CoordinateReferenceSystem sourceCRS = parseCoordinateReferenceSystem(element, MANDATORY, WKTKeywords.SourceCRS);
final CoordinateReferenceSystem targetCRS = parseCoordinateReferenceSystem(element, MANDATORY, WKTKeywords.TargetCRS);
final CoordinateReferenceSystem interpolationCRS = parseCoordinateReferenceSystem(element, OPTIONAL, WKTKeywords.InterpolationCRS);
final OperationMethod method = parseMethod(element, WKTKeywords.Method);
final Element accuracy = element.pullElement(OPTIONAL, WKTKeywords.OperationAccuracy);
final Map<String, Object> properties = parseMetadataAndClose(element, name, method);
final ParameterValueGroup parameters = method.getParameters().createValue();
parseParameters(element, parameters, null, null);
properties.put(ReferencingServices.PARAMETERS_KEY, parameters);
if (accuracy != null) {
properties.put(CoordinateOperation.COORDINATE_OPERATION_ACCURACY_KEY, TransformationAccuracy.create(accuracy.pullDouble("accuracy")));
accuracy.close(ignoredElements);
}
try {
return referencing.createSingleOperation(properties, sourceCRS, targetCRS, interpolationCRS, method, opFactory);
} catch (FactoryException e) {
throw element.parseFailed(e);
}
}
use of org.opengis.util.FactoryException in project sis by apache.
the class MathTransformParser method parseConcatMT.
/**
* 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;
}
use of org.opengis.util.FactoryException in project sis by apache.
the class AbstractParser method createFromWKT.
/**
* Creates the object from a string and log the warnings if any.
* This method is for implementation of {@code createFromWKT(String)} method is SIS factories only.
*
* @param text coordinate system encoded in Well-Known Text format (version 1 or 2).
* @return the result of parsing the given text.
* @throws FactoryException if the object creation failed.
*
* @see org.apache.sis.referencing.factory.GeodeticObjectFactory#createFromWKT(String)
* @see org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory#createFromWKT(String)
*/
@Override
public final Object createFromWKT(final String text) throws FactoryException {
final Object value;
try {
value = parseObject(text, new ParsePosition(0));
} catch (ParseException exception) {
final Throwable cause = exception.getCause();
if (cause instanceof FactoryException) {
throw (FactoryException) cause;
}
throw new FactoryException(exception.getLocalizedMessage(), exception);
}
final Warnings warnings = getAndClearWarnings(value);
if (warnings != null) {
log(new LogRecord(Level.WARNING, warnings.toString()));
}
return value;
}
Aggregations