Search in sources :

Example 1 with IsValidOp

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

the class PolygonGenerator method newGeometry.

/**
 * As the user increases the number of points, the probability of creating a random valid polygon decreases.
 * Please take not of this when selecting the generation style, and the number of points.
 *
 * May return null if a geometry could not be created.
 *
 * @see #getNumberPoints()
 * @see #setNumberPoints(int)
 * @see #getGenerationAlgorithm()
 * @see #setGenerationAlgorithm(int)
 *
 * @see #BOX
 * @see #ARC
 *
 * @see com.revolsys.geometry.testold.generator.GeometryGenerator#newIterator()
 *
 * @throws IllegalStateException When the alg is not valid or the number of points is invalid
 * @throws NullPointerException when either the Geometry Factory, or the Bounding Box are undefined.
 */
@Override
public Geometry newGeometry() {
    if (this.geometryFactory == null) {
        throw new NullPointerException("GeometryFactoryI is not declared");
    }
    if (this.boundingBox == null || this.boundingBox.isEmpty()) {
        throw new NullPointerException("Bounding Box is not declared");
    }
    if (this.numberPoints < 4) {
        throw new IllegalStateException("Too few points");
    }
    // base x
    final double x = this.boundingBox.getMinX();
    final double dx = this.boundingBox.getMaxX() - x;
    // base y
    final double y = this.boundingBox.getMinY();
    final double dy = this.boundingBox.getMaxY() - y;
    Polygon p = null;
    for (int i = 0; i < RUNS; i++) {
        switch(getGenerationAlgorithm()) {
            case BOX:
                p = newBox(x, dx, y, dy, this.numberHoles, this.numberPoints, this.geometryFactory);
                break;
            case ARC:
                p = newArc(x, dx, y, dy, this.numberHoles, this.numberPoints, this.geometryFactory);
                break;
            default:
                throw new IllegalStateException("Invalid Alg. Specified");
        }
        final IsValidOp valid = new IsValidOp(p);
        if (valid.isValid()) {
            return p;
        }
    }
    return null;
}
Also used : IsValidOp(com.revolsys.geometry.operation.valid.IsValidOp) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Example 2 with IsValidOp

use of com.revolsys.geometry.operation.valid.IsValidOp 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 3 with IsValidOp

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

the class ValidSelfTouchingRingFormingHoleTest method checkIsValidSTR.

private void checkIsValidSTR(final String wkt, final boolean expected) {
    final Geometry geom = fromWKT(wkt);
    final IsValidOp validator = new IsValidOp(geom);
    validator.setSelfTouchingRingFormingHoleValid(true);
    final boolean isValid = validator.isValid();
    assertTrue(isValid == expected);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) IsValidOp(com.revolsys.geometry.operation.valid.IsValidOp)

Example 4 with IsValidOp

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

the class ValidSelfTouchingRingFormingHoleTest method checkIsValidDefault.

private void checkIsValidDefault(final String wkt, final boolean expected) {
    final Geometry geom = fromWKT(wkt);
    final IsValidOp validator = new IsValidOp(geom);
    final boolean isValid = validator.isValid();
    assertTrue(isValid == expected);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) IsValidOp(com.revolsys.geometry.operation.valid.IsValidOp)

Example 5 with IsValidOp

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

the class LineStringGenerator method newGeometry.

/**
 * As the user increases the number of points, the probability of creating a random valid linestring decreases.
 * Please take not of this when selecting the generation style, and the number of points.
 *
 * May return null if a geometry could not be created.
 *
 * @see #getNumberPoints()
 * @see #setNumberPoints(int)
 * @see #getGenerationAlgorithm()
 * @see #setGenerationAlgorithm(int)
 *
 * @see #VERT
 * @see #HORZ
 * @see #ARC
 *
 * @see com.revolsys.geometry.testold.generator.GeometryGenerator#newIterator()
 *
 * @throws IllegalStateException When the alg is not valid or the number of points is invalid
 * @throws NullPointerException when either the Geometry Factory, or the Bounding Box are undefined.
 */
@Override
public Geometry newGeometry() {
    if (this.geometryFactory == null) {
        throw new NullPointerException("GeometryFactoryI is not declared");
    }
    if (this.boundingBox == null || this.boundingBox.isEmpty()) {
        throw new NullPointerException("Bounding Box is not declared");
    }
    if (this.numberPoints < 2) {
        throw new IllegalStateException("Too few points");
    }
    final Point[] coords = new Point[this.numberPoints];
    // base x
    final double x = this.boundingBox.getMinX();
    final double dx = this.boundingBox.getMaxX() - x;
    // base y
    final double y = this.boundingBox.getMinY();
    final double dy = this.boundingBox.getMaxY() - y;
    for (int i = 0; i < RUNS; i++) {
        switch(getGenerationAlgorithm()) {
            case VERT:
                fillVert(x, dx, y, dy, coords, this.geometryFactory);
                break;
            case HORZ:
                fillHorz(x, dx, y, dy, coords, this.geometryFactory);
                break;
            case ARC:
                fillArc(x, dx, y, dy, coords, this.geometryFactory);
                break;
            default:
                throw new IllegalStateException("Invalid Alg. Specified");
        }
        final LineString ls = this.geometryFactory.lineString(coords);
        final IsValidOp valid = new IsValidOp(ls);
        if (valid.isValid()) {
            return ls;
        }
    }
    return null;
}
Also used : LineString(com.revolsys.geometry.model.LineString) IsValidOp(com.revolsys.geometry.operation.valid.IsValidOp) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Aggregations

IsValidOp (com.revolsys.geometry.operation.valid.IsValidOp)9 Geometry (com.revolsys.geometry.model.Geometry)6 Point (com.revolsys.geometry.model.Point)3 GeometryValidationError (com.revolsys.geometry.operation.valid.GeometryValidationError)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LineString (com.revolsys.geometry.model.LineString)1 Polygon (com.revolsys.geometry.model.Polygon)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1 CoordinateNaNError (com.revolsys.geometry.operation.valid.CoordinateNaNError)1 Identifier (com.revolsys.identifier.Identifier)1 CodeTable (com.revolsys.record.code.CodeTable)1 CodeTableProperty (com.revolsys.record.code.CodeTableProperty)1 BigDecimal (java.math.BigDecimal)1