Search in sources :

Example 41 with FactoryException

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

the class UnionFF method exec.

@Override
public NodeValue exec(NodeValue v1, NodeValue v2) {
    try {
        GeometryWrapper geometry1 = GeometryWrapper.extract(v1, GeometryIndex.PRIMARY);
        GeometryWrapper geometry2 = GeometryWrapper.extract(v2, GeometryIndex.SECONDARY);
        GeometryWrapper union = geometry1.union(geometry2);
        return union.asNodeValue();
    } catch (DatatypeFormatException ex) {
        throw new ExprEvalException(ex.getMessage(), ex);
    } catch (FactoryException | MismatchedDimensionException | TransformException ex) {
        throw new ExprEvalException(ex.getMessage() + ": " + FmtUtils.stringForNode(v1.asNode()) + ", " + FmtUtils.stringForNode(v2.asNode()), ex);
    }
}
Also used : DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) FactoryException(org.opengis.util.FactoryException) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) TransformException(org.opengis.referencing.operation.TransformException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException)

Example 42 with FactoryException

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

the class SpatialIndex method getGeometryLiteralIndexItems.

/**
 * @param model
 * @param srsURI
 * @return GeometryLiteral items prepared for adding to SpatialIndex.
 * @throws SpatialIndexException
 */
private static Collection<SpatialIndexItem> getGeometryLiteralIndexItems(Model model, String srsURI) throws SpatialIndexException {
    List<SpatialIndexItem> items = new ArrayList<>();
    StmtIterator stmtIt = model.listStatements(null, Geo.HAS_GEOMETRY_PROP, (Resource) null);
    while (stmtIt.hasNext()) {
        Statement stmt = stmtIt.nextStatement();
        Resource feature = stmt.getSubject();
        Resource geometry = stmt.getResource();
        ExtendedIterator<RDFNode> nodeIter = model.listObjectsOfProperty(geometry, Geo.HAS_SERIALIZATION_PROP);
        if (!nodeIter.hasNext()) {
            NodeIterator wktNodeIter = model.listObjectsOfProperty(geometry, Geo.AS_WKT_PROP);
            NodeIterator gmlNodeIter = model.listObjectsOfProperty(geometry, Geo.AS_GML_PROP);
            nodeIter = wktNodeIter.andThen(gmlNodeIter);
        }
        while (nodeIter.hasNext()) {
            Literal geometryLiteral = nodeIter.next().asLiteral();
            GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometryLiteral);
            try {
                // Ensure all entries in the target SRS URI.
                GeometryWrapper transformedGeometryWrapper = geometryWrapper.convertSRS(srsURI);
                Envelope envelope = transformedGeometryWrapper.getEnvelope();
                SpatialIndexItem item = new SpatialIndexItem(envelope, feature);
                items.add(item);
            } catch (FactoryException | MismatchedDimensionException | TransformException ex) {
                throw new SpatialIndexException("Transformation Exception: " + geometryLiteral + ". " + ex.getMessage());
            }
        }
    }
    return items;
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) StmtIterator(org.apache.jena.rdf.model.StmtIterator) FactoryException(org.opengis.util.FactoryException) Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) TransformException(org.opengis.referencing.operation.TransformException) Envelope(org.locationtech.jts.geom.Envelope) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) Literal(org.apache.jena.rdf.model.Literal) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 43 with FactoryException

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

the class SearchEnvelope method build.

public static SearchEnvelope build(GeometryWrapper geometryWrapper, SRSInfo srsInfo, double radius, String unitsURI) {
    try {
        // Get the envelope of the target GeometryWrapper and convert to SRS URI, in case it is a complex polygon.
        GeometryWrapper envelopeGeometryWrapper = geometryWrapper.envelope();
        // Convert to SRS URI.
        GeometryWrapper srsGeometryWrapper = envelopeGeometryWrapper.convertSRS(srsInfo.getSrsURI());
        Envelope envelope = srsGeometryWrapper.getEnvelope();
        // Expand the envelope by the radius distance in all directions,
        // i.e. a bigger box rather than circle. More precise checks made later.
        SearchEnvelope searchEnvelope;
        if (srsInfo.isGeographic()) {
            double radiusMetres = UnitsOfMeasure.convertToMetres(radius, unitsURI, srsGeometryWrapper.getLatitude());
            searchEnvelope = expandGeographicEnvelope(envelope, radiusMetres, srsInfo);
        } else {
            String targetUnitsURI = srsInfo.getUnitsOfMeasure().getUnitURI();
            double targetRadius = UnitsOfMeasure.conversion(radius, unitsURI, targetUnitsURI);
            searchEnvelope = expandEnvelope(envelope, targetRadius, srsInfo);
        }
        return searchEnvelope;
    } catch (FactoryException | MismatchedDimensionException | TransformException ex) {
        throw new ExprEvalException(ex.getMessage() + ": " + geometryWrapper.asLiteral(), ex);
    }
}
Also used : FactoryException(org.opengis.util.FactoryException) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) TransformException(org.opengis.referencing.operation.TransformException) Envelope(org.locationtech.jts.geom.Envelope) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 44 with FactoryException

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

the class TransformSRSFF method exec.

@Override
public NodeValue exec(NodeValue v1, NodeValue v2) {
    try {
        if (!(v2.isIRI() || v2.isString())) {
            throw new ExprEvalException("Not a URI: " + FmtUtils.stringForNode(v2.asNode()));
        }
        String srsURI;
        if (v2.isIRI()) {
            srsURI = v2.asNode().getURI();
        } else {
            srsURI = v2.asString();
        }
        GeometryWrapper geometry = GeometryWrapper.extract(v1, GeometryLiteralIndex.GeometryIndex.PRIMARY);
        GeometryWrapper convertedGeom = geometry.transform(srsURI);
        return convertedGeom.asNodeValue();
    } catch (DatatypeFormatException | TransformException | FactoryException ex) {
        throw new ExprEvalException(ex.getMessage(), ex);
    }
}
Also used : DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) FactoryException(org.opengis.util.FactoryException) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) TransformException(org.opengis.referencing.operation.TransformException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 45 with FactoryException

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

the class SRSRegistryTest method testGetDefaultWKTCRS.

/**
 * Test of getCRS method, of class SRSRegistry.
 */
@Test
public void testGetDefaultWKTCRS() {
    try {
        String srsURI = SRS_URI.DEFAULT_WKT_CRS84;
        String default_CRS_WKT = "GeodeticCRS[\"WGS 84\",\n" + "  Datum[\"World Geodetic System 1984\",\n" + "    Ellipsoid[\"WGS 84\", 6378137.0, 298.257223563]],\n" + "  CS[ellipsoidal, 2],\n" + "    Axis[\"Geodetic longitude (Lon)\", east],\n" + "    Axis[\"Geodetic latitude (Lat)\", north],\n" + "    Unit[\"degree\", 0.017453292519943295],\n" + "  Scope[\"Horizontal component of 3D system. Used by the GPS satellite navigation system and for NATO military geodetic surveying.\"],\n" + "  Area[\"World.\"],\n" + "  BBox[-90.00, -180.00, 90.00, 180.00],\n" + "  Id[\"CRS\", 84, Citation[\"WMS\"], URI[\"urn:ogc:def:crs:OGC:1.3:CRS84\"]]]";
        CoordinateReferenceSystem expResult = CRS.fromWKT(default_CRS_WKT);
        CoordinateReferenceSystem result = SRSRegistry.getCRS(srsURI);
        assertEquals(expResult.toWKT(), result.toWKT());
    } catch (FactoryException ex) {
    }
}
Also used : FactoryException(org.opengis.util.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

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