Search in sources :

Example 1 with GeometryWrapper

use of org.apache.jena.geosparql.implementation.GeometryWrapper in project jena by apache.

the class ModeSRS method search.

public void search(Model model) {
    ExtendedIterator<RDFNode> nodeIter = model.listObjectsOfProperty(Geo.HAS_SERIALIZATION_PROP);
    boolean isGeometryLiteralsFound = nodeIter.hasNext();
    if (!isGeometryLiteralsFound) {
        NodeIterator wktNodeIter = model.listObjectsOfProperty(Geo.AS_WKT_PROP);
        NodeIterator gmlNodeIter = model.listObjectsOfProperty(Geo.AS_GML_PROP);
        nodeIter = wktNodeIter.andThen(gmlNodeIter);
    }
    while (nodeIter.hasNext()) {
        RDFNode node = nodeIter.next();
        if (node.isLiteral()) {
            GeometryWrapper geometryWrapper = GeometryWrapper.extract(node.asLiteral());
            String srsURI = geometryWrapper.getSrsURI();
            // Put the SRS URI into the map.
            Integer count;
            if (srsMap.containsKey(srsURI)) {
                count = srsMap.get(srsURI);
                count++;
            } else {
                count = 1;
            }
            srsMap.put(srsURI, count);
        }
    }
    if (!isGeometryLiteralsFound) {
        // No GeometryLiterals so check for Geo predicates use.
        List<RDFNode> geoList = model.listObjectsOfProperty(SpatialExtension.GEO_LAT_PROP).toList();
        if (!geoList.isEmpty()) {
            srsMap.put(SRS_URI.WGS84_CRS, geoList.size());
        }
    }
    srsList = srsMap.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors.toList());
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 2 with GeometryWrapper

use of org.apache.jena.geosparql.implementation.GeometryWrapper in project jena by apache.

the class GenericSpatialBoxPropertyFunction method extractObjectArguments.

@Override
protected SpatialArguments extractObjectArguments(Node predicate, PropFuncArg object, SRSInfo indexSRSInfo) {
    try {
        // Check minimum arguments.
        List<Node> objectArgs = object.getArgList();
        if (objectArgs.size() < 4) {
            throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Minimum of 4 arguments.");
        } else if (objectArgs.size() > 5) {
            throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Maximum of 5 arguments.");
        }
        Node latMin = objectArgs.get(LAT_MIN_POS);
        Node lonMin = objectArgs.get(LON_MIN_POS);
        Node latMax = objectArgs.get(LAT_MAX_POS);
        Node lonMax = objectArgs.get(LON_MAX_POS);
        // Check minimum arguments are all bound.
        if (latMin.isVariable() || lonMin.isVariable() || latMax.isVariable() || lonMax.isVariable()) {
            throw new ExprEvalException("Arguments are not all concrete: " + FmtUtils.stringForNode(latMin) + ", " + FmtUtils.stringForNode(lonMin) + FmtUtils.stringForNode(latMax) + ", " + FmtUtils.stringForNode(lonMax));
        }
        // Find the limit.
        int limit;
        if (objectArgs.size() > LIMIT_POS) {
            NodeValue limitNode = NodeValue.makeNode(objectArgs.get(LIMIT_POS));
            if (!limitNode.isInteger()) {
                throw new ExprEvalException("Not an integer: " + FmtUtils.stringForNode(limitNode.getNode()));
            }
            limit = limitNode.getInteger().intValue();
        } else {
            limit = DEFAULT_LIMIT;
        }
        Node geometryNode = ConvertLatLonBox.toNode(latMin, lonMin, latMax, lonMax);
        GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometryNode);
        SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, indexSRSInfo);
        return new SpatialArguments(limit, geometryWrapper, searchEnvelope);
    } catch (DatatypeFormatException ex) {
        throw new ExprEvalException(ex.getMessage(), ex);
    }
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) SpatialArguments(org.apache.jena.geosparql.spatial.property_functions.SpatialArguments) DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) Node(org.apache.jena.graph.Node) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) SearchEnvelope(org.apache.jena.geosparql.spatial.SearchEnvelope) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 3 with GeometryWrapper

use of org.apache.jena.geosparql.implementation.GeometryWrapper in project jena by apache.

the class GenericCardinalPropertyFunction method extractObjectArguments.

@Override
protected SpatialArguments extractObjectArguments(Node predicate, PropFuncArg object, SRSInfo indexSRSInfo) {
    try {
        // Check minimum arguments.
        List<Node> objectArgs = object.getArgList();
        if (objectArgs.size() < 2) {
            throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Minimum of 2 arguments.");
        } else if (objectArgs.size() > 3) {
            throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Maximum of 3 arguments.");
        }
        Node lat = objectArgs.get(LAT_POS);
        Node lon = objectArgs.get(LON_POS);
        // Check minimum arguments are all bound.
        if (lat.isVariable() || lon.isVariable()) {
            throw new ExprEvalException("Arguments are not all concrete: " + FmtUtils.stringForNode(lat) + ", " + FmtUtils.stringForNode(lon));
        }
        // Find the limit.
        int limit;
        if (objectArgs.size() > LIMIT_POS) {
            NodeValue limitNode = NodeValue.makeNode(objectArgs.get(LIMIT_POS));
            if (!limitNode.isInteger()) {
                throw new ExprEvalException("Not an integer: " + FmtUtils.stringForNode(limitNode.getNode()));
            }
            limit = limitNode.getInteger().intValue();
        } else {
            limit = DEFAULT_LIMIT;
        }
        GeometryWrapper geometryWrapper = ConvertLatLon.toGeometryWrapper(lat, lon);
        SearchEnvelope searchEnvelope = buildSearchEnvelope(geometryWrapper, indexSRSInfo);
        return new SpatialArguments(limit, geometryWrapper, searchEnvelope);
    } catch (DatatypeFormatException ex) {
        throw new ExprEvalException(ex.getMessage(), ex);
    }
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) SpatialArguments(org.apache.jena.geosparql.spatial.property_functions.SpatialArguments) DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) Node(org.apache.jena.graph.Node) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) SearchEnvelope(org.apache.jena.geosparql.spatial.SearchEnvelope) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 4 with GeometryWrapper

