Search in sources :

Example 21 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class LinearRingEditorTest method testSetM.

@Test
public void testSetM() {
    final LineStringEditor lineEditor = LINE_STRING.newGeometryEditor(4);
    lineEditor.setM(0, 10);
    final LineString newLineString = lineEditor.newGeometry();
    Assert.assertNotSame(LINE_STRING, newLineString);
    Assert.assertEquals(10.0, newLineString.getM(0), 0.0);
}
Also used : LineString(com.revolsys.geometry.model.LineString) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) Test(org.junit.Test)

Example 22 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class IntArrayScaleGriddedElevationModel method getNullBoundaryPoints.

@Override
public LineStringEditor getNullBoundaryPoints() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final LineStringEditor points = new LineStringEditor(geometryFactory);
    final double minX = getGridMinX();
    final double minY = getGridMinY();
    final double gridCellSize = getGridCellSize();
    final int gridHeight = getGridHeight();
    final int gridWidth = getGridWidth();
    final int[] elevations = this.elevations;
    int index = 0;
    final int[] offsets = { -1, 0, 1 };
    for (int gridY = 0; gridY < gridHeight; gridY++) {
        for (int gridX = 0; gridX < gridWidth; gridX++) {
            final int elevation = elevations[index];
            if (elevation == NULL_VALUE) {
                int countZ = 0;
                long sumZ = 0;
                for (final int offsetY : offsets) {
                    if (!(gridY == 0 && offsetY == -1 || gridY == gridHeight - 1 && offsetY == 1)) {
                        final int offsetIndex = index + offsetY * gridWidth;
                        for (final int offsetX : offsets) {
                            if (!(gridX == 0 && offsetX == -1 || gridX == gridWidth - 1 && offsetX == 1)) {
                                final int elevationNeighbour = elevations[offsetIndex + offsetX];
                                if (elevationNeighbour != NULL_VALUE) {
                                    sumZ += elevationNeighbour;
                                    countZ++;
                                }
                            }
                        }
                    }
                }
                if (countZ > 0) {
                    final double x = minX + gridCellSize * gridX;
                    final double y = minY + gridCellSize * gridY;
                    final double z = toDoubleZ((int) (sumZ / countZ));
                    points.appendVertex(x, y, z);
                }
            }
            index++;
        }
    }
    return points;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Example 23 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class ConvexHull method convexHull.

public static Geometry convexHull(final GeometryFactory geometryFactory, final Iterable<? extends Point> inputPoints, final int maxPoints) {
    Collection<Point> points = ConvexHull.getUniquePoints(inputPoints);
    final int vertexCount = points.size();
    if (vertexCount == 0) {
        return geometryFactory.geometryCollection();
    } else if (vertexCount == 1) {
        return geometryFactory.point(points.iterator().next());
    } else if (vertexCount == 2) {
        return geometryFactory.lineString(points);
    } else {
        // use heuristic to reduce points, if large
        if (vertexCount > maxPoints) {
            points = reduce(points);
        }
        points = preSort(points);
        final Stack<Point> hullPoints = grahamScan(points);
        final LineStringEditor cleanedRing = cleanRing(geometryFactory, hullPoints);
        if (cleanedRing.getVertexCount() == 3) {
            return geometryFactory.lineString(cleanedRing.getVertex(0), cleanedRing.getVertex(1));
        } else {
            return cleanedRing.newPolygon();
        }
    }
}
Also used : Point(com.revolsys.geometry.model.Point) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) Point(com.revolsys.geometry.model.Point)

Example 24 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class LineString method subLine.

