use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class WktParser method parsePointParts.
private List<Point> parsePointParts(final GeometryFactory geometryFactory, final PushbackReader reader, final int axisCount) throws IOException {
skipWhitespace(reader);
final List<Point> parts = new ArrayList<>();
int character = reader.read();
switch(character) {
case '(':
do {
final LineStringEditor lineBuilder = parseCoordinatesLineString(geometryFactory, reader, axisCount);
parts.add(geometryFactory.point(lineBuilder));
skipWhitespace(reader);
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 WktParser method parseCoordinatesLineString.
private LineStringEditor parseCoordinatesLineString(final GeometryFactory geometryFactory, final PushbackReader reader, final int axisCount) throws IOException {
final LineStringEditor line = geometryFactory.newLineStringBuilder();
skipWhitespace(reader);
int character = reader.read();
if (character == '(') {
int axisIndex = 0;
int vertexIndex = 0;
while (true) {
final double number;
try {
number = parseDouble(reader);
} catch (final IllegalArgumentException e) {
character = reader.read();
if (character == ')') {
return line;
} else {
reader.unread(character);
throw new IllegalArgumentException("Invalid WKT geometry. Expecting end of coordinates ')' not " + FileUtil.getString(reader, 50));
}
}
character = reader.read();
if (character == ',' || character == ')') {
if (character == ',') {
skipWhitespace(reader);
}
if (axisIndex < axisCount) {
line.setCoordinate(vertexIndex, axisIndex, number);
axisIndex = 0;
vertexIndex++;
}
if (character == ')') {
return line;
}
} else if (character == ' ' || Character.isWhitespace(character)) {
skipWhitespace(reader);
if (axisIndex == 0) {
line.appendVertex(number, Double.NaN);
axisIndex++;
} else if (axisIndex < axisCount) {
line.setCoordinate(vertexIndex, axisIndex, number);
axisIndex++;
}
} else {
throw new IllegalArgumentException("Invalid WKT geometry. Expecting a space between coordinates not: " + FileUtil.getString(reader, 50));
}
}
} else {
reader.unread(character);
throw new IllegalArgumentException("Invalid WKT geometry. Expecting start of coordinates '(' not: " + FileUtil.getString(reader, 50));
}
}
use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class ArcConverter method read.
@Override
public Object read(final OsnIterator iterator) {
final Map<String, Object> values = new TreeMap<>();
values.put(SaifConstants.TYPE, this.geometryType);
String field = iterator.nextFieldName();
LineString geometry = null;
while (field != null) {
if (field.equals("LineString")) {
int axisCount = 2;
final LineStringEditor line = new LineStringEditor(this.geometryFactory);
while (iterator.next() != OsnIterator.END_LIST) {
final String pointName = iterator.nextObjectName();
if (!pointName.equals("/Point")) {
iterator.throwParseError("Expecting Point object");
}
final String coordsName = iterator.nextFieldName();
if (!coordsName.equals("coords")) {
iterator.throwParseError("Expecting coords attribute");
}
final String coordTypeName = iterator.nextObjectName();
if (coordTypeName.equals("/Coord3D")) {
final double x = iterator.nextDoubleAttribute("c1");
final double y = iterator.nextDoubleAttribute("c2");
final double z = iterator.nextDoubleAttribute("c3");
axisCount = 3;
line.appendVertex(x, y, z);
} else if (coordTypeName.equals("/Coord2D")) {
final double x = iterator.nextDoubleAttribute("c1");
final double y = iterator.nextDoubleAttribute("c2");
line.appendVertex(x, y);
} else {
iterator.throwParseError("Expecting Coord2D or Coord3D");
}
iterator.nextEndObject();
iterator.nextEndObject();
}
final int axisCount1 = axisCount;
final GeometryFactory geometryFactory1 = this.geometryFactory.convertAxisCount(axisCount1);
geometry = newLineString(geometryFactory1, line);
} else {
readAttribute(iterator, field, values);
}
field = iterator.nextFieldName();
}
Property.set(geometry, values);
return geometry;
}
use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class WktParser method parseLineString.
private Geometry parseLineString(GeometryFactory geometryFactory, final boolean useAxisCountFromGeometryFactory, final PushbackReader reader) throws IOException {
final int axisCount = getAxisCount(reader);
if (!useAxisCountFromGeometryFactory) {
if (axisCount != geometryFactory.getAxisCount()) {
final int srid = geometryFactory.getCoordinateSystemId();
final double[] scales = geometryFactory.newScales(axisCount);
geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
}
}
if (isEmpty(reader)) {
return geometryFactory.lineString();
} else {
final LineStringEditor points = parseCoordinatesLineString(geometryFactory, reader, axisCount);
if (points.getVertexCount() == 1) {
return geometryFactory.point(points);
} else {
return points.newLineString();
}
}
}
use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class SnapTransformer method snapVertices.
/**
* Snap source vertices to vertices in the target.
*
* @param newCoordinates the points to snap
* @param snapPoints the points to snap to
*/
private LineString snapVertices(final LineString line) {
LineStringEditor newLine = null;
final int vertexCount = line.getVertexCount();
final boolean closed = line.isClosed();
// if src is a ring then don't snap final vertex
final int end = closed ? vertexCount - 1 : vertexCount;
for (int i = 0; i < end; i++) {
final double x = line.getX(i);
final double y = line.getY(i);
final Point snapVert = findSnapForVertex(x, y);
if (snapVert != null) {
if (newLine == null) {
newLine = LineStringEditor.newLineStringEditor(line);
if (i == 0 && closed) {
// keep final closing point in synch (rings only)
newLine.setVertex(vertexCount - 1, snapVert);
}
}
newLine.setVertex(i, snapVert);
}
}
if (newLine == null) {
return line;
} else {
return newLine;
}
}
Aggregations