Search in sources :

Example 61 with GeometryFactory

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

the class LineStringTest method assertDistanceAlong.

private static void assertDistanceAlong(final double distanceAlong, final double distance, final double x, final double y, final Side side, final double... coordinates) {
    final GeometryFactory geometryFactory = GeometryFactory.worldMercator().convertAxisCount(2);
    final Point point = geometryFactory.point(x, y);
    final LineString line = geometryFactory.lineString(2, coordinates);
    final double actual = line.distanceAlong(point);
    Assert.assertEquals("Distance Along", distanceAlong, actual, 0.0000001);
    final PointLineStringMetrics metrics = line.getMetrics(point);
    Assert.assertEquals("Metrics Distance Along", distanceAlong, metrics.getDistanceAlong(), 0.0000001);
    Assert.assertEquals("Metrics Distance", distance, metrics.getDistance(), 0.0000001);
    Assert.assertEquals("Metrics Side", side, metrics.getSide());
    Assert.assertEquals("Metrics Length", line.getLength(), metrics.getLineLength(), 0.0000001);
    Assert.assertEquals("Distance Along -> Metrics", distanceAlong, metrics.getDistanceAlong(), 0.0000001);
    if (side != null) {
        final Side reverseSide = Side.opposite(side);
        final LineString reverseLine = line.reverse();
        final PointLineStringMetrics reverseMetrics = reverseLine.getMetrics(point);
        Assert.assertEquals("Reverse Metrics Side", reverseSide, reverseMetrics.getSide());
    }
}
Also used : Side(com.revolsys.geometry.model.Side) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) PointLineStringMetrics(com.revolsys.geometry.model.metrics.PointLineStringMetrics) Point(com.revolsys.geometry.model.Point)

Example 62 with GeometryFactory

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

the class LineStringTest method constructEmpty.

