Search in sources :

Example 66 with Geometry

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

the class LinearLocationTest method testGetSegmentMultiLineString.

public void testGetSegmentMultiLineString() throws Exception {
    final Geometry line = this.geometryFactory.geometry("MULTILINESTRING ((0 0, 10 0, 20 0), (20 0, 30 0))");
    final LocationIndexedLine indexedLine = new LocationIndexedLine(line);
    final LinearLocation loc0 = indexedLine.indexOf(new PointDoubleXY(0, 0));
    final LinearLocation loc0_5 = indexedLine.indexOf(new PointDoubleXY(5, 0));
    final LinearLocation loc1 = indexedLine.indexOf(new PointDoubleXY(10, 0));
    final LinearLocation loc2 = indexedLine.indexOf(new PointDoubleXY(20, 0));
    final LinearLocation loc2B = new LinearLocation(1, 0, 0.0);
    final LinearLocation loc2_5 = indexedLine.indexOf(new PointDoubleXY(25, 0));
    final LinearLocation loc3 = indexedLine.indexOf(new PointDoubleXY(30, 0));
    final LineSegment seg0 = new LineSegmentDouble(new PointDoubleXY(0, 0), new PointDoubleXY(10, 0));
    final LineSegment seg1 = new LineSegmentDouble(new PointDoubleXY(10, 0), new PointDoubleXY(20, 0));
    final LineSegment seg2 = new LineSegmentDouble(new PointDoubleXY(20, 0), new PointDoubleXY(30, 0));
    assertTrue(loc0.getSegment(line).equals(seg0));
    assertTrue(loc0_5.getSegment(line).equals(seg0));
    assertTrue(loc1.getSegment(line).equals(seg1));
    assertTrue(loc2.getSegment(line).equals(seg1));
    assertTrue(loc2_5.getSegment(line).equals(seg2));
    assertTrue(loc3.getSegment(line).equals(seg2));
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LocationIndexedLine(com.revolsys.geometry.linearref.LocationIndexedLine) LinearLocation(com.revolsys.geometry.linearref.LinearLocation) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 67 with Geometry

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

the class TestUtil method doTestGeometry.

public static void doTestGeometry(final Class<?> clazz, final String file) {
    boolean valid = true;
    final Resource resource = new ClassPathResource(file, clazz);
    try (Reader<Record> reader = RecordReader.newRecordReader(resource)) {
        int i = 0;
        for (final Record object : reader) {
            final int srid = object.getInteger("srid");
            final int axisCount = object.getInteger("axisCount");
            final double scaleXy = object.getInteger("scaleXy");
            final double scaleZ = object.getInteger("scaleZ");
            final double[] scales = { scaleXy, scaleXy, scaleZ };
            final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
            final String wkt = object.getValue("wkt");
            final Geometry geometry = geometryFactory.geometry(wkt);
            valid &= equalsExpectedWkt(i, object, geometry);
            final CoordinateSystem coordinateSystem = geometry.getCoordinateSystem();
            GeometryFactory otherGeometryFactory;
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
                otherGeometryFactory = GeometryFactory.fixed(projectedCoordinateSystem.getCoordinateSystemId(), axisCount, scales);
            } else {
                otherGeometryFactory = GeometryFactory.fixed(3005, axisCount, scales);
            }
            final Geometry convertedGeometry = geometry.convertGeometry(otherGeometryFactory);
            final Geometry convertedBackGeometry = convertedGeometry.convertGeometry(geometryFactory);
            valid &= equalsExpectedGeometry(i, convertedBackGeometry, geometry);
            i++;
        }
    }
    if (!valid) {
        Assert.fail("Has Errors");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Resource(com.revolsys.spring.resource.Resource) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Geometry(com.revolsys.geometry.model.Geometry) Record(com.revolsys.record.Record)

Example 68 with Geometry

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

the class ConvexHullTest method test6.

public void test6() throws Exception {
    final Punctual inputGeometry = GEOMETRY_FACTORY_1M.punctual(2, 0, 0, 5, 1, 10, 0);
    final Geometry actualGeometry = inputGeometry.convexHull();
    final Geometry expectedGeometry = GEOMETRY_FACTORY_1M.geometry("POLYGON((0 0,5 1,10 0,0 0))");
    assertEquals(expectedGeometry.toString(), actualGeometry.toString());
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Punctual(com.revolsys.geometry.model.Punctual)

Example 69 with Geometry

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

the class ConvexHullTest method test5.

public void test5() throws Exception {
    final Geometry geometry = GEOMETRY_FACTORY_1M.punctual(2, 0, 0, 5, 0, 10, 0);
    final LineString convexHull = (LineString) GEOMETRY_FACTORY_1M.geometry("LINESTRING(0 0,10 0)");
    assertTrue(convexHull.equals(2, geometry.convexHull()));
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString)

Example 70 with Geometry

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

the class ConvexHullTest method testAllIdenticalPoints.

public void testAllIdenticalPoints() throws Exception {
    final List<Point> points = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        points.add(new PointDoubleXY(0.0, 0));
    }
    final Geometry actualGeometry = ConvexHull.convexHull(this.geometryFactory, points);
    final Geometry expectedGeometry = this.geometryFactory.geometry("POINT(0 0)");
    assertTrue(expectedGeometry.equals(2, actualGeometry));
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

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