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);
}
}
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);
}
}
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());
}
}
Aggregations