Search in sources :

Example 11 with FactoryException

use of org.opengis.util.FactoryException in project sis by apache.

the class GeodeticObjectParser method parseDerivingConversion.

/**
 * Parses a {@code "Method"} (WKT 2) element, followed by parameter values. The syntax is given by
 * <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#62">WKT 2 specification §9.3</a>.
 *
 * The legacy WKT 1 specification was:
 *
 * {@preformat wkt
 *     PROJECTION["<name>" {,<authority>}]
 * }
 *
 * Note that in WKT 2, this element is wrapped inside a {@code Conversion} or {@code DerivingConversion}
 * element which is itself inside the {@code ProjectedCRS} element. This is different than WKT 1, which
 * puts this element right into the the {@code ProjectedCRS} element without {@code Conversion} wrapper.
 *
 * @param  mode                {@link #FIRST}, {@link #OPTIONAL} or {@link #MANDATORY}.
 * @param  parent              the parent element.
 * @param  wrapper             "Conversion" or "DerivingConversion" wrapper name, or null if parsing a WKT 1.
 * @param  defaultUnit         the unit (usually linear) of the parent element, or {@code null}.
 * @param  defaultAngularUnit  the angular unit of the sibling {@code GeographicCRS} element, or {@code null}.
 * @return the {@code "Method"} element and its parameters as a defining conversion.
 * @throws ParseException if the {@code "Method"} element can not be parsed.
 */
private Conversion parseDerivingConversion(final int mode, Element parent, final String wrapper, final Unit<?> defaultUnit, final Unit<Angle> defaultAngularUnit) throws ParseException {
    final String name;
    if (wrapper == null) {
        // Will actually be ignored. WKT 1 does not provide name for Conversion objects.
        name = null;
    } else {
        /*
             * If we are parsing WKT 2, then there is an additional "Conversion" element between
             * the parent (usually a ProjectedCRS) and the other elements parsed by this method.
             */
        parent = parent.pullElement(mode, wrapper);
        if (parent == null) {
            return null;
        }
        name = parent.pullString("name");
    }
    final OperationMethod method = parseMethod(parent, WKTKeywords.Method, WKTKeywords.Projection);
    // Same properties then OperationMethod, with ID removed.
    Map<String, ?> properties = this.properties;
    /*
         * Set the list of parameters.
         *
         * NOTE 1: Parameters are defined in the parent element (usually a "ProjectedCRS" element
         *         in WKT 1 or a "Conversion" element in WKT 2), not in this "Method" element.
         *
         * NOTE 2: We may inherit the OperationMethod name if there is no Conversion wrapper with its own name,
         *         but we shall not inherit the OperationMethod identifier. This is the reason why we invoked
         *         properties.remove(IdentifiedObject.IDENTIFIERS_KEY)) above.
         */
    final ParameterValueGroup parameters = method.getParameters().createValue();
    parseParameters(parent, parameters, defaultUnit, defaultAngularUnit);
    if (wrapper != null) {
        properties = parseMetadataAndClose(parent, name, method);
    /*
             * DEPARTURE FROM ISO 19162: the specification in §9.3.2 said:
             *
             *     "If an identifier is provided as an attribute within the <map projection conversion> object,
             *     because it is expected to describe a complete collection of zone name, method, parameters and
             *     parameter values, it shall override any identifiers given within the map projection method and
             *     map projection parameter objects."
             *
             * However this would require this GeodeticObjectParser to hold a CoordinateOperationAuthorityFactory,
             * which we do not yet implement. See https://issues.apache.org/jira/browse/SIS-210
             */
    }
    try {
        return opFactory.createDefiningConversion(properties, method, parameters);
    } catch (FactoryException exception) {
        throw parent.parseFailed(exception);
    }
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) FactoryException(org.opengis.util.FactoryException)

Example 12 with FactoryException

use of org.opengis.util.FactoryException in project sis by apache.

the class GeodeticObjectParser method parseCompoundCRS.

/**
 * Parses a {@code "CompoundCRS"} element. The syntax is given by
 * <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#110">WKT 2 specification §16</a>.
 *
 * The legacy WKT 1 specification was:
 *
 * {@preformat wkt
 *     COMPD_CS["<name>", <head cs>, <tail cs> {,<authority>}]
 * }
 *
 * In the particular case where there is a geographic CRS and an ellipsoidal height,
 * this method rather build a three-dimensional geographic CRS.
 *
 * @param  mode    {@link #FIRST}, {@link #OPTIONAL} or {@link #MANDATORY}.
 * @param  parent  the parent element.
 * @return the {@code "CompoundCRS"} element as a {@link CompoundCRS} object.
 * @throws ParseException if the {@code "CompoundCRS"} element can not be parsed.
 */
