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