Search in sources :

Example 11 with LineStringEditor

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

the class LinearRing method removeDuplicatePoints.

@Override
default LinearRing removeDuplicatePoints() {
    if (isEmpty()) {
        return this;
    } else {
        final LineStringEditor editor = newGeometryEditor();
        final int axisCount = getAxisCount();
        double previousX = getX(0);
        double previousY = getY(0);
        int newVertexIndex = 1;
        final int vertexCount = getVertexCount();
        for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
            final double x = getX(vertexIndex);
            final double y = getY(vertexIndex);
            if (x != previousX || y != previousY) {
                if (newVertexIndex != vertexIndex) {
                    editor.setX(newVertexIndex, x);
                    editor.setY(newVertexIndex, y);
                    for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) {
                        final double coordinate = getCoordinate(newVertexIndex, axisIndex);
                        editor.setCoordinate(newVertexIndex, axisIndex, coordinate);
                    }
                }
                newVertexIndex++;
            }
            previousX = x;
            previousY = y;
        }
        editor.setVertexCount(newVertexIndex);
        final GeometryFactory geometryFactory = getGeometryFactory();
        if (newVertexIndex < 3) {
            return geometryFactory.linearRing();
        } else if (editor.isModified()) {
            return editor.newLinearRing();
        } else {
            return this;
        }
    }
}
Also used : LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Example 12 with LineStringEditor

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

the class GeometryFactory method newLineStringBuilder.

private LineStringEditor newLineStringBuilder(final Collection<?> points) {
    final LineStringEditor lineBuilder = new LineStringEditor(this, points.size());
    for (final Object object : points) {
        if (object == null) {
        } else if (object instanceof Point) {
            final Point point = (Point) object;
            lineBuilder.appendVertex(point);
        } else if (object instanceof double[]) {
            final double[] coordinates = (double[]) object;
            lineBuilder.appendVertex(coordinates);
        } else if (object instanceof List<?>) {
            @SuppressWarnings("unchecked") final List<Number> list = (List<Number>) object;
            final double[] coordinates = MathUtil.toDoubleArray(list);
            lineBuilder.appendVertex(coordinates);
        } else if (object instanceof LineString) {
            final LineString LineString = (LineString) object;
            final Point point = LineString.getPoint(0);
            lineBuilder.appendVertex(point);
        } else {
            throw new IllegalArgumentException("Unexepected data type: " + object);
        }
    }
    return lineBuilder;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) AbstractPoint(com.revolsys.geometry.model.impl.AbstractPoint) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Example 13 with LineStringEditor

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

the class WktParser method parseParts.

private List<LineString> parseParts(final GeometryFactory geometryFactory, final PushbackReader reader, final int axisCount) throws IOException {
    skipWhitespace(reader);
    final List<LineString> parts = new ArrayList<>();
    int character = reader.read();
    switch(character) {
        case '(':
            do {
                final LineStringEditor lineBuilder = parseCoordinatesLineString(geometryFactory, reader, axisCount);
                parts.add(lineBuilder.newLineString());
                character = reader.read();
            } while (character == ',');
            if (character != ')') {
                throw new IllegalArgumentException("Expecting ) not" + FileUtil.getString(reader, 50));
            }
            break;
        case ')':
            character = reader.read();
            if (character == ')' || character == ',') {
            } else {
                throw new IllegalArgumentException("Expecting ' or ) not" + FileUtil.getString(reader, 50));
            }
            break;
        default:
            throw new IllegalArgumentException("Expecting ( not" + FileUtil.getString(reader, 50));
    }
    return parts;
}
Also used : LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) Point(com.revolsys.geometry.model.Point)

Example 14 with LineStringEditor

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

the class LineStringEditorTest method testSetX.

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

Example 15 with LineStringEditor

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

the class LineStringEditorTest method testSetCoordinates.

@Test
public void testSetCoordinates() {
    for (int i = 0; i < 4; i++) {
        final LineStringEditor lineEditor = LINE_STRING.newGeometryEditor(4);
        final int newValue = i * 10;
        lineEditor.setCoordinate(0, i, newValue);
        final LineString newLineString = lineEditor.newGeometry();
        Assert.assertNotSame(LINE_STRING, newLineString);
        Assert.assertEquals(newValue, newLineString.getCoordinate(0, i), 0.0);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) Test(org.junit.Test)

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