Search in sources :

Example 1 with GeometryValidationError

use of com.revolsys.geometry.operation.valid.GeometryValidationError in project com.revolsys.open by revolsys.

the class IsValidTest method testNaNCoordinate.

public void testNaNCoordinate() throws Exception {
    final Point badCoord = new PointDoubleXY(1.0, Double.NaN);
    final Point[] pts = { new PointDoubleXY(0.0, 0.0), badCoord };
    final Geometry line = this.geometryFactory.lineString(pts);
    final IsValidOp isValidOp = new IsValidOp(line);
    final boolean valid = isValidOp.isValid();
    final GeometryValidationError err = isValidOp.getValidationError();
    final Point errCoord = err.getErrorPoint();
    assertTrue(err instanceof CoordinateNaNError);
    assertTrue(Double.isNaN(errCoord.getY()));
    assertEquals(false, valid);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryValidationError(com.revolsys.geometry.operation.valid.GeometryValidationError) CoordinateNaNError(com.revolsys.geometry.operation.valid.CoordinateNaNError) IsValidOp(com.revolsys.geometry.operation.valid.IsValidOp) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 2 with GeometryValidationError

use of com.revolsys.geometry.operation.valid.GeometryValidationError in project com.revolsys.open by revolsys.

the class IsSimpleTest method runIsSimpleTest.

private void runIsSimpleTest(final String wkt, final boolean expectedResult, final Point expectedLocation) throws ParseException {
    final Geometry g = this.geometryFactory.geometry(wkt);
    final List<GeometryValidationError> errors = g.getIsSimpleErrors();
    final boolean isSimple = g.isSimple();
    // if geom is not simple, should have a valid location
    assertTrue(isSimple || !errors.isEmpty());
    assertTrue(expectedResult == isSimple);
    if (!isSimple && expectedLocation != null) {
        final Point nonSimpleLoc = errors.get(0).getErrorPoint();
        assertTrue(expectedLocation.distancePoint(nonSimpleLoc) < TOLERANCE);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryValidationError(com.revolsys.geometry.operation.valid.GeometryValidationError) Point(com.revolsys.geometry.model.Point)

Example 3 with GeometryValidationError

use of com.revolsys.geometry.operation.valid.GeometryValidationError in project com.revolsys.open by revolsys.

the class Lineal method addIsSimpleErrors.

static boolean addIsSimpleErrors(final Lineal lineal, final List<GeometryValidationError> errors, final boolean shortCircuit) {
    final LineSegmentIndex index = new LineSegmentIndex(lineal);
    for (final Segment segment : lineal.segments()) {
        final int segmentIndex = segment.getSegmentIndex();
        final int partIndex = segment.getPartIndex();
        if (segment.getLength() == 0) {
            errors.add(new DuplicateVertexError(segment.getGeometryVertex(0)));
        } else {
            final List<LineSegment> segments = index.queryBoundingBox(segment);
            for (final LineSegment lineSegment : segments) {
                final Segment segment2 = (Segment) lineSegment;
                final int partIndex2 = segment2.getPartIndex();
                final int segmentIndex2 = segment2.getSegmentIndex();
                if (partIndex2 > partIndex || partIndex == partIndex2 && segmentIndex2 > segmentIndex) {
                    if (segment.equals(lineSegment)) {
                        final SelfOverlapSegmentError error = new SelfOverlapSegmentError(segment);
                        errors.add(error);
                        if (shortCircuit) {
                            return false;
                        }
                    } else {
                        final Geometry intersection = segment.getIntersection(lineSegment);
                        if (intersection instanceof Point) {
                            final Point pointIntersection = (Point) intersection;
                            boolean isIntersection = true;
                            // Process segments on the same linestring part
                            if (partIndex == partIndex2) {
                                // segment
                                if (segmentIndex + 1 == segmentIndex2) {
                                    if (lineSegment.equalsVertex(2, 0, pointIntersection)) {
                                        isIntersection = false;
                                    }
                                // A loop can touch itself at the start/end
                                } else if (segment.isLineClosed()) {
                                    if (segment.isLineStart() && segment2.isLineEnd()) {
                                        if (segment.equalsVertex(2, 0, pointIntersection)) {
                                            isIntersection = false;
                                        }
                                    }
                                }
                            } else {
                                if (!segment.isLineClosed() && !segment2.isLineClosed()) {
                                    final boolean segment1EndIntersection = segment.isEndIntersection(pointIntersection);
                                    final boolean segment2EndIntersection = segment2.isEndIntersection(pointIntersection);
                                    if (segment1EndIntersection && segment2EndIntersection) {
                                        isIntersection = false;
                                    }
                                }
                            }
                            if (isIntersection) {
                                GeometryValidationError error;
                                if (segment.equalsVertex(2, 0, pointIntersection)) {
                                    final Vertex vertex = segment.getGeometryVertex(0);
                                    error = new SelfIntersectionVertexError(vertex);
                                } else if (segment.equalsVertex(2, 1, pointIntersection)) {
                                    final Vertex vertex = segment.getGeometryVertex(1);
                                    error = new SelfIntersectionVertexError(vertex);
                                } else {
                                    error = new SelfIntersectionPointError(lineal, pointIntersection);
                                }
                                errors.add(error);
                                if (shortCircuit) {
                                    return false;
                                }
                            }
                        } else if (intersection instanceof LineSegment) {
                            final LineSegment lineIntersection = (LineSegment) intersection;
                            GeometryValidationError error;
                            if (segment.equals(lineIntersection)) {
                                error = new SelfOverlapSegmentError(segment);
                            } else if (lineSegment.equals(lineIntersection)) {
                                error = new SelfOverlapSegmentError(segment2);
                            } else {
                                error = new SelfOverlapLineSegmentError(lineal, lineIntersection);
                            }
                            errors.add(error);
                            if (shortCircuit) {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }
    return errors.isEmpty();
}
Also used : GeometryValidationError(com.revolsys.geometry.operation.valid.GeometryValidationError) Vertex(com.revolsys.geometry.model.vertex.Vertex) SelfOverlapLineSegmentError(com.revolsys.geometry.operation.simple.SelfOverlapLineSegmentError) SelfIntersectionPointError(com.revolsys.geometry.operation.simple.SelfIntersectionPointError) DuplicateVertexError(com.revolsys.geometry.operation.simple.DuplicateVertexError) LineSegment(com.revolsys.geometry.model.segment.LineSegment) Segment(com.revolsys.geometry.model.segment.Segment) LineSegmentIndex(com.revolsys.geometry.index.LineSegmentIndex) SelfIntersectionVertexError(com.revolsys.geometry.operation.simple.SelfIntersectionVertexError) SelfOverlapSegmentError(com.revolsys.geometry.operation.simple.SelfOverlapSegmentError) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 4 with GeometryValidationError

use of com.revolsys.geometry.operation.valid.GeometryValidationError in project com.revolsys.open by revolsys.

the class ValidationFunctions method invalidGeoms.

public static Geometry invalidGeoms(final Geometry g) {
    final List invalidGeoms = new ArrayList();
    for (int i = 0; i < g.getGeometryCount(); i++) {
        final Geometry geom = g.getGeometry(i);
        final IsValidOp ivop = new IsValidOp(geom);
        final GeometryValidationError err = ivop.getValidationError();
        if (err != null) {
            invalidGeoms.add(geom);
        }
    }
    return g.getGeometryFactory().buildGeometry(invalidGeoms);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryValidationError(com.revolsys.geometry.operation.valid.GeometryValidationError) ArrayList(java.util.ArrayList) IsValidOp(com.revolsys.geometry.operation.valid.IsValidOp) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with GeometryValidationError

use of com.revolsys.geometry.operation.valid.GeometryValidationError in project com.revolsys.open by revolsys.

the class ValidationFunctions method invalidLocations.

/**
 * Validates all geometries in a collection independently.
 * Errors are returned as points at the invalid location
 *
 * @param g
 * @return the invalid locations, if any
 */
public static Geometry invalidLocations(final Geometry g) {
    final List invalidLoc = new ArrayList();
    for (int i = 0; i < g.getGeometryCount(); i++) {
        final Geometry geom = g.getGeometry(i);
        final IsValidOp ivop = new IsValidOp(geom);
        final GeometryValidationError err = ivop.getValidationError();
        if (err != null) {
            invalidLoc.add(g.getGeometryFactory().point(err.getErrorPoint()));
        }
    }
    return g.getGeometryFactory().buildGeometry(invalidLoc);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryValidationError(com.revolsys.geometry.operation.valid.GeometryValidationError) ArrayList(java.util.ArrayList) IsValidOp(com.revolsys.geometry.operation.valid.IsValidOp) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

GeometryValidationError (com.revolsys.geometry.operation.valid.GeometryValidationError)5 Geometry (com.revolsys.geometry.model.Geometry)4 IsValidOp (com.revolsys.geometry.operation.valid.IsValidOp)3 Point (com.revolsys.geometry.model.Point)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LineSegmentIndex (com.revolsys.geometry.index.LineSegmentIndex)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1 LineSegment (com.revolsys.geometry.model.segment.LineSegment)1 Segment (com.revolsys.geometry.model.segment.Segment)1 Vertex (com.revolsys.geometry.model.vertex.Vertex)1 DuplicateVertexError (com.revolsys.geometry.operation.simple.DuplicateVertexError)1 SelfIntersectionPointError (com.revolsys.geometry.operation.simple.SelfIntersectionPointError)1 SelfIntersectionVertexError (com.revolsys.geometry.operation.simple.SelfIntersectionVertexError)1 SelfOverlapLineSegmentError (com.revolsys.geometry.operation.simple.SelfOverlapLineSegmentError)1 SelfOverlapSegmentError (com.revolsys.geometry.operation.simple.SelfOverlapSegmentError)1 CoordinateNaNError (com.revolsys.geometry.operation.valid.CoordinateNaNError)1