Search in sources :

Example 1 with IntersectionMatrix

use of org.locationtech.jts.geom.IntersectionMatrix in project jena by apache.

the class RelateFF 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.isString()) {
            throw new ExprEvalException("Not a String: " + FmtUtils.stringForNode(v3.asNode()));
        }
        String compareMatrix = v3.getString();
        IntersectionMatrix matrix = geometry1.relate(geometry2);
        boolean result = matrix.matches(compareMatrix);
        return NodeValue.makeBoolean(result);
    } 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) IntersectionMatrix(org.locationtech.jts.geom.IntersectionMatrix) TransformException(org.opengis.referencing.operation.TransformException) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException)

Aggregations

DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)1 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)1 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)1 IntersectionMatrix (org.locationtech.jts.geom.IntersectionMatrix)1 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)1 TransformException (org.opengis.referencing.operation.TransformException)1 FactoryException (org.opengis.util.FactoryException)1