Search in sources :

Example 71 with LineString

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

the class LineStringTest method testMerge.

@Test
public void testMerge() {
    final GeometryFactory geometryFactory = GeometryFactory.fixed3d(26910, 1.0, 1.0, 1.0);
    // Last point is duplicated
    final LineString line1 = geometryFactory.lineString(3, START_X, START_Y, 0, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 200, 2, START_X + 300, START_Y + 300, 3, START_X + 300, START_Y + 300, 3);
    final LineString line1Reverse = line1.reverse();
    // Every point is duplicated
    final LineString line2 = geometryFactory.lineString(3, START_X + 300, START_Y + 300, 3, START_X + 300, START_Y + 300, 3, START_X + 400, START_Y + 400, 4, START_X + 400, START_Y + 400, 4, START_X + 500, START_Y + 500, 5, START_X + 500, START_Y + 500, 5);
    final LineString line2Reverse = line2.reverse();
    // Line to make a loop
    final LineString line3 = geometryFactory.lineString(3, START_X + 300, START_Y + 300, 3, START_X, START_Y, 0);
    final LineString line3Reverse = line3.reverse();
    // Forwards, Forwards
    assertMerge(false, line1, line2, START_X + 300, START_Y + 300, START_X, START_Y, 0, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 200, 2, START_X + 300, START_Y + 300, 3, START_X + 400, START_Y + 400, 4, START_X + 500, START_Y + 500, 5);
    // Forwards, Reverse
    assertMerge(false, line1, line2Reverse, START_X + 300, START_Y + 300, START_X, START_Y, 0, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 200, 2, START_X + 300, START_Y + 300, 3, START_X + 400, START_Y + 400, 4, START_X + 500, START_Y + 500, 5);
    // Reverse, Forwards
    assertMerge(false, line1Reverse, line2, START_X + 300, START_Y + 300, START_X + 500, START_Y + 500, 5, START_X + 400, START_Y + 400, 4, START_X + 300, START_Y + 300, 3, START_X + 200, START_Y + 200, 2, START_X + 100, START_Y + 100, 1, START_X, START_Y, 0);
    // Reverse, Reverse
    assertMerge(false, line1Reverse, line2Reverse, START_X + 300, START_Y + 300, START_X + 500, START_Y + 500, 5, START_X + 400, START_Y + 400, 4, START_X + 300, START_Y + 300, 3, START_X + 200, START_Y + 200, 2, START_X + 100, START_Y + 100, 1, START_X, START_Y, 0);
    // Loop Forwards, Forwards
    assertMerge(true, line1, line3, START_X + 300, START_Y + 300, START_X, START_Y, 0, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 200, 2, START_X + 300, START_Y + 300, 3, START_X, START_Y, 0);
    // Loop Forwards, Reverse
    assertMerge(true, line1, line3Reverse, START_X + 300, START_Y + 300, START_X, START_Y, 0, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 200, 2, START_X + 300, START_Y + 300, 3, START_X, START_Y, 0);
    // Loop Reverse, Forwards
    assertMerge(true, line1Reverse, line3, START_X + 300, START_Y + 300, START_X, START_Y, 0, START_X + 300, START_Y + 300, 3, START_X + 200, START_Y + 200, 2, START_X + 100, START_Y + 100, 1, START_X, START_Y, 0);
    // Loop Reverse, Reverse
    assertMerge(true, line1Reverse, line3Reverse, START_X + 300, START_Y + 300, START_X, START_Y, 0, START_X + 300, START_Y + 300, 3, START_X + 200, START_Y + 200, 2, START_X + 100, START_Y + 100, 1, START_X, START_Y, 0);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) Test(org.junit.Test)

Example 72 with LineString

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

the class LineStringTest method testSplit.

@Test
public void testSplit() {
    final GeometryFactory geometryFactory = GeometryFactory.fixed3d(26910, 1000.0, 1000.0, 1.0);
    // Last point is duplicated
    final LineString line = geometryFactory.lineString(3, START_X, START_Y, 0, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 100, 2, START_X + 100, START_Y, 3);
    // From vertex
    assertSplit(true, line, geometryFactory.point(START_X, START_Y), line);
    // To vertex
    assertSplit(true, line, geometryFactory.point(START_X + 100, START_Y), line);
    // Middle vertex
    final LineString lineVertexMiddle1 = geometryFactory.lineString(3, START_X, START_Y, 0, START_X + 100, START_Y + 100, 1);
    final LineString lineVertexMiddle2 = geometryFactory.lineString(3, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 100, 2, START_X + 100, START_Y, 3);
    final Point pointVertexMiddle2 = geometryFactory.point(START_X + 100, START_Y + 100);
    assertSplit(true, line, pointVertexMiddle2, lineVertexMiddle1, lineVertexMiddle2);
    // Middle vertex
    final LineString lineVertexClose1 = geometryFactory.lineString(3, START_X, START_Y, 0, START_X + 100, START_Y + 100, 1, START_X + 99.999, START_Y + 100.001, 1);
    final LineString lineVertexClose2 = geometryFactory.lineString(3, START_X + 99.999, START_Y + 100.001, 1, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 100, 2, START_X + 100, START_Y, 3);
    assertSplit(false, line, geometryFactory.point(START_X + 99.999, START_Y + 100.001, 1), lineVertexClose1, lineVertexClose2);
    // Middle of first segment
    for (final double offset : new double[] { 0.001, 50, 99.999 }) {
        final double x = START_X + offset;
        final double y = START_Y + offset;
        final LineString lineSegmentFirst1 = geometryFactory.lineString(3, START_X, START_Y, 0, x, y, offset);
        final LineString lineSegmentFirst2 = geometryFactory.lineString(3, x, y, offset, START_X + 100, START_Y + 100, 1, START_X + 200, START_Y + 100, 2, START_X + 100, START_Y, 3);
        final Point splitPoint = geometryFactory.point(x, y, offset);
        assertSplit(false, line, splitPoint, lineSegmentFirst1, lineSegmentFirst2);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Test(org.junit.Test)

Example 73 with LineString

use of com.revolsys.geometry.model.LineString 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 74 with LineString

use of com.revolsys.geometry.model.LineString 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 75 with LineString

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

the class ConvexHullTest method test1.

public void test1() throws Exception {
    final LineString lineString = (LineString) GEOMETRY_FACTORY_1M.geometry("LINESTRING(30 220,240 220,240 220)");
    final LineString convexHull = (LineString) GEOMETRY_FACTORY_1M.geometry("LINESTRING(30 220,240 220)");
    assertTrue(convexHull.equals(2, lineString.convexHull()));
}
Also used : LineString(com.revolsys.geometry.model.LineString)

Aggregations

LineString (com.revolsys.geometry.model.LineString)380 Point (com.revolsys.geometry.model.Point)184 Geometry (com.revolsys.geometry.model.Geometry)65 ArrayList (java.util.ArrayList)62 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)51 Polygon (com.revolsys.geometry.model.Polygon)37 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)24 Edge (com.revolsys.geometry.graph.Edge)22 List (java.util.List)22 BoundingBox (com.revolsys.geometry.model.BoundingBox)20 Lineal (com.revolsys.geometry.model.Lineal)20 Test (org.junit.Test)20 LinearRing (com.revolsys.geometry.model.LinearRing)19 Record (com.revolsys.record.Record)17 Iterator (java.util.Iterator)14 LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)13 Punctual (com.revolsys.geometry.model.Punctual)12 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)12 LineSegment (com.revolsys.geometry.model.segment.LineSegment)10 Polygonal (com.revolsys.geometry.model.Polygonal)9