Search in sources :

Example 6 with LineStringDouble

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);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) List(java.util.List) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 7 with LineStringDouble

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);
}
Also used : ArrayList(java.util.ArrayList) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble) Point(com.revolsys.geometry.model.Point) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 8 with LineStringDouble

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;
}
Also used : HashMap(java.util.HashMap) LineStringGraph(com.revolsys.geometry.graph.linestring.LineStringGraph) Node(com.revolsys.geometry.graph.Node) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) List(java.util.List) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 9 with LineStringDouble

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;
    }
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) ArrayList(java.util.ArrayList) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 10 with LineStringDouble

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);
}
Also used : ArrayList(java.util.ArrayList) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble) Point(com.revolsys.geometry.model.Point) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Aggregations

LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)22 Point (com.revolsys.geometry.model.Point)17 LineString (com.revolsys.geometry.model.LineString)10 ArrayList (java.util.ArrayList)7 CoordinatesDistanceComparator (com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 BPlusTreeMap (com.revolsys.collection.bplus.BPlusTreeMap)1 IntHashMap (com.revolsys.collection.map.IntHashMap)1 MonotoneChainEdge (com.revolsys.geometry.geomgraph.index.MonotoneChainEdge)1 Edge (com.revolsys.geometry.graph.Edge)1 Node (com.revolsys.geometry.graph.Node)1 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)1 DelegatingLineString (com.revolsys.geometry.model.DelegatingLineString)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Lineal (com.revolsys.geometry.model.Lineal)1 LinearRing (com.revolsys.geometry.model.LinearRing)1 Polygon (com.revolsys.geometry.model.Polygon)1