Java 类com.vividsolutions.jts.geomgraph.PlanarGraph 实例源码

项目:Earth    文件:ConnectedInteriorTester.java   
private void visitInteriorRing(LineString ring, PlanarGraph graph) {
    Coordinate[] pts = ring.getCoordinates();
    Coordinate pt0 = pts[0];
    /**
     * Find first point in coord list different to initial point.
     * Need special check since the first point may be repeated.
     */
    Coordinate pt1 = findDifferentPoint(pts, pt0);
    Edge e = graph.findEdgeInSameDirection(pt0, pt1);
    DirectedEdge de = (DirectedEdge) graph.findEdgeEnd(e);
    DirectedEdge intDe = null;
    if (de.getLabel().getLocation(0, Position.RIGHT) == Location.INTERIOR) {
        intDe = de;
    } else if (de.getSym().getLabel().getLocation(0, Position.RIGHT) == Location.INTERIOR) {
        intDe = de.getSym();
    }
    Assert.isTrue(intDe != null, "unable to find dirEdge with Interior on RHS");

    this.visitLinkedDirectedEdges(intDe);
}
项目:Earth    文件:BufferBuilder.java   
private List createSubgraphs(PlanarGraph graph) {
    List subgraphList = new ArrayList();
    for (Object o : graph.getNodes()) {
        Node node = (Node) o;
        if (!node.isVisited()) {
            BufferSubgraph subgraph = new BufferSubgraph();
            subgraph.create(node);
            subgraphList.add(subgraph);
        }
    }
    /**
     * Sort the subgraphs in descending order of their rightmost coordinate.
     * This ensures that when the Polygons for the subgraphs are built,
     * subgraphs for shells will have been built before the subgraphs for
     * any holes they contain.
     */
    subgraphList.sort(Collections.reverseOrder());
    return subgraphList;
}
项目:Earth    文件:ConnectedInteriorTester.java   
public boolean isInteriorsConnected() {
    // node the edges, in case holes touch the shell
    List splitEdges = new ArrayList();
    this.geomGraph.computeSplitEdges(splitEdges);

    // form the edges into rings
    PlanarGraph graph = new PlanarGraph(new OverlayNodeFactory());
    graph.addEdges(splitEdges);
    this.setInteriorEdgesInResult(graph);
    graph.linkResultDirectedEdges();
    List edgeRings = this.buildEdgeRings(graph.getEdgeEnds());

    /**
     * Mark all the edges for the edgeRings corresponding to the shells
     * of the input polygons.  Note only ONE ring gets marked for each shell.
     */
    this.visitShellInteriors(this.geomGraph.getGeometry(), graph);

    /**
     * If there are any unvisited shell edges
     * (i.e. a ring which is not a hole and which has the interior
     * of the parent area on the RHS)
     * this means that one or more holes must have split the interior of the
     * polygon into at least two pieces.  The polygon is thus invalid.
     */
    return !this.hasUnvisitedShellEdge(edgeRings);
}
项目:Earth    文件:ConnectedInteriorTester.java   
private void setInteriorEdgesInResult(PlanarGraph graph) {
    for (Object o : graph.getEdgeEnds()) {
        DirectedEdge de = (DirectedEdge) o;
        if (de.getLabel().getLocation(0, Position.RIGHT) == Location.INTERIOR) {
            de.setInResult(true);
        }
    }
}
项目:Earth    文件:PolygonBuilder.java   
/**
 * Add a set of edges and nodes, which form a graph.
 * The graph is assumed to contain one or more polygons,
 * possibly with holes.
 */
