Search in sources :

Example 1 with SpatialIndexException

use of org.apache.jena.geosparql.spatial.SpatialIndexException in project jena by apache.

the class GenericSpatialPropertyFunction method execEvaluated.

@Override
public final QueryIterator execEvaluated(Binding binding, Node subject, Node predicate, PropFuncArg object, ExecutionContext execCxt) {
    try {
        spatialIndex = SpatialIndex.retrieve(execCxt);
        spatialArguments = extractObjectArguments(predicate, object, spatialIndex.getSrsInfo());
        return search(binding, execCxt, subject, spatialArguments.limit);
    } catch (SpatialIndexException ex) {
        throw new ExprEvalException(ex.getMessage(), ex);
    }
}
Also used : SpatialIndexException(org.apache.jena.geosparql.spatial.SpatialIndexException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 2 with SpatialIndexException

use of org.apache.jena.geosparql.spatial.SpatialIndexException 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 3 with SpatialIndexException

use of org.apache.jena.geosparql.spatial.SpatialIndexException in project jena by apache.

the class Main method main.

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // Apache SIS j.u.l logging redirection.
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    LOGGER.info("Arguments Received: {}", Arrays.asList(args));
    ArgsConfig argsConfig = new ArgsConfig();
    JCommander jCommander = JCommander.newBuilder().addObject(argsConfig).build();
    jCommander.setProgramName("GeoSPARQL Fuseki");
    jCommander.parse(args);
    if (argsConfig.isHelp()) {
        jCommander.usage();
        return;
    }
    // Setup dataset
    try {
        Dataset dataset = DatasetOperations.setup(argsConfig);
        // Configure server
        GeosparqlServer server = new GeosparqlServer(argsConfig.getPort(), argsConfig.getDatsetName(), argsConfig.isLoopbackOnly(), dataset, argsConfig.isUpdateAllowed());
        server.start();
    } catch (SrsException | DatasetException | SpatialIndexException ex) {
        LOGGER.error("GeoSPARQL Server:  Exiting - {}: {}", ex.getMessage(), argsConfig.getDatsetName());
    }
}
Also used : SrsException(org.apache.jena.geosparql.configuration.SrsException) ArgsConfig(org.apache.jena.fuseki.geosparql.cli.ArgsConfig) JCommander(com.beust.jcommander.JCommander) Dataset(org.apache.jena.query.Dataset) SpatialIndexException(org.apache.jena.geosparql.spatial.SpatialIndexException)

Aggregations

SpatialIndexException (org.apache.jena.geosparql.spatial.SpatialIndexException)3 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)2 JCommander (com.beust.jcommander.JCommander)1 ArgsConfig (org.apache.jena.fuseki.geosparql.cli.ArgsConfig)1 SrsException (org.apache.jena.geosparql.configuration.SrsException)1 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)1 SpatialIndex (org.apache.jena.geosparql.spatial.SpatialIndex)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 Dataset (org.apache.jena.query.Dataset)1 Resource (org.apache.jena.rdf.model.Resource)1 Var (org.apache.jena.sparql.core.Var)1 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 QueryIterConcat (org.apache.jena.sparql.engine.iterator.QueryIterConcat)1 Envelope (org.locationtech.jts.geom.Envelope)1 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)1 TransformException (org.opengis.referencing.operation.TransformException)1 FactoryException (org.opengis.util.FactoryException)1