Search in sources :

Example 36 with FactoryException

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

the class DistanceFF method exec.

@Override
public NodeValue exec(NodeValue v1, NodeValue v2, NodeValue v3) {
    try {
        GeometryWrapper geometry1 = GeometryWrapper.extract(v1, GeometryLiteralIndex.GeometryIndex.PRIMARY);
        GeometryWrapper geometry2 = GeometryWrapper.extract(v2, GeometryLiteralIndex.GeometryIndex.SECONDARY);
        if (!(v3.isIRI() || v3.isString())) {
            throw new ExprEvalException("Not an IRI or String: " + FmtUtils.stringForNode(v3.asNode()));
        }
        String unitsURI;
        if (v3.isIRI()) {
            unitsURI = v3.asNode().getURI();
        } else {
            unitsURI = v3.asString();
        }
        double distance = geometry1.distance(geometry2, unitsURI);
        return NodeValue.makeDouble(distance);
    } catch (DatatypeFormatException | FactoryException | MismatchedDimensionException | TransformException 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) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException)

Example 37 with FactoryException

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

the class TransformFF method exec.

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

Example 38 with FactoryException

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

the class GenericPropertyFunction method findIndex.

private QueryIterConcat findIndex(Graph graph, Node boundNode, Node unboundNode, Binding binding, boolean isSubjectBound, Node predicate, ExecutionContext execCxt) throws ExprEvalException {
    try {
        // Prepare for results.
        Var unboundVar = Var.alloc(unboundNode.getName());
        QueryIterConcat queryIterConcat = new QueryIterConcat(execCxt);
        // Find the asserted triples.
        List<Node> assertedNodes = findAsserted(graph, boundNode, isSubjectBound, predicate);
        for (Node node : assertedNodes) {
            Binding newBind = BindingFactory.binding(binding, unboundVar, node);
            QueryIterator queryIter = QueryIterSingleton.create(newBind, execCxt);
            queryIterConcat.add(queryIter);
        }
        // Find the GeometryLiteral of the Bound Node.
        SpatialObjectGeometryLiteral boundGeometryLiteral = SpatialObjectGeometryLiteral.retrieve(graph, boundNode);
        if (!boundGeometryLiteral.isValid()) {
            // Bound Node is not a Feature or a Geometry or there is no GeometryLiteral so exit.
            return queryIterConcat;
        }
        Node geometryLiteral = boundGeometryLiteral.getGeometryLiteral();
        // Perform the search of the Spatial Index of the Dataset.
        SpatialIndex spatialIndex = SpatialIndex.retrieve(execCxt);
        GeometryWrapper geom = GeometryWrapper.extract(geometryLiteral);
        GeometryWrapper transformedGeom = geom.transform(spatialIndex.getSrsInfo());
        Envelope searchEnvelope = transformedGeom.getEnvelope();
        HashSet<Resource> features = spatialIndex.query(searchEnvelope);
        // Check each of the Features that match the search.
        for (Resource feature : features) {
            Node featureNode = feature.asNode();
            // Ensure not already an asserted node.
            if (!assertedNodes.contains(featureNode)) {
                Binding newBind = BindingFactory.binding(binding, unboundVar, featureNode);
                QueryIterator queryIter;
                if (isSubjectBound) {
                    queryIter = bothBound(newBind, boundNode, predicate, featureNode, execCxt);
                } else {
                    queryIter = bothBound(newBind, featureNode, predicate, boundNode, execCxt);
                }
                queryIterConcat.add(queryIter);
            }
            // Also test all Geometry of the Features. All, some or one Geometry may have matched.
            ExtendedIterator<Triple> featureGeometryTriples = graph.find(feature.asNode(), Geo.HAS_GEOMETRY_NODE, null);
            while (featureGeometryTriples.hasNext()) {
                Triple unboundTriple = featureGeometryTriples.next();
                Node geomNode = unboundTriple.getObject();
                // Ensure not already an asserted node.
                if (!assertedNodes.contains(geomNode)) {
                    Binding newBind = BindingFactory.binding(binding, unboundVar, geomNode);
                    QueryIterator queryIter;
                    if (isSubjectBound) {
                        queryIter = bothBound(newBind, boundNode, predicate, geomNode, execCxt);
                    } else {
                        queryIter = bothBound(newBind, geomNode, predicate, boundNode, execCxt);
                    }
                    queryIterConcat.add(queryIter);
                }
            }
        }
        return queryIterConcat;
    } catch (MismatchedDimensionException | TransformException | FactoryException | SpatialIndexException ex) {
        throw new ExprEvalException(ex.getMessage() + ": " + FmtUtils.stringForNode(boundNode) + ", " + FmtUtils.stringForNode(unboundNode) + ", " + FmtUtils.stringForNode(predicate), ex);
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) FactoryException(org.opengis.util.FactoryException) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) Resource(org.apache.jena.rdf.model.Resource) TransformException(org.opengis.referencing.operation.TransformException) SpatialIndexException(org.apache.jena.geosparql.spatial.SpatialIndexException) Envelope(org.locationtech.jts.geom.Envelope) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) Triple(org.apache.jena.graph.Triple) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) SpatialIndex(org.apache.jena.geosparql.spatial.SpatialIndex) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 39 with FactoryException

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

the class DistanceFF method exec.

@Override
public NodeValue exec(NodeValue v1, NodeValue v2, NodeValue v3) {
    try {
        GeometryWrapper geometry1 = GeometryWrapper.extract(v1, GeometryIndex.PRIMARY);
        GeometryWrapper geometry2 = GeometryWrapper.extract(v2, GeometryIndex.SECONDARY);
        if (!v3.isIRI()) {
            throw new ExprEvalException("Not a IRI: " + FmtUtils.stringForNode(v3.asNode()));
        }
        // GeoSPARQL uses the Euclidean distance regardless of SRS URI.
        double distance = geometry1.distanceEuclidean(geometry2, v3.asNode().getURI());
        return NodeValue.makeDouble(distance);
    } 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()) + ", " + FmtUtils.stringForNode(v3.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 40 with FactoryException

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

the class GenericFilterFunction method exec.

public Boolean exec(Node v1, Node v2) {
    try {
        // Check if the first literal is unparseable or geometry is empty (always fails).
        GeometryWrapper geometry1 = GeometryWrapper.extract(v1, GeometryIndex.PRIMARY);
        if (geometry1.isEmpty()) {
            return Boolean.FALSE;
        }
        // Check if the second literal is unparseable or geometry is empty (always fails).
        GeometryWrapper geometry2 = GeometryWrapper.extract(v2, GeometryIndex.SECONDARY);
        if (geometry2.isEmpty()) {
            return Boolean.FALSE;
        }
        if (!permittedTopology(geometry1.getDimensionInfo(), geometry2.getDimensionInfo())) {
            return Boolean.FALSE;
        }
        boolean result = relate(geometry1, geometry2);
        return result;
    } catch (DatatypeFormatException | FactoryException | MismatchedDimensionException | TransformException ex) {
        throw new ExprEvalException(ex.getMessage() + ": " + FmtUtils.stringForNode(v1) + ", " + FmtUtils.stringForNode(v2), 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) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

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