@Test
public void constructEmpty() {
    for (int axisCount = 2; axisCount < 4; axisCount++) {
        final GeometryFactory geometryFactory = GeometryFactory.fixed(26910, axisCount, GeometryFactory.newScalesFixed(axisCount, 1000.0));
        // Empty Constructor
        final LineString pointEmpty = geometryFactory.lineString();
        assertEmpty(pointEmpty);
        // Point[] Constructor
        final LineString pointCoordinatesArrayNull = geometryFactory.lineString((Point[]) null);
        assertEmpty(pointCoordinatesArrayNull);
        final LineString pointCoordinatesArraySize0 = geometryFactory.lineString(new Point[0]);
        assertEmpty(pointCoordinatesArraySize0);
        final LineString pointCoordinatesNull = geometryFactory.lineString((Point) null);
        assertEmpty(pointCoordinatesNull);
        // LineString Constructor
        final LineString pointCoordinatesListNull = geometryFactory.lineString((LineString) null);
        assertEmpty(pointCoordinatesListNull);
        final LineString pointCoordinatesListSize0 = geometryFactory.lineString(geometryFactory.lineString());
        assertEmpty(pointCoordinatesListSize0);
        // double[] Constructor
        final LineString pointDoubleArray0Null = geometryFactory.lineString(0, (double[]) null);
        assertEmpty(pointDoubleArray0Null);
        final LineString pointDoubleArray2Null = geometryFactory.lineString(2, (double[]) null);
        assertEmpty(pointDoubleArray2Null);
        final LineString pointDoubleArray0NoValue = geometryFactory.lineString(0);
        assertEmpty(pointDoubleArray0NoValue);
        final LineString pointDoubleArray2NoValue = geometryFactory.lineString(2);
        assertEmpty(pointDoubleArray2NoValue);
        // LineString Constructor
        final LineString pointLineStringNull = geometryFactory.lineString((LineString) null);
        assertEmpty(pointLineStringNull);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Test(org.junit.Test)

Example 63 with GeometryFactory

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

the class PointTest method assertEquals.

public static void assertEquals(final Point point, final double... coordinates) {
    final GeometryFactory geometryFactory = point.getGeometryFactory();
    final GeometryFactory geometryFactory2;
    final int axisCount = geometryFactory.getAxisCount();
    if (geometryFactory.getCoordinateSystem() instanceof ProjectedCoordinateSystem) {
        final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) geometryFactory.getCoordinateSystem();
        final GeographicCoordinateSystem geographicCoordinateSystem = projectedCs.getGeographicCoordinateSystem();
        geometryFactory2 = GeometryFactory.floating(geographicCoordinateSystem.getCoordinateSystemId(), axisCount);
    } else {
        geometryFactory2 = GeometryFactory.floating(26910, axisCount);
    }
    assertCoordinatesEquals(point, coordinates);
    final Point clone = point.newPoint();
    assertCoordinatesEquals(clone, coordinates);
    final Point converted = point.convertGeometry(geometryFactory);
    assertCoordinatesEquals(converted, coordinates);
    Assert.assertSame(point, converted);
    final Point convertedOther = point.convertGeometry(geometryFactory2);
    final Point convertedBack = convertedOther.convertGeometry(geometryFactory);
    assertCoordinatesEquals(convertedBack, coordinates);
    Assert.assertNotSame(point, convertedBack);
    final Point copy = point.newGeometry(geometryFactory);
    assertCoordinatesEquals(copy, coordinates);
    Assert.assertNotSame(point, copy);
    final Point copyOther = point.convertGeometry(geometryFactory2);
    final Point copyBack = copyOther.convertGeometry(geometryFactory);
    assertCoordinatesEquals(copyBack, coordinates);
    Assert.assertNotSame(point, copyBack);
    final String string = point.toString();
    final Point pointString = geometryFactory.geometry(string);
    assertCoordinatesEquals(pointString, coordinates);
    final String wkt = point.toEwkt();
    final Point pointWkt = geometryFactory.geometry(wkt);
    assertCoordinatesEquals(pointWkt, coordinates);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 64 with GeometryFactory

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

the class PointTest method constructEmpty.

@Test
public void constructEmpty() {
    for (int axisCount = 2; axisCount < 4; axisCount++) {
        final GeometryFactory geometryFactory = GeometryFactory.fixed(26910, axisCount, GeometryFactory.newScalesFixed(axisCount, 1000.0));
        final Point pointEmpty = geometryFactory.point();
        assertEmpty(pointEmpty);
        final Point pointCoordinatesNull = geometryFactory.point((Point) null);
        assertEmpty(pointCoordinatesNull);
        final Point pointCoordinatesListNull = geometryFactory.point();
        assertEmpty(pointCoordinatesListNull);
        final Point pointObjectNull = geometryFactory.point((Object) null);
        assertEmpty(pointObjectNull);
        final Point pointDoubleArrayNull = geometryFactory.point((double[]) null);
        assertEmpty(pointDoubleArrayNull);
        final Point pointDoubleArraySize0 = geometryFactory.point(new double[0]);
        assertEmpty(pointDoubleArraySize0);
        final Point pointDoubleArraySize1 = geometryFactory.point(new double[1]);
        assertEmpty(pointDoubleArraySize1);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Test(org.junit.Test)

Example 65 with GeometryFactory

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

Aggregations

GeometryFactory (com.revolsys.geometry.model.GeometryFactory)360 Point (com.revolsys.geometry.model.Point)142 Geometry (com.revolsys.geometry.model.Geometry)72 BoundingBox (com.revolsys.geometry.model.BoundingBox)70 LineString (com.revolsys.geometry.model.LineString)61 ArrayList (java.util.ArrayList)45 DataType (com.revolsys.datatype.DataType)25 FieldDefinition (com.revolsys.record.schema.FieldDefinition)24 Polygon (com.revolsys.geometry.model.Polygon)22 List (java.util.List)18 RecordDefinition (com.revolsys.record.schema.RecordDefinition)17 Test (org.junit.Test)16 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)14 Record (com.revolsys.record.Record)14 IOException (java.io.IOException)13 PathName (com.revolsys.io.PathName)12 LinearRing (com.revolsys.geometry.model.LinearRing)10 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)10 QuadEdgeDelaunayTinBuilder (com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)8