Search in sources :

Example 1 with IsSimpleOp

use of org.locationtech.jts.operation.IsSimpleOp in project presto by prestodb.

the class GeometryUtils method getGeometryInvalidReason.

public static Optional<String> getGeometryInvalidReason(org.locationtech.jts.geom.Geometry geometry) {
    IsValidOp validOp = new IsValidOp(geometry);
    IsSimpleOp simpleOp = new IsSimpleOp(geometry);
    try {
        TopologyValidationError err = validOp.getValidationError();
        if (err != null) {
            return Optional.of(err.getMessage());
        }
    } catch (UnsupportedOperationException e) {
        // It should not happen in practice.
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Geometry type not valid", e);
    }
    if (!simpleOp.isSimple()) {
        String errorDescription;
        String geometryType = geometry.getGeometryType();
        switch(GeometryType.getForJtsGeometryType(geometryType)) {
            case POINT:
                errorDescription = "Invalid point";
                break;
            case MULTI_POINT:
                errorDescription = "Repeated point";
                break;
            case LINE_STRING:
            case MULTI_LINE_STRING:
                errorDescription = "Self-intersection at or near";
                break;
            case POLYGON:
            case MULTI_POLYGON:
            case GEOMETRY_COLLECTION:
                // In OGC (which JTS follows): Polygons, MultiPolygons, Geometry Collections are simple.
                // This shouldn't happen, but in case it does, return a reasonable generic message.
                errorDescription = "Topology exception at or near";
                break;
            default:
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Unknown geometry type: %s", geometryType));
        }
        org.locationtech.jts.geom.Coordinate nonSimpleLocation = simpleOp.getNonSimpleLocation();
        return Optional.of(format("[%s] %s: (%s %s)", geometryType, errorDescription, nonSimpleLocation.getX(), nonSimpleLocation.getY()));
    }
    return Optional.empty();
}
Also used : IsSimpleOp(org.locationtech.jts.operation.IsSimpleOp) IsValidOp(org.locationtech.jts.operation.valid.IsValidOp) Coordinate(org.locationtech.jts.geom.Coordinate) TopologyValidationError(org.locationtech.jts.operation.valid.TopologyValidationError) PrestoException(com.facebook.presto.spi.PrestoException)

Example 2 with IsSimpleOp

use of org.locationtech.jts.operation.IsSimpleOp in project urban-eureka by errir503.

the class GeometryUtils method getGeometryInvalidReason.

public static Optional<String> getGeometryInvalidReason(org.locationtech.jts.geom.Geometry geometry) {
    IsValidOp validOp = new IsValidOp(geometry);
    IsSimpleOp simpleOp = new IsSimpleOp(geometry);
    try {
        TopologyValidationError err = validOp.getValidationError();
        if (err != null) {
            return Optional.of(err.getMessage());
        }
    } catch (UnsupportedOperationException e) {
        // It should not happen in practice.
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Geometry type not valid", e);
    }
    if (!simpleOp.isSimple()) {
        String errorDescription;
        String geometryType = geometry.getGeometryType();
        switch(GeometryType.getForJtsGeometryType(geometryType)) {
            case POINT:
                errorDescription = "Invalid point";
                break;
            case MULTI_POINT:
                errorDescription = "Repeated point";
                break;
            case LINE_STRING:
            case MULTI_LINE_STRING:
                errorDescription = "Self-intersection at or near";
                break;
            case POLYGON:
            case MULTI_POLYGON:
            case GEOMETRY_COLLECTION:
                // In OGC (which JTS follows): Polygons, MultiPolygons, Geometry Collections are simple.
                // This shouldn't happen, but in case it does, return a reasonable generic message.
                errorDescription = "Topology exception at or near";
                break;
            default:
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Unknown geometry type: %s", geometryType));
        }
        org.locationtech.jts.geom.Coordinate nonSimpleLocation = simpleOp.getNonSimpleLocation();
        return Optional.of(format("[%s] %s: (%s %s)", geometryType, errorDescription, nonSimpleLocation.getX(), nonSimpleLocation.getY()));
    }
    return Optional.empty();
}
Also used : IsSimpleOp(org.locationtech.jts.operation.IsSimpleOp) IsValidOp(org.locationtech.jts.operation.valid.IsValidOp) Coordinate(org.locationtech.jts.geom.Coordinate) TopologyValidationError(org.locationtech.jts.operation.valid.TopologyValidationError) PrestoException(com.facebook.presto.spi.PrestoException)

Aggregations

PrestoException (com.facebook.presto.spi.PrestoException)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 IsSimpleOp (org.locationtech.jts.operation.IsSimpleOp)2 IsValidOp (org.locationtech.jts.operation.valid.IsValidOp)2 TopologyValidationError (org.locationtech.jts.operation.valid.TopologyValidationError)2