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;
}
}
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations