Search in sources :

Example 31 with Point

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

the class Edge method addIntersection.

/**
 * Add an EdgeIntersection for intersection intIndex.
 * An intersection that falls exactly on a vertex of the edge is normalized
 * to use the higher of the two possible segmentIndexes
 */
public void addIntersection(final LineIntersector li, final int segmentIndex, final int geomIndex, final int intIndex) {
    final Point intPt = li.getIntersection(intIndex);
    int normalizedSegmentIndex = segmentIndex;
    double dist = li.getEdgeDistance(geomIndex, intIndex);
    // normalize the intersection point location
    final int nextSegIndex = normalizedSegmentIndex + 1;
    if (nextSegIndex < getVertexCount()) {
        final double nextX = getX(nextSegIndex);
        final double nextY = getY(nextSegIndex);
        // The check for point equality is 2D only - Z values are ignored
        if (intPt.equalsVertex(nextX, nextY)) {
            normalizedSegmentIndex = nextSegIndex;
            dist = 0.0;
        }
    }
    /**
     * Add the intersection point to edge intersection list.
     */
    this.eiList.add(intPt.getX(), intPt.getY(), normalizedSegmentIndex, dist);
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 32 with Point

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

the class EdgeEndStar method computeLabelling.

public void computeLabelling(final GeometryGraph[] geomGraph) {
    computeEdgeEndLabels(geomGraph[0].getBoundaryNodeRule());
    // Propagate side labels around the edges in the star
    // for each parent Geometry
    // Debug.print(this);
    propagateSideLabels(0);
    // Debug.print(this);
    // Debug.printIfWatch(this);
    propagateSideLabels(1);
    // Debug.print(this);
    // Debug.printIfWatch(this);
    /**
     * If there are edges that still have null labels for a geometry
     * this must be because there are no area edges for that geometry incident on this node.
     * In this case, to label the edge for that geometry we must test whether the
     * edge is in the interior of the geometry.
     * To do this it suffices to determine whether the node for the edge is in the interior of an area.
     * If so, the edge has location INTERIOR for the geometry.
     * In all other cases (e.g. the node is on a line, on a point, or not on the geometry at all) the edge
     * has the location EXTERIOR for the geometry.
     * <p>
     * Note that the edge cannot be on the BOUNDARY of the geometry, since then
     * there would have been a parallel edge from the Geometry at this node also labelled BOUNDARY
     * and this edge would have been labelled in the previous step.
     * <p>
     * This code causes a problem when dimensional collapses are present, since it may try and
     * determine the location of a node where a dimensional collapse has occurred.
     * The point should be considered to be on the EXTERIOR
     * of the polygon, but locate() will return INTERIOR, since it is passed
     * the original Geometry, not the collapsed version.
     *
     * If there are incident edges which are Line edges labelled BOUNDARY,
     * then they must be edges resulting from dimensional collapses.
     * In this case the other edges can be labelled EXTERIOR for this Geometry.
     *
     * MD 8/11/01 - NOT TRUE!  The collapsed edges may in fact be in the interior of the Geometry,
     * which means the other edges should be labelled INTERIOR for this Geometry.
     * Not sure how solve this...  Possibly labelling needs to be split into several phases:
     * area label propagation, symLabel merging, then finally null label resolution.
     */
    final boolean[] hasDimensionalCollapseEdge = { false, false };
    for (final EdgeEnd e : this) {
        final Label label = e.getLabel();
        for (int geomi = 0; geomi < 2; geomi++) {
            if (label.isLine(geomi) && label.getLocation(geomi) == Location.BOUNDARY) {
                hasDimensionalCollapseEdge[geomi] = true;
            }
        }
    }
    // Debug.print(this);
    for (final EdgeEnd e : this) {
        final Label label = e.getLabel();
        // Debug.println(e);
        for (int geomi = 0; geomi < 2; geomi++) {
            if (label.isAnyNull(geomi)) {
                Location loc = Location.NONE;
                if (hasDimensionalCollapseEdge[geomi]) {
                    loc = Location.EXTERIOR;
                } else {
                    final double x = e.getX1();
                    final double y = e.getY1();
                    final Point c = e.getCoordinate();
                    loc = getLocation(geomi, x, y, geomGraph);
                }
                label.setAllLocationsIfNull(geomi, loc);
            }
        }
    // Debug.println(e);
    }
// Debug.print(this);
// Debug.printIfWatch(this);
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Location(com.revolsys.geometry.model.Location)

Example 33 with Point

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

the class Densifier method densify.

private static LineString densify(final LineString line, final double distanceTolerance) {
    final List<Point> points = densifyPoints(line, distanceTolerance);
    final GeometryFactory geometryFactory = line.getGeometryFactory();
    return geometryFactory.lineString(points);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

Example 34 with Point

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

the class Densifier method densifyPoints.

/**
 * Densifies a coordinate sequence.
 *
 * @param pts
 * @param distanceTolerance
 * @return the densified coordinate sequence
 */
private static List<Point> densifyPoints(final LineString line, final double distanceTolerance) {
    final List<Point> points = new ArrayList<>();
    for (final Segment segment : line.segments()) {
        if (points.isEmpty()) {
            points.add(segment.getPoint(0));
        }
        final double length = segment.getLength();
        if (length > 0) {
            final int densifiedSegCount = (int) (length / distanceTolerance) + 1;
            if (densifiedSegCount > 1) {
                final double densifiedSegLen = length / densifiedSegCount;
                for (int j = 1; j < densifiedSegCount; j++) {
                    final double segFract = j * densifiedSegLen / length;
                    final Point point = segment.pointAlong(segFract);
                    if (!segment.isEndPoint(point)) {
                        points.add(point);
                    }
                }
            }
            points.add(segment.getPoint(1));
        }
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment) Point(com.revolsys.geometry.model.Point)

Example 35 with Point

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

the class EdgeGraph method addEdge.

/**
 * Adds an edge between the coordinates orig and dest
 * to this graph.
 *
 * @param orig the edge origin location
 * @param dest the edge destination location.
 * @return the created edge
 */
public HalfEdge addEdge(final Point orig, final Point dest) {
    final int cmp = dest.compareTo(orig);
    // ignore zero-length edges
    if (cmp == 0) {
        return null;
    }
    /**
     * Attempt to find the edge already in the graph.
     * Return it if found.
     * Otherwise, use a found edge with same origin (if any) to construct new edge.
     */
    final HalfEdge eAdj = (HalfEdge) this.vertexMap.get(orig);
    HalfEdge eSame = null;
    if (eAdj != null) {
        eSame = eAdj.find(dest);
    }
    if (eSame != null) {
        return eSame;
    }
    final HalfEdge e = insert(orig, dest, eAdj);
    return e;
}
Also used : 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