Search in sources :

Example 26 with Point

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

the class LineStringGraph method isSimple.

public boolean isSimple() {
    for (final Node<LineSegment> node : getNodes()) {
        if (node.getDegree() > 2) {
            return false;
        }
    }
    for (final Edge<LineSegment> edge : getEdges()) {
        final LineSegment line = edge.getObject();
        final EdgeObjectFilter<LineSegment> filter = new EdgeObjectFilter<>(new LineSegmentIntersectingFilter(line));
        final List<Edge<LineSegment>> edges = getEdges(line, filter);
        for (final Edge<LineSegment> edge2 : edges) {
            final LineSegment line2 = edge2.getObject();
            final Geometry intersections = line.getIntersection(line2);
            if (intersections instanceof LineSegment) {
                return false;
            } else if (intersections instanceof Point) {
                if (edge.getCommonNodes(edge2).isEmpty()) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) EdgeObjectFilter(com.revolsys.geometry.graph.filter.EdgeObjectFilter) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 27 with Point

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

the class LineStringGraph method getSelfIntersections.

public Geometry getSelfIntersections() {
    final Set<Point> intersectionPoints = new HashSet<>();
    for (int i = 0; i < this.points.getVertexCount(); i++) {
        final Point point = this.points.getPoint(i);
        final Node<LineSegment> node = getNode(point);
        if (node.getDegree() > 2 || hasTouchingEdges(node)) {
            intersectionPoints.add(point);
        }
    }
    forEachEdge((edge1) -> {
        final LineSegment lineSegment1 = edge1.getObject();
        forEachEdge(edge1, (edge2) -> {
            if (edge1 != edge2) {
                final LineSegment lineSegment2 = edge2.getObject();
                final Geometry intersections = ((LineSegment) lineSegment1.convertGeometry(getGeometryFactory())).getIntersection(lineSegment2);
                for (final Point intersection : intersections.vertices()) {
                    if (!lineSegment1.isEndPoint(intersection) && !lineSegment2.isEndPoint(intersection)) {
                        intersectionPoints.add(intersection);
                    }
                }
            }
        });
    });
    return this.geometryFactory.punctual(intersectionPoints);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) HashSet(java.util.HashSet) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 28 with Point

use of com.revolsys.geometry.model.Point 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 29 with Point

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

the class GeometryGraph method insertBoundaryPoint.

/**
 * Adds candidate boundary points using the current {@link BoundaryNodeRule}.
 * This is used to add the boundary
 * points of dim-1 geometries (Curves/MultiCurves).
 */
private void insertBoundaryPoint(final int argIndex, final Point point) {
    final NodeMap nodes = getNodeMap();
    final Node n = nodes.addNode(point);
    // nodes always have labels
    final Label lbl = n.getLabel();
    // the new point to insert is on a boundary
    int boundaryCount = 1;
    // determine the current location for the point (if any)
    Location loc = Location.NONE;
    loc = lbl.getLocation(argIndex, Position.ON);
    if (loc == Location.BOUNDARY) {
        boundaryCount++;
    }
    // determine the boundary status of the point according to the Boundary
    // Determination Rule
    final Location newLoc = determineBoundary(this.boundaryNodeRule, boundaryCount);
    lbl.setLocation(argIndex, newLoc);
}
Also used : Point(com.revolsys.geometry.model.Point) Location(com.revolsys.geometry.model.Location)

Example 30 with Point

use of com.revolsys.geometry.model.Point 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)

Aggregations

Point (com.revolsys.geometry.model.Point)669 LineString (com.revolsys.geometry.model.LineString)130 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)103 Geometry (com.revolsys.geometry.model.Geometry)95 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)90 ArrayList (java.util.ArrayList)79 BoundingBox (com.revolsys.geometry.model.BoundingBox)51 Polygon (com.revolsys.geometry.model.Polygon)42 LineSegment (com.revolsys.geometry.model.segment.LineSegment)34 List (java.util.List)28 LinearRing (com.revolsys.geometry.model.LinearRing)26 PointDouble (com.revolsys.geometry.model.impl.PointDouble)22 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)19 Edge (com.revolsys.geometry.graph.Edge)18 Test (org.junit.Test)17 Punctual (com.revolsys.geometry.model.Punctual)16 Segment (com.revolsys.geometry.model.segment.Segment)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)15 Record (com.revolsys.record.Record)15 Lineal (com.revolsys.geometry.model.Lineal)14