default LineString subLine(final LineStringLocation fromLocation, final LineStringLocation toLocation) {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final LineStringEditor lineBuilder = new LineStringEditor(geometryFactory);
    int vertexIndexFrom;
    if (fromLocation == null || fromLocation.getLine() != this) {
        vertexIndexFrom = 0;
    } else {
        vertexIndexFrom = fromLocation.getSegmentIndex();
        if (fromLocation.getSegmentFraction() > 0.0) {
            vertexIndexFrom += 1;
        }
        if (!fromLocation.isVertex()) {
            final Point point = fromLocation.getPoint();
            lineBuilder.appendVertex(point, false);
        }
    }
    Point toPoint;
    int vertexIndexTo;
    if (toLocation == null) {
        vertexIndexTo = getVertexCount() - 1;
        toPoint = null;
    } else {
        vertexIndexTo = toLocation.getSegmentIndex();
        if (toLocation.getSegmentFraction() >= 1.0) {
            vertexIndexTo += 1;
        }
        if (toLocation.isVertex()) {
            toPoint = null;
        } else {
            toPoint = toLocation.getPoint();
        }
    }
    for (int vertexIndex = vertexIndexFrom; vertexIndex <= vertexIndexTo; vertexIndex++) {
        final Point point = getPoint(vertexIndex);
        lineBuilder.appendVertex(point, false);
    }
    if (toPoint != null) {
        lineBuilder.appendVertex(toPoint, false);
    }
    if (lineBuilder.getVertexCount() < 2) {
        return lineBuilder.newLineStringEmpty();
    } else {
        return lineBuilder.newLineString();
    }
}
Also used : LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Example 25 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class LineString method cleanCloseVertices.

default LineString cleanCloseVertices(final double maxDistance) {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final int axisCount = geometryFactory.getAxisCount();
    final int vertexCount = getVertexCount();
    final LineStringEditor newLine = new LineStringEditor(geometryFactory, vertexCount);
    double x1 = getX(0);
    double y1 = getY(0);
    newLine.appendVertex(x1, y1);
    for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) {
        final double coordinate = getCoordinate(0, axisIndex);
        newLine.setCoordinate(0, axisIndex, coordinate);
    }
    final int lastVertexIndex = getLastVertexIndex();
    for (int vertexIndex = 1; vertexIndex < lastVertexIndex; vertexIndex++) {
        final double x2 = getX(vertexIndex);
        final double y2 = getY(vertexIndex);
        if (MathUtil.distance(x1, y1, x2, y2) < maxDistance) {
        // Skip vertex
        } else {
            newLine.appendVertex(x2, y2);
            final int newVertexIndex = newLine.getLastVertexIndex();
            for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) {
                final double coordinate = getCoordinate(newVertexIndex, axisIndex);
                newLine.setCoordinate(newVertexIndex, axisIndex, coordinate);
            }
            x1 = x2;
            y1 = y2;
        }
    }
    final double xn = getX(lastVertexIndex);
    final double yn = getY(lastVertexIndex);
    if (lastVertexIndex > 2 && MathUtil.distance(x1, y1, xn, yn) < maxDistance) {
        final int newVertexIndex = newLine.getLastVertexIndex();
        for (int axisIndex = 0; axisIndex < axisCount; axisIndex++) {
            final double coordinate = getCoordinate(lastVertexIndex, axisIndex);
            newLine.setCoordinate(newVertexIndex, axisIndex, coordinate);
        }
    } else {
        newLine.appendVertex(xn, yn);
        final int newVertexIndex = newLine.getLastVertexIndex();
        for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) {
            final double coordinate = getCoordinate(lastVertexIndex, axisIndex);
            newLine.setCoordinate(newVertexIndex, axisIndex, coordinate);
        }
    }
    if (newLine.getVertexCount() == 1) {
        return this;
    } else {
        final LineString newLineString = newLine.newLineString();
        return newLineString;
    }
}
Also used : PreparedLineString(com.revolsys.geometry.model.prep.PreparedLineString) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Aggregations

LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)35 LineString (com.revolsys.geometry.model.LineString)13 Test (org.junit.Test)13 Point (com.revolsys.geometry.model.Point)11 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 ArrayList (java.util.ArrayList)3 TopologyException (com.revolsys.geometry.model.TopologyException)1 AbstractPoint (com.revolsys.geometry.model.impl.AbstractPoint)1 PreparedLineString (com.revolsys.geometry.model.prep.PreparedLineString)1 ArcLineString (com.revolsys.record.io.format.saif.geometry.ArcLineString)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1