Search in sources :

Example 31 with LineString

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

the class PlanarPolygon3D method intersects.

public boolean intersects(final Point pt, final LineString ring) {
    final LineString seq = ring;
    final LineString seqProj = project(seq, this.facingPlane);
    final Point ptProj = project(pt, this.facingPlane);
    return Location.EXTERIOR != RayCrossingCounter.locatePointInRing(ptProj, seqProj);
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 32 with LineString

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

the class Distance3DOp method computeMinDistancePolygonPoint.

private void computeMinDistancePolygonPoint(final PlanarPolygon3D polyPlane, final Point point, final boolean flip) {
    final Point pt = point.getPoint();
    final LineString shell = polyPlane.getPolygon().getShell();
    if (polyPlane.intersects(pt, shell)) {
        // point is either inside or in a hole
        final int nHole = polyPlane.getPolygon().getHoleCount();
        for (int i = 0; i < nHole; i++) {
            final LineString hole = polyPlane.getPolygon().getHole(i);
            if (polyPlane.intersects(pt, hole)) {
                computeMinDistanceLinePoint(hole, point, flip);
                return;
            }
        }
        // point is in interior of polygon
        // distance is distance to polygon plane
        final double dist = Math.abs(polyPlane.getPlane().orientedDistance(pt));
        updateDistance(dist, new GeometryLocation(polyPlane.getPolygon(), 0, pt), new GeometryLocation(point, 0, pt), flip);
    }
    // point is outside polygon, so compute distance to shell linework
    computeMinDistanceLinePoint(shell, point, flip);
}
Also used : GeometryLocation(com.revolsys.geometry.operation.distance.GeometryLocation) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 33 with LineString

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

the class Distance3DOp method intersection.

private Point intersection(final PlanarPolygon3D poly, final LineString line) {
    final LineString seq = line;
    if (seq.getVertexCount() == 0) {
        return null;
    }
    // start point of line
    Point p0 = seq.getPoint(0);
    double d0 = poly.getPlane().orientedDistance(p0);
    // for each segment in the line
    for (int i = 0; i < seq.getVertexCount() - 1; i++) {
        p0 = seq.getPoint(i);
        final Point p1 = seq.getPoint(i + 1);
        final double d1 = poly.getPlane().orientedDistance(p1);
        /**
         * If the oriented distances of the segment endpoints have the same sign,
         * the segment does not cross the plane, and is skipped.
         */
        if (d0 * d1 > 0) {
            continue;
        }
        /**
         * Compute segment-plane intersection point
         * which is then used for a point-in-polygon test.
         * The endpoint distances to the plane d0 and d1
         * give the proportional distance of the intersection point
         * along the segment.
         */
        final Point intPt = segmentPoint(p0, p1, d0, d1);
        // Point intPt = polyPlane.intersection(p0, p1, s0, s1);
        if (poly.intersects(intPt)) {
            return intPt;
        }
        // shift to next segment
        d0 = d1;
    }
    return null;
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 34 with LineString

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

the class LineMergeGraph method addEdge.

/**
 * Adds an Edge, DirectedEdges, and Nodes for the given LineString representation
 * of an edge.
 * Empty lines or lines with all coordinates equal are not added.
 *
 * @param line the linestring to add to the graph
 */
public void addEdge(final LineString line) {
    if (line.isEmpty()) {
        return;
    }
    final LineString points = line.removeDuplicatePoints();
    final int vertexCount = points.getVertexCount();
    if (vertexCount > 1) {
        final Point fromPoint = points.getPoint(0);
        final Point toPoint = points.getPoint(vertexCount - 1);
        final Node startNode = getNode(fromPoint);
        final Node endNode = getNode(toPoint);
        final DirectedEdge directedEdge0 = new LineMergeDirectedEdge(startNode, endNode, points.getPoint(1).newPoint(), true);
        final DirectedEdge directedEdge1 = new LineMergeDirectedEdge(endNode, startNode, points.getPoint(vertexCount - 2).newPoint(), false);
        final Edge edge = new LineMergeEdge(line);
        edge.setDirectedEdges(directedEdge0, directedEdge1);
        add(edge);
    }
}
Also used : DirectedEdge(com.revolsys.geometry.planargraph.DirectedEdge) LineString(com.revolsys.geometry.model.LineString) Node(com.revolsys.geometry.planargraph.Node) Point(com.revolsys.geometry.model.Point) DirectedEdge(com.revolsys.geometry.planargraph.DirectedEdge) Edge(com.revolsys.geometry.planargraph.Edge) Point(com.revolsys.geometry.model.Point)

Example 35 with LineString

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

the class LineSequencer method isSequenced.

/**
 * Tests whether a {@link Geometry} is sequenced correctly.
 * {@link LineString}s are trivially sequenced.
 * {@link Lineal}s are checked for correct sequencing.
 * Otherwise, <code>isSequenced</code> is defined
 * to be <code>true</code> for geometries that are not lineal.
 *
 * @param geom the geometry to test
 * @return <code>true</code> if the geometry is sequenced or is not lineal
 */
public static boolean isSequenced(final Geometry geom) {
    if (!(geom instanceof Lineal) || geom instanceof LineString) {
        return true;
    }
    final Lineal lineal = (Lineal) geom;
    // the nodes in all subgraphs which have been completely scanned
    final Set prevSubgraphNodes = new TreeSet();
    Point lastNode = null;
    final List currNodes = new ArrayList();
    for (int i = 0; i < lineal.getGeometryCount(); i++) {
        final LineString line = (LineString) lineal.getGeometry(i);
        final Point startNode = line.getPoint(0);
        final Point endNode = line.getPoint(line.getVertexCount() - 1);
        /**
         * If this linestring is connected to a previous subgraph, geom is not sequenced
         */
        if (prevSubgraphNodes.contains(startNode)) {
            return false;
        }
        if (prevSubgraphNodes.contains(endNode)) {
            return false;
        }
        if (lastNode != null) {
            if (!startNode.equals(lastNode)) {
                // start new connected sequence
                prevSubgraphNodes.addAll(currNodes);
                currNodes.clear();
            }
        }
        currNodes.add(startNode);
        currNodes.add(endNode);
        lastNode = endNode;
    }
    return true;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

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