use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.
the class PackedCoordinateUtil method getMultiPolygonPoints.
@SuppressWarnings("unused")
private static List<List<LineString>> getMultiPolygonPoints(final int vertexCount, final Double xOffset, final Double yOffset, final Double xyScale, final Double zOffset, final Double zScale, final Double mOffset, final Double mScale, final InputStream inputStream) {
try (final PackedIntegerInputStream in = new PackedIntegerInputStream(inputStream)) {
final List<List<double[]>> parts = new ArrayList<>();
final long packedByteLength = in.readLong5();
final long dimensionFlag = in.readLong();
final int annotationDimension = in.read();
final int shapeFlags = in.read();
final boolean hasZ = (dimensionFlag & 0x01) == 0x01;
final boolean hasM = (dimensionFlag & 0x02) == 0x02;
int axisCount;
if (hasM) {
axisCount = 4;
} else if (hasZ) {
axisCount = 3;
} else {
axisCount = 2;
}
List<double[]> pointsList = new ArrayList<>();
final double[] coordinates = new double[vertexCount * axisCount];
long previousX = Math.round(xOffset * xyScale);
long previousY = Math.round(yOffset * xyScale);
int j = 0;
for (int i = 0; i < vertexCount; i++) {
final long deltaX = in.readLong();
final long deltaY = in.readLong();
previousX = previousX + deltaX;
previousY = previousY + deltaY;
final double x = previousX / xyScale;
final double y = previousY / xyScale;
if (previousX == -1 && previousY == 0 || x == -1 && y == 0) {
if (!pointsList.isEmpty()) {
parts.add(pointsList);
}
pointsList = new ArrayList<>();
} else {
coordinates[j * axisCount] = x;
coordinates[j * axisCount + 1] = y;
if (j > 0 && i < vertexCount - 1) {
if (coordinates[0] == x && coordinates[1] == y) {
if (j > 2) {
final double[] subCoordinates = new double[j * axisCount + axisCount];
System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
pointsList.add(subCoordinates);
}
j = 0;
} else {
j++;
}
} else {
j++;
}
}
}
if (j > 2) {
if (coordinates.length == axisCount * j) {
pointsList.add(coordinates);
} else {
final double[] subCoordinates = new double[j * axisCount];
System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
pointsList.add(subCoordinates);
}
}
if (!pointsList.isEmpty()) {
parts.add(pointsList);
}
if (hasZ) {
getMultiPolygonPointsZorM(in, parts, axisCount, 2, zOffset, zScale);
}
if (hasM) {
getMultiPolygonPointsZorM(in, parts, axisCount, 3, mOffset, mScale);
}
final List<List<LineString>> lists = new ArrayList<>();
for (final List<double[]> part : parts) {
final List<LineString> list = new ArrayList<>();
lists.add(list);
for (final double[] partCoordinates : part) {
list.add(new LineStringDouble(axisCount, partCoordinates));
}
}
return lists;
} catch (final IOException e) {
throw new RuntimeException("Error reading coordinates", e);
} finally {
FileUtil.closeSilent(inputStream);
}
}
use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.
the class CoordinatesListUtil method removeRepeatedPoints.
public static LineString removeRepeatedPoints(final LineString points) {
final int axisCount = points.getAxisCount();
final List<Double> coordinates = new ArrayList<>();
double x = points.getX(0);
double y = points.getY(0);
coordinates.add(x);
coordinates.add(y);
for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) {
coordinates.add(points.getCoordinate(0, axisIndex));
}
for (int i = 0; i < points.getVertexCount(); i++) {
final double x1 = points.getX(i);
final double y1 = points.getY(i);
if (x != x1 || y != y1) {
coordinates.add(x1);
coordinates.add(y1);
for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) {
coordinates.add(points.getCoordinate(i, axisIndex));
}
x = x1;
y = y1;
}
}
return new LineStringDouble(axisCount, coordinates);
}
use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.
the class CoordinatesListUtil method intersection.
public static List<LineString> intersection(final GeometryFactory geometryFactory, final LineString points1, final LineString points2, final double maxDistance) {
final LineStringGraph graph1 = new LineStringGraph(points1);
graph1.setPrecisionModel(geometryFactory);
final LineStringGraph graph2 = new LineStringGraph(points2);
graph2.setPrecisionModel(geometryFactory);
final Map<Point, Point> movedNodes = new HashMap<>();
graph1.forEachNode((node) -> movePointsWithinTolerance(movedNodes, graph2, maxDistance, node));
graph2.forEachNode((node) -> movePointsWithinTolerance(movedNodes, graph1, maxDistance, node));
final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge1 = graph1.getPointsOnEdges(graph2, maxDistance);
final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge2 = graph2.getPointsOnEdges(graph1, maxDistance);
graph1.splitEdges(pointsOnEdge1);
graph2.splitEdges(pointsOnEdge2);
Point startPoint = points1.getPoint(0);
if (movedNodes.containsKey(startPoint)) {
startPoint = movedNodes.get(startPoint);
}
Point endPoint = points1.getPoint(points1.getVertexCount() - 1);
if (movedNodes.containsKey(endPoint)) {
endPoint = movedNodes.get(endPoint);
}
final List<LineString> intersections = new ArrayList<>();
final List<Point> currentCoordinates = new ArrayList<>();
Node<LineSegment> previousNode = graph1.getNode(startPoint);
do {
final List<Edge<LineSegment>> outEdges = previousNode.getOutEdges();
if (outEdges.isEmpty()) {
previousNode = null;
} else if (outEdges.size() > 1) {
throw new IllegalArgumentException("Cannot handle overlaps\n" + points1 + "\n " + points2);
} else {
final Edge<LineSegment> edge = outEdges.get(0);
final LineSegment line = edge.getObject();
final Node<LineSegment> nextNode = edge.getToNode();
if (graph2.hasEdgeBetween(previousNode, nextNode)) {
if (currentCoordinates.size() == 0) {
currentCoordinates.add(line.getPoint(0));
}
currentCoordinates.add(line.getPoint(1));
} else {
if (currentCoordinates.size() > 0) {
final LineString points = new LineStringDouble(points1.getAxisCount(), currentCoordinates);
intersections.add(points);
currentCoordinates.clear();
}
}
previousNode = nextNode;
}
} while (previousNode != null && !endPoint.equals(2, startPoint));
if (currentCoordinates.size() > 0) {
final LineString points = new LineStringDouble(points1.getAxisCount(), currentCoordinates);
intersections.add(points);
}
return intersections;
}
use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.
the class KmlGeometryReader method parseCoordinates.
private LineString parseCoordinates() throws XMLStreamException {
this.in.requireLocalName(COORDINATES);
final String coordinatesListString = this.in.getElementText();
if (Property.hasValue(coordinatesListString)) {
int axisCount = 2;
final String[] coordinatesListArray = coordinatesListString.trim().split("\\s+");
final List<Point> points = new ArrayList<>();
for (final String coordinatesString : coordinatesListArray) {
final String[] coordinatesArray = coordinatesString.split(",");
final double[] coordinates = new double[coordinatesArray.length];
for (int axisIndex = 0; axisIndex < coordinatesArray.length; axisIndex++) {
final String coordinate = coordinatesArray[axisIndex];
coordinates[axisIndex] = Double.valueOf(coordinate);
}
axisCount = Math.max(axisCount, coordinates.length);
points.add(new PointDouble(coordinates));
}
this.in.skipToEndElement();
return new LineStringDouble(axisCount, points);
} else {
return null;
}
}
use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.
the class GeoJsonGeometryReader method readCoordinatesList.
private LineString readCoordinatesList(final boolean cogo, final boolean ring) {
final List<Double> coordinates = new ArrayList<>();
final int axisCount = readCoordinatesList(coordinates);
if (cogo) {
final int vertexCount = coordinates.size() / axisCount;
if (vertexCount > 0) {
final double firstX = coordinates.get(0);
final double firstY = coordinates.get(1);
double previousX = firstX;
double previousY = firstY;
for (int i = 1; i < vertexCount; i++) {
final double distance = coordinates.get(i * axisCount);
final double angleDegrees = coordinates.get(i * axisCount + 1);
final double angle = Math.toRadians((450 - angleDegrees) % 360);
final double x = previousX + distance * Math.cos(angle);
final double y = previousY + distance * Math.sin(angle);
coordinates.set(i * axisCount, x);
coordinates.set(i * axisCount + 1, y);
previousX = x;
previousY = y;
}
if (ring) {
coordinates.set((vertexCount - 1) * axisCount, firstX);
coordinates.set((vertexCount - 1) * axisCount + 1, firstY);
}
}
}
return new LineStringDouble(axisCount, coordinates);
}
Aggregations