Search in sources :

Example 1 with NodedSegmentString

use of com.revolsys.geometry.noding.NodedSegmentString in project com.revolsys.open by revolsys.

the class SimpleSnapRounder method computeVertexSnaps.

/**
 * Computes nodes introduced as a result of
 * snapping segments to vertices of other segments
 *
 * @param edges the list of segment strings to snap together
 */
public void computeVertexSnaps(final Collection edges) {
    for (final Iterator i0 = edges.iterator(); i0.hasNext(); ) {
        final NodedSegmentString edge0 = (NodedSegmentString) i0.next();
        for (final Iterator i1 = edges.iterator(); i1.hasNext(); ) {
            final NodedSegmentString edge1 = (NodedSegmentString) i1.next();
            computeVertexSnaps(edge0, edge1);
        }
    }
}
Also used : NodedSegmentString(com.revolsys.geometry.noding.NodedSegmentString) Iterator(java.util.Iterator)

Example 2 with NodedSegmentString

use of com.revolsys.geometry.noding.NodedSegmentString in project com.revolsys.open by revolsys.

the class Buffer method buffer.

private static Geometry buffer(final Noder noder, final GeometryFactory precisionModel, final Geometry geometry, final double distance, final BufferParameters parameters) {
    final GeometryFactory geometryFactory = geometry.getGeometryFactory();
    final OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(geometry, distance, precisionModel, parameters);
    final List<NodedSegmentString> curves = curveSetBuilder.getCurves();
    if (curves.size() == 0) {
        return geometryFactory.polygon();
    } else {
        final EdgeList edgeList = new EdgeList();
        computeNodedEdges(noder, edgeList, curves);
        final PlanarGraph graph = new PlanarGraph(new OverlayNodeFactory());
        final List<Edge> edges = edgeList.getEdges();
        graph.addEdges(edges);
        final List<BufferSubgraph> subgraphList = newSubgraphs(graph);
        final PolygonBuilder polyBuilder = new PolygonBuilder(geometryFactory);
        buildSubgraphs(subgraphList, polyBuilder);
        final List<Polygon> polygons = polyBuilder.getPolygons();
        if (polygons.size() == 0) {
            return geometryFactory.polygon();
        } else {
            final Geometry resultGeom = geometryFactory.buildGeometry(polygons);
            return resultGeom;
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) OverlayNodeFactory(com.revolsys.geometry.operation.overlay.OverlayNodeFactory) EdgeList(com.revolsys.geometry.geomgraph.EdgeList) Geometry(com.revolsys.geometry.model.Geometry) PlanarGraph(com.revolsys.geometry.geomgraph.PlanarGraph) NodedSegmentString(com.revolsys.geometry.noding.NodedSegmentString) Polygon(com.revolsys.geometry.model.Polygon) Edge(com.revolsys.geometry.geomgraph.Edge) DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) PolygonBuilder(com.revolsys.geometry.operation.overlay.PolygonBuilder)

Example 3 with NodedSegmentString

use of com.revolsys.geometry.noding.NodedSegmentString in project com.revolsys.open by revolsys.

the class OffsetCurveSetBuilder method addCurve.

/**
 * Creates a {@link SegmentString} for a coordinate list which is a raw offset curve,
 * and adds it to the list of buffer curves.
 * The SegmentString is tagged with a Label giving the topology of the curve.
 * The curve may be oriented in either direction.
 * If the curve is oriented CW, the locations will be:
 * <br>Left: Location.EXTERIOR
 * <br>Right: Location.INTERIOR
 */
private void addCurve(final LineString points, final Location leftLoc, final Location rightLoc) {
    if (points != null && points.getVertexCount() >= 2) {
        final Label label = new Label(0, Location.BOUNDARY, leftLoc, rightLoc);
        final NodedSegmentString segment = new NodedSegmentString(points, label);
        this.curveList.add(segment);
    }
}
Also used : NodedSegmentString(com.revolsys.geometry.noding.NodedSegmentString) Label(com.revolsys.geometry.geomgraph.Label)

Example 4 with NodedSegmentString

use of com.revolsys.geometry.noding.NodedSegmentString in project com.revolsys.open by revolsys.

the class PreparedPolygon method intersects.

@Override
public boolean intersects(final Geometry geometry) {
    if (envelopesIntersect(geometry)) {
        if (this.isRectangle) {
            return RectangleIntersects.rectangleIntersects(this, geometry);
        } else {
            final PointOnGeometryLocator pointLocator = getPointLocator();
            /**
             * Do point-in-poly tests first, since they are cheaper and may result in a
             * quick positive result.
             *
             * If a point of any test components lie in target, result is true
             */
            final boolean isInPrepGeomArea = AbstractPreparedPolygonContains.isAnyTestComponentInTarget(pointLocator, geometry);
            if (isInPrepGeomArea) {
                return true;
            }
            /**
             * If input contains only points, then at
             * this point it is known that none of them are contained in the target
             */
            if (geometry.getDimension() == 0) {
                return false;
            } else {
                /**
                 * If any segments intersect, result is true
                 */
                final List<NodedSegmentString> lineSegStr = SegmentStringUtil.extractSegmentStrings(geometry);
                // (i.e. NOT for point inputs)
                if (lineSegStr.size() > 0) {
                    final boolean segsIntersect = getIntersectionFinder().intersects(lineSegStr);
                    if (segsIntersect) {
                        return true;
                    }
                }
                /**
                 * If the test has dimension = 2 as well, it is necessary to test for proper
                 * inclusion of the target. Since no segments intersect, it is sufficient to
                 * test representative points.
                 */
                if (geometry.getDimension() == 2) {
                    // TODO: generalize this to handle GeometryCollections
                    final boolean isPrepGeomInArea = AbstractPreparedPolygonContains.isAnyTargetComponentInAreaTest(geometry, this);
                    if (isPrepGeomInArea) {
                        return true;
                    }
                }
                return false;
            }
        }
    } else {
        return false;
    }
}
Also used : NodedSegmentString(com.revolsys.geometry.noding.NodedSegmentString) PointOnGeometryLocator(com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator)

Example 5 with NodedSegmentString

use of com.revolsys.geometry.noding.NodedSegmentString in project com.revolsys.open by revolsys.

the class GeometryNoder method node.

/**
 * Nodes the linework of a set of Geometrys using SnapRounding.
 *
 * @param geometries a Collection of Geometrys of any type
 * @return a List of LineStrings representing the noded linework of the input
 */
public List<LineString> node(final Collection<? extends Geometry> geometries) {
    // get geometry factory
    final Geometry geom0 = geometries.iterator().next();
    this.geomFact = geom0.getGeometryFactory();
    final Collection<LineString> lines = extractLines(geometries);
    final List<NodedSegmentString> segStrings = toSegmentStrings(lines);
    // Noder sr = new SimpleSnapRounder(pm);
    final Noder sr = new MCIndexSnapRounder(this.scale);
    sr.computeNodes(segStrings);
    final Collection<NodedSegmentString> nodedLines = sr.getNodedSubstrings();
    // TODO: improve this to check for full snap-rounded correctness
    if (this.isValidityChecked) {
        final NodingValidator nv = new NodingValidator(nodedLines);
        nv.checkValid();
    }
    return toLineStrings(nodedLines);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) NodedSegmentString(com.revolsys.geometry.noding.NodedSegmentString) LineString(com.revolsys.geometry.model.LineString) NodingValidator(com.revolsys.geometry.noding.NodingValidator) Noder(com.revolsys.geometry.noding.Noder)

Aggregations

NodedSegmentString (com.revolsys.geometry.noding.NodedSegmentString)8 LineString (com.revolsys.geometry.model.LineString)3 DirectedEdge (com.revolsys.geometry.geomgraph.DirectedEdge)2 Edge (com.revolsys.geometry.geomgraph.Edge)2 Label (com.revolsys.geometry.geomgraph.Label)2 Geometry (com.revolsys.geometry.model.Geometry)2 Iterator (java.util.Iterator)2 PointOnGeometryLocator (com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator)1 EdgeList (com.revolsys.geometry.geomgraph.EdgeList)1 PlanarGraph (com.revolsys.geometry.geomgraph.PlanarGraph)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Point (com.revolsys.geometry.model.Point)1 Polygon (com.revolsys.geometry.model.Polygon)1 Noder (com.revolsys.geometry.noding.Noder)1 NodingValidator (com.revolsys.geometry.noding.NodingValidator)1 SegmentString (com.revolsys.geometry.noding.SegmentString)1 OverlayNodeFactory (com.revolsys.geometry.operation.overlay.OverlayNodeFactory)1 PolygonBuilder (com.revolsys.geometry.operation.overlay.PolygonBuilder)1 ArrayList (java.util.ArrayList)1