Search in sources :

Example 11 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class LineStringRelate method getOverlap.

public Lineal getOverlap() {
    final List<List<Point>> intersections = new ArrayList<>();
    final LineString points1 = this.line1;
    final List<Point> currentCoordinates = new ArrayList<>();
    Node<LineSegment> previousNode = this.graph1.getNode(this.fromPoint1);
    do {
        final List<Edge<LineSegment>> outEdges = previousNode.getOutEdges();
        if (outEdges.isEmpty()) {
            previousNode = null;
        } else if (outEdges.size() > 1) {
            System.err.println("Cannot handle overlaps\n" + getLine1() + "\n " + getLine2());
            final GeometryFactory factory = this.line1.getGeometryFactory();
            return factory.lineString();
        } else {
            final Edge<LineSegment> edge = outEdges.get(0);
            final LineSegment line = edge.getObject();
            final Node<LineSegment> nextNode = edge.getToNode();
            if (this.graph2.hasEdgeBetween(previousNode, nextNode)) {
                if (currentCoordinates.size() == 0) {
                    currentCoordinates.add(line.getPoint(0));
                }
                currentCoordinates.add(line.getPoint(1));
            } else {
                if (currentCoordinates.size() > 0) {
                    final List<Point> points = new ArrayList<>();
                    intersections.add(points);
                    currentCoordinates.clear();
                }
            }
            previousNode = nextNode;
        }
    } while (previousNode != null && !previousNode.equals(2, this.fromPoint1));
    if (currentCoordinates.size() > 0) {
        final List<Point> points = new ArrayList<>();
        intersections.add(points);
    }
    final GeometryFactory factory = this.line1.getGeometryFactory();
    return factory.lineal(intersections);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Node(com.revolsys.geometry.graph.Node) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) List(java.util.List) ArrayList(java.util.ArrayList) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 12 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class EdgeRing method addPoints.