use of org.apache.jena.geosparql.implementation.GeometryWrapper in project jena by apache.

the class NearbyPF method extractObjectArguments.

@Override
protected SpatialArguments extractObjectArguments(Node predicate, PropFuncArg object, SRSInfo indexSRSInfo) {
    try {
        // Check minimum arguments.
        List<Node> objectArgs = object.getArgList();
        if (objectArgs.size() < 3) {
            throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Minimum of 3 arguments.");
        } else if (objectArgs.size() > 5) {
            throw new ExprEvalException(FmtUtils.stringForNode(predicate) + ": Maximum of 5 arguments.");
        }
        Node lat = objectArgs.get(LAT_POS);
        Node lon = objectArgs.get(LON_POS);
        NodeValue radiusNode = NodeValue.makeNode(objectArgs.get(RADIUS_POS));
        // Check minimum arguments are all bound.
        if (lat.isVariable() || lon.isVariable() || !radiusNode.isDouble()) {
            throw new ExprEvalException("Arguments are not all concrete: " + FmtUtils.stringForNode(lat) + ", " + FmtUtils.stringForNode(lon) + ", " + FmtUtils.stringForNode(radiusNode.asNode()));
        }
        radius = radiusNode.getDouble();
        // Find the units.
        if (objectArgs.size() > UNITS_POS) {
            Node unitsNode = objectArgs.get(UNITS_POS);
            if (!unitsNode.isURI()) {
                throw new ExprEvalException("Not a URI: " + FmtUtils.stringForNode(unitsNode));
            }
            unitsURI = unitsNode.getURI();
        } else {
            unitsURI = DEFAULT_UNITS;
        }
        // Find the limit.
        int limit;
        if (objectArgs.size() > LIMIT_POS) {
            NodeValue limitNode = NodeValue.makeNode(objectArgs.get(LIMIT_POS));
            if (!limitNode.isInteger()) {
                throw new ExprEvalException("Not an integer: " + FmtUtils.stringForNode(limitNode.getNode()));
            }
            limit = limitNode.getInteger().intValue();
        } else {
            limit = DEFAULT_LIMIT;
        }
        GeometryWrapper geometryWrapper = ConvertLatLon.toGeometryWrapper(lat, lon);
        SearchEnvelope searchEnvelope = SearchEnvelope.build(geometryWrapper, indexSRSInfo, radius, unitsURI);
        return new SpatialArguments(limit, geometryWrapper, searchEnvelope);
    } catch (DatatypeFormatException ex) {
        throw new ExprEvalException(ex.getMessage(), ex);
    }
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) SpatialArguments(org.apache.jena.geosparql.spatial.property_functions.SpatialArguments) DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) Node(org.apache.jena.graph.Node) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) SearchEnvelope(org.apache.jena.geosparql.spatial.SearchEnvelope) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 5 with GeometryWrapper

use of org.apache.jena.geosparql.implementation.GeometryWrapper in project jena by apache.

the class GenericCardinalGeomPropertyFunction method checkSecondFilter.

@Override
protected boolean checkSecondFilter(SpatialArguments spatialArguments, GeometryWrapper targetGeometryWrapper) {
    // Test Geometry against the Geometry from Object to see if it is a success.
    // Used when checking against bound Subjects.
    // Cardinal functions only check against the search envelope.
    SearchEnvelope searchEnvelope = spatialArguments.getSearchEnvelope();
    try {
        GeometryWrapper srs = targetGeometryWrapper.convertSRS(searchEnvelope.getSrsURI());
        Envelope targetEnvelope = srs.getEnvelope();
        boolean result = searchEnvelope.check(targetEnvelope);
        return result;
    } catch (FactoryException | MismatchedDimensionException | TransformException ex) {
        throw new ExprEvalException(ex.getMessage() + ": " + targetGeometryWrapper.asLiteral(), ex);
    }
}
Also used : FactoryException(org.opengis.util.FactoryException) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) TransformException(org.opengis.referencing.operation.TransformException) SearchEnvelope(org.apache.jena.geosparql.spatial.SearchEnvelope) SearchEnvelope(org.apache.jena.geosparql.spatial.SearchEnvelope) Envelope(org.locationtech.jts.geom.Envelope) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Aggregations

GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)356 Test (org.junit.Test)297 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)70 Node (org.apache.jena.graph.Node)64 SearchEnvelope (org.apache.jena.geosparql.spatial.SearchEnvelope)63 Literal (org.apache.jena.rdf.model.Literal)59 PropFuncArg (org.apache.jena.sparql.pfunction.PropFuncArg)53 LineString (org.locationtech.jts.geom.LineString)52 SpatialArguments (org.apache.jena.geosparql.spatial.property_functions.SpatialArguments)51 Geometry (org.locationtech.jts.geom.Geometry)48 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)39 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)36 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)32 NodeValue (org.apache.jena.sparql.expr.NodeValue)24 TransformException (org.opengis.referencing.operation.TransformException)21 FactoryException (org.opengis.util.FactoryException)21 Envelope (org.locationtech.jts.geom.Envelope)19 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)19 Coordinate (org.locationtech.jts.geom.Coordinate)15 Resource (org.apache.jena.rdf.model.Resource)13