private CoordinateReferenceSystem parseCompoundCRS(final int mode, final Element parent) throws ParseException {
    final Element element = parent.pullElement(mode, WKTKeywords.CompoundCRS, WKTKeywords.Compd_CS);
    if (element == null) {
        return null;
    }
    final String name = element.pullString("name");
    CoordinateReferenceSystem crs;
    final List<CoordinateReferenceSystem> components = new ArrayList<>(4);
    while ((crs = parseCoordinateReferenceSystem(element, components.size() < 2)) != null) {
        components.add(crs);
    }
    try {
        return new EllipsoidalHeightCombiner(crsFactory, csFactory, opFactory).createCompoundCRS(parseMetadataAndClose(element, name, null), components.toArray(new CoordinateReferenceSystem[components.size()]));
    } catch (FactoryException exception) {
        throw element.parseFailed(exception);
    }
}
Also used : EllipsoidalHeightCombiner(org.apache.sis.internal.metadata.EllipsoidalHeightCombiner) FactoryException(org.opengis.util.FactoryException) ArrayList(java.util.ArrayList)

Example 13 with FactoryException

use of org.opengis.util.FactoryException in project sis by apache.

the class MathTransformParser method parseParamMT.

/**
 * Parses a {@code "PARAM_MT"} element. This element has the following pattern:
 *
 * {@preformat text
 *     PARAM_MT["<classification-name>" {,<parameter>}* ]
 * }
 *
 * @param  parent  the parent element.
 * @return the {@code "PARAM_MT"} element as an {@link MathTransform} object.
 * @throws ParseException if the {@code "PARAM_MT"} element can not be parsed.
 */
private MathTransform parseParamMT(final Element parent) throws ParseException {
    final Element element = parent.pullElement(FIRST, WKTKeywords.Param_MT);
    if (element == null) {
        return null;
    }
    classification = element.pullString("classification");
    final ParameterValueGroup parameters;
    try {
        parameters = mtFactory.getDefaultParameters(classification);
    } catch (NoSuchIdentifierException exception) {
        throw element.parseFailed(exception);
    }
    /*
         * Scan over all PARAMETER["name", value] elements and
         * set the corresponding parameter in the parameter group.
         */
    parseParameters(element, parameters, null, null);
    element.close(ignoredElements);
    /*
         * We now have all informations for constructing the math transform.
         */
    final MathTransform transform;
    try {
        transform = mtFactory.createParameterizedTransform(parameters);
    } catch (FactoryException exception) {
        throw element.parseFailed(exception);
    }
    lastMethod = mtFactory.getLastMethodUsed();
    return transform;
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) FactoryException(org.opengis.util.FactoryException) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException)

Example 14 with FactoryException

use of org.opengis.util.FactoryException in project sis by apache.

the class MathTransformParser method parsePassThroughMT.

/**
 * 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);
    }
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) FactoryException(org.opengis.util.FactoryException)

Example 15 with FactoryException

use of org.opengis.util.FactoryException in project sis by apache.

the class EPSGDataAccess method close.

/**
 * Closes the JDBC connection used by this factory.
 * If this {@code EPSGDataAccess} is used by an {@link EPSGFactory}, then this method
 * will be automatically invoked after some {@linkplain EPSGFactory#getTimeout timeout}.
 *
 * @throws FactoryException if an error occurred while closing the connection.
 *
 * @see #connection
 */
@Override
public synchronized void close() throws FactoryException {
    SQLException exception = null;
    final Iterator<PreparedStatement> ip = statements.values().iterator();
    while (ip.hasNext()) {
        try {
            ip.next().close();
        } catch (SQLException e) {
            if (exception == null) {
                exception = e;
            } else {
                exception.addSuppressed(e);
            }
        }
        ip.remove();
    }
    final Iterator<CloseableReference<AuthorityCodes>> it = authorityCodes.values().iterator();
    while (it.hasNext()) {
        try {
            it.next().close();
        } catch (SQLException e) {
            if (exception == null) {
                exception = e;
            } else {
                exception.addSuppressed(e);
            }
        }
        it.remove();
    }
    try {
        connection.close();
    } catch (SQLException e) {
        if (exception == null) {
            exception = e;
        } else {
            // Keep the connection thrown be Connection as the main one to report.
            e.addSuppressed(exception);
        }
    }
    if (exception != null) {
        throw new FactoryException(exception);
    }
}
Also used : SQLException(java.sql.SQLException) FactoryException(org.opengis.util.FactoryException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

FactoryException (org.opengis.util.FactoryException)84 TransformException (org.opengis.referencing.operation.TransformException)27 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)21 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)19 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)17 MathTransform (org.opengis.referencing.operation.MathTransform)15 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)12 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)10 IdentifiedObject (org.opengis.referencing.IdentifiedObject)8 Envelope (org.locationtech.jts.geom.Envelope)7 ArrayList (java.util.ArrayList)6 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)6 NoninvertibleTransformException (org.opengis.referencing.operation.NoninvertibleTransformException)6 Literal (org.apache.jena.rdf.model.Literal)5 UnavailableFactoryException (org.apache.sis.referencing.factory.UnavailableFactoryException)5 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)5 ParseException (java.text.ParseException)4 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)4 BackingStoreException (org.apache.sis.util.collection.BackingStoreException)4 Test (org.junit.Test)4