private void addPoints(final LineStringEditor points, final Edge edge, final boolean isForward, final boolean isFirstEdge) {
    final LineString line = edge.getLineString();
    final int numPoints = line.getVertexCount();
    if (isForward) {
        int startIndex = 1;
        if (isFirstEdge) {
            startIndex = 0;
        }
        for (int i = startIndex; i < numPoints; i++) {
            final double x = line.getX(i);
            final double y = line.getY(i);
            points.appendVertex(x, y);
        }
    } else {
        // is backward
        int startIndex = numPoints - 2;
        if (isFirstEdge) {
            startIndex = numPoints - 1;
        }
        for (int i = startIndex; i >= 0; i--) {
            final double x = line.getX(i);
            final double y = line.getY(i);
            points.appendVertex(x, y);
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 13 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class GeometryGraph method addLineString.

private void addLineString(final LineString line) {
    final LineString cleanLine = line.removeDuplicatePoints();
    final int cleanVertexCount = cleanLine.getVertexCount();
    if (cleanVertexCount < 2 || cleanLine.isEmpty()) {
        this.hasTooFewPoints = true;
        this.invalidPoint = cleanLine.getPoint(0);
        return;
    } else {
        // add the edge for the LineString
        // line edges do not have locations for their left and right sides
        final Edge e = new Edge(cleanLine, new Label(this.argIndex, Location.INTERIOR));
        this.lineEdgeMap.put(line, e);
        insertEdge(e);
        /**
         * Add the boundary points of the LineString, if any.
         * Even if the LineString is closed, add both points as if they were endpoints.
         * This allows for the case that the node already exists and is a boundary point.
         */
        insertBoundaryPoint(this.argIndex, cleanLine.getPoint(0));
        insertBoundaryPoint(this.argIndex, cleanLine.getPoint(cleanVertexCount - 1));
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 14 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class GeometryGraph method addPolygonRing.

/**
 * Adds a polygon ring to the graph.
 * Empty rings are ignored.
 *
 * The left and right topological location arguments assume that the ring is oriented CW.
 * If the ring is in the opposite orientation,
 * the left and right locations must be interchanged.
 */
private void addPolygonRing(final LinearRing ring, final Location cwLeft, final Location cwRight) {
    if (!ring.isEmpty()) {
        final LineString simplifiedRing;
        try {
            simplifiedRing = ring.removeDuplicatePoints();
            final int vertexCount = simplifiedRing.getVertexCount();
            if (vertexCount > 3) {
                Location left;
                Location right;
                if (ring.isCounterClockwise()) {
                    left = cwRight;
                    right = cwLeft;
                } else {
                    left = cwLeft;
                    right = cwRight;
                }
                final Label label = new Label(this.argIndex, Location.BOUNDARY, left, right);
                final Edge e = new Edge(simplifiedRing, label);
                this.lineEdgeMap.put(ring, e);
                insertEdge(e);
                // insert the endpoint as a node, to mark that it is on the boundary
                insertPoint(this.argIndex, simplifiedRing.getPoint2D(0), Location.BOUNDARY);
            } else if (vertexCount == 0) {
                this.hasTooFewPoints = true;
                this.invalidPoint = GeometryFactory.DEFAULT_2D.point();
            } else {
                this.hasTooFewPoints = true;
                this.invalidPoint = simplifiedRing.getPoint2D(0);
            }
        } catch (final IllegalArgumentException e) {
            this.hasTooFewPoints = true;
            this.invalidPoint = ring.getPoint2D(0);
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Location(com.revolsys.geometry.model.Location)

Example 15 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class EdgeIntersectionList method newSplitEdge.

/**
 * Construct a new new "split edge" with the section of points between
 * (and including) the two intersections.
 * The label for the new edge is the same as the label for the parent edge.
 */
Edge newSplitEdge(final EdgeIntersection ei0, final EdgeIntersection ei1) {
    final int fromIndex = ei0.segmentIndex;
    final int toIndex = ei1.segmentIndex;
    int pointCount = toIndex - fromIndex + 2;
    // if the last intersection point is not equal to the its segment start pt,
    // add it to the points list as well.
    // (This check is needed because the distance metric is not totally
    // reliable!)
    // The check for point equality is 2D only - Z values are ignored
    final double xEnd = ei1.getX();
    final double yEnd = ei1.getY();
    final Edge edge = this.edge;
    final boolean useIntPt1 = ei1.dist > 0.0 || !edge.equalsVertex(toIndex, xEnd, yEnd);
    if (!useIntPt1) {
        pointCount--;
    }
    final double[] coordinates = new double[pointCount * 2];
    int coordinateIndex = 0;
    coordinates[coordinateIndex++] = ei0.getX();
    coordinates[coordinateIndex++] = ei0.getY();
    for (int i = fromIndex + 1; i <= toIndex; i++) {
        final double x = edge.getX(i);
        final double y = edge.getY(i);
        coordinates[coordinateIndex++] = x;
        coordinates[coordinateIndex++] = y;
    }
    if (useIntPt1) {
        coordinates[coordinateIndex++] = xEnd;
        coordinates[coordinateIndex++] = yEnd;
    }
    final LineString line = new LineStringDouble(2, coordinates);
    return new Edge(line, new Label(edge.label));
}
Also used : LineString(com.revolsys.geometry.model.LineString) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Aggregations

LineString (com.revolsys.geometry.model.LineString)380 Point (com.revolsys.geometry.model.Point)184 Geometry (com.revolsys.geometry.model.Geometry)65 ArrayList (java.util.ArrayList)62 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)51 Polygon (com.revolsys.geometry.model.Polygon)37 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)24 Edge (com.revolsys.geometry.graph.Edge)22 List (java.util.List)22 BoundingBox (com.revolsys.geometry.model.BoundingBox)20 Lineal (com.revolsys.geometry.model.Lineal)20 Test (org.junit.Test)20 LinearRing (com.revolsys.geometry.model.LinearRing)19 Record (com.revolsys.record.Record)17 Iterator (java.util.Iterator)14 LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)13 Punctual (com.revolsys.geometry.model.Punctual)12 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)12 LineSegment (com.revolsys.geometry.model.segment.LineSegment)10 Polygonal (com.revolsys.geometry.model.Polygonal)9