Search in sources :

Example 81 with Geometry

use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.

the class TriangleTest method checkCentroid.

public void checkCentroid(final String wkt, final Point expectedValue) throws Exception {
    final Geometry g = this.geometryFactory.geometry(wkt);
    final TriangleImpl t = newTriangle(g);
    Point centroid = Triangles.centroid(t.p0, t.p1, t.p2);
    // System.out.println("(Static) centroid = " + centroid);
    assertEquals(expectedValue.toString(), centroid.toString());
    // Test Instance version
    // 
    centroid = t.centroid();
    // System.out.println("(Instance) centroid = " + centroid.toString());
    assertEquals(expectedValue.toString(), centroid.toString());
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) TriangleImpl(com.revolsys.geometry.model.util.TriangleImpl) Point(com.revolsys.geometry.model.Point)

Example 82 with Geometry

use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.

the class PreparedPolygonPredicateStressTest method checkContains.

public boolean checkContains(final Geometry target, final Geometry test) {
    final boolean expectedResult = target.contains(test);
    final Geometry prepGeom = target.prepare();
    final boolean prepResult = prepGeom.contains(test);
    if (prepResult != expectedResult) {
        return false;
    }
    return true;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry)

Example 83 with Geometry

use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.

the class STRtreeTest method testQuery.

public void testQuery() throws Throwable {
    final ArrayList geometries = new ArrayList();
    geometries.add(this.factory.lineString(new Point[] { new PointDoubleXY(0, 0), new PointDoubleXY(10, 10) }));
    geometries.add(this.factory.lineString(new Point[] { new PointDoubleXY(20, 20), new PointDoubleXY(30, 30) }));
    geometries.add(this.factory.lineString(new Point[] { new PointDoubleXY(20, 20), new PointDoubleXY(30, 30) }));
    final STRtreeDemo.TestTree t = new STRtreeDemo.TestTree(4);
    for (final Iterator i = geometries.iterator(); i.hasNext(); ) {
        final Geometry g = (Geometry) i.next();
        t.insertItem(g.getBoundingBox(), new Object());
    }
    t.build();
    try {
        assertEquals(1, t.getItems(new BoundingBoxDoubleXY(5, 5, 6, 6)).size());
        assertEquals(0, t.getItems(new BoundingBoxDoubleXY(20, 0, 30, 10)).size());
        assertEquals(2, t.getItems(new BoundingBoxDoubleXY(25, 25, 26, 26)).size());
        assertEquals(3, t.getItems(new BoundingBoxDoubleXY(0, 0, 100, 100)).size());
    } catch (final Throwable x) {
        STRtreeDemo.printSourceData(geometries, System.out);
        STRtreeDemo.printLevels(t, System.out);
        throw x;
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Example 84 with Geometry

use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.

the class CascadedPolygonUnionTester method unionIterated.

public Geometry unionIterated(final Collection<? extends Polygon> polygons) {
    Geometry unionAll = null;
    int count = 0;
    for (final Polygon polygon : polygons) {
        if (unionAll == null) {
            unionAll = polygon.clone();
        } else {
            unionAll = unionAll.union(polygon);
        }
        count++;
        if (count % 100 == 0) {
            System.out.print(".");
        }
    }
    return unionAll;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Polygon(com.revolsys.geometry.model.Polygon)

Example 85 with Geometry

use of com.revolsys.geometry.model.Geometry 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)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)488 Point (com.revolsys.geometry.model.Point)140 LineString (com.revolsys.geometry.model.LineString)87 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)75 ArrayList (java.util.ArrayList)70 BoundingBox (com.revolsys.geometry.model.BoundingBox)39 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)39 Polygon (com.revolsys.geometry.model.Polygon)34 List (java.util.List)33 Record (com.revolsys.record.Record)32 Iterator (java.util.Iterator)20 RecordDefinition (com.revolsys.record.schema.RecordDefinition)18 LinearRing (com.revolsys.geometry.model.LinearRing)16 Vertex (com.revolsys.geometry.model.vertex.Vertex)16 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)14 LineSegment (com.revolsys.geometry.model.segment.LineSegment)13 GeometricShapeFactory (com.revolsys.geometry.util.GeometricShapeFactory)13 FieldDefinition (com.revolsys.record.schema.FieldDefinition)12 DataType (com.revolsys.datatype.DataType)10 IOException (java.io.IOException)10