public void add(Collection dirEdges, Collection nodes) {
    PlanarGraph.linkResultDirectedEdges(nodes);
    List maxEdgeRings = this.buildMaximalEdgeRings(dirEdges);
    List freeHoleList = new ArrayList();
    List edgeRings = this.buildMinimalEdgeRings(maxEdgeRings, this.shellList, freeHoleList);
    this.sortShellsAndHoles(edgeRings, this.shellList, freeHoleList);
    this.placeFreeHoles(this.shellList, freeHoleList);
    //Assert: every hole on freeHoleList has a shell assigned to it
}
项目:Earth    文件:OverlayOp.java   
public OverlayOp(Geometry g0, Geometry g1) {
    super(g0, g1);
    this.graph = new PlanarGraph(new OverlayNodeFactory());
    /**
     * Use factory of primary geometry.
     * Note that this does NOT handle mixed-precision arguments
     * where the second arg has greater precision than the first.
     */
    this.geomFact = g0.getFactory();
}
项目:jts    文件:PolygonBuilder.java   
/**
 * Add a set of edges and nodes, which form a graph.
 * The graph is assumed to contain one or more polygons,
 * possibly with holes.
 */
public void add(Collection dirEdges, Collection nodes) {
    PlanarGraph.linkResultDirectedEdges(nodes);
    List maxEdgeRings = buildMaximalEdgeRings(dirEdges);
    List freeHoleList = new ArrayList();
    List edgeRings = buildMinimalEdgeRings(maxEdgeRings, shellList, freeHoleList);
    sortShellsAndHoles(edgeRings, shellList, freeHoleList);
    placeFreeHoles(shellList, freeHoleList);
    //Assert: every hole on freeHoleList has a shell assigned to it
}
项目:Earth    文件:ConsistentPolygonRingChecker.java   
public ConsistentPolygonRingChecker(PlanarGraph graph) {
    this.graph = graph;
}
项目:Earth    文件:OverlayOp.java   
public PlanarGraph getGraph() {
    return this.graph;
}
项目:Earth    文件:BufferBuilder.java   
public Geometry buffer(Geometry g, double distance) {
        PrecisionModel precisionModel = this.workingPrecisionModel;
        if (precisionModel == null) {
            precisionModel = g.getPrecisionModel();
        }

        // factory must be the same as the one used by the input
        this.geomFact = g.getFactory();

        OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, this.bufParams);

        OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);

        List bufferSegStrList = curveSetBuilder.getCurves();

        // short-circuit test
        if (bufferSegStrList.size() <= 0) {
            return this.createEmptyResultGeometry();
        }

//BufferDebug.runCount++;
//String filename = "run" + BufferDebug.runCount + "_curves";
//System.out.println("saving " + filename);
//BufferDebug.saveEdges(bufferEdgeList, filename);
// DEBUGGING ONLY
//WKTWriter wktWriter = new WKTWriter();
//Debug.println("Rings: " + wktWriter.write(convertSegStrings(bufferSegStrList.iterator())));
//wktWriter.setMaxCoordinatesPerLine(10);
//System.out.println(wktWriter.writeFormatted(convertSegStrings(bufferSegStrList.iterator())));

        this.computeNodedEdges(bufferSegStrList, precisionModel);
        this.graph = new PlanarGraph(new OverlayNodeFactory());
        this.graph.addEdges(this.edgeList.getEdges());

        List subgraphList = this.createSubgraphs(this.graph);
        PolygonBuilder polyBuilder = new PolygonBuilder(this.geomFact);
        this.buildSubgraphs(subgraphList, polyBuilder);
        List resultPolyList = polyBuilder.getPolygons();

        // just in case...
        if (resultPolyList.size() <= 0) {
            return this.createEmptyResultGeometry();
        }

        Geometry resultGeom = this.geomFact.buildGeometry(resultPolyList);
        return resultGeom;
    }
项目:Earth    文件:PolygonBuilder.java   
/**
 * Add a complete graph.
 * The graph is assumed to contain one or more polygons,
 * possibly with holes.
 */
public void add(PlanarGraph graph) {
    this.add(graph.getEdgeEnds(), graph.getNodes());
}
项目:jts    文件:PolygonBuilder.java   
/**
 * Add a complete graph.
 * The graph is assumed to contain one or more polygons,
 * possibly with holes.
 */
public void add(PlanarGraph graph) {
    add(graph.getEdgeEnds(), graph.getNodes());
}