Search in sources :

Example 6 with IsValidOp

use of org.locationtech.jts.operation.valid.IsValidOp 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

IsValidOp (org.locationtech.jts.operation.valid.IsValidOp)6 TopologyValidationError (org.locationtech.jts.operation.valid.TopologyValidationError)4 PrestoException (com.facebook.presto.spi.PrestoException)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 IsSimpleOp (org.locationtech.jts.operation.IsSimpleOp)2 ByteProcessor (ij.process.ByteProcessor)1 ImageStatistics (ij.process.ImageStatistics)1 BufferedImage (java.awt.image.BufferedImage)1 DataBufferByte (java.awt.image.DataBufferByte)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1