/**
  * Creates the levels higher than the given level
  *
  * @param boundablesOfALevel the level to build on
  * @param level the level of the Boundables, or -1 if the boundables are item boundables (that is,
  *     below level 0)
  * @return the root, which may be a ParentNode or a LeafNode
  */
 private AbstractNode createHigherLevels(List boundablesOfALevel, int level) {
   Assert.isTrue(!boundablesOfALevel.isEmpty());
   List parentBoundables = createParentBoundables(boundablesOfALevel, level + 1);
   if (parentBoundables.size() == 1) {
     return (AbstractNode) parentBoundables.get(0);
   }
   return createHigherLevels(parentBoundables, level + 1);
 }
Esempio n. 2
0
 private static Geometry convertSegStrings(Iterator it) {
   GeometryFactory fact = new GeometryFactory();
   List lines = new ArrayList();
   while (it.hasNext()) {
     SegmentString ss = (SegmentString) it.next();
     LineString line = fact.createLineString(ss.getCoordinates());
     lines.add(line);
   }
   return fact.buildGeometry(lines);
 }
Esempio n. 3
0
  public void findEdge(List dirEdgeList) {
    /**
     * Check all forward DirectedEdges only. This is still general, because each edge has a forward
     * DirectedEdge.
     */
    for (Iterator i = dirEdgeList.iterator(); i.hasNext(); ) {
      DirectedEdge de = (DirectedEdge) i.next();
      if (!de.isForward()) continue;
      checkForRightmostCoordinate(de);
    }

    /**
     * If the rightmost point is a node, we need to identify which of the incident edges is
     * rightmost.
     */
    Assert.isTrue(
        minIndex != 0 || minCoord.equals(minDe.getCoordinate()),
        "inconsistency in rightmost processing");
    if (minIndex == 0) {
      findRightmostEdgeAtNode();
    } else {
      findRightmostEdgeAtVertex();
    }
    /** now check that the extreme side is the R side. If not, use the sym instead. */
    orientedDe = minDe;
    int rightmostSide = getRightmostSide(minDe, minIndex);
    if (rightmostSide == Position.LEFT) {
      orientedDe = minDe.getSym();
    }
  }
 private void query(Object searchBounds, AbstractNode node, ItemVisitor visitor) {
   List childBoundables = node.getChildBoundables();
   for (int i = 0; i < childBoundables.size(); i++) {
     Boundable childBoundable = (Boundable) childBoundables.get(i);
     if (!getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) {
       continue;
     }
     if (childBoundable instanceof AbstractNode) {
       query(searchBounds, (AbstractNode) childBoundable, visitor);
     } else if (childBoundable instanceof ItemBoundable) {
       visitor.visitItem(((ItemBoundable) childBoundable).getItem());
     } else {
       Assert.shouldNeverReachHere();
     }
   }
 }
 private List itemsTree(AbstractNode node) {
   List valuesTreeForNode = new ArrayList();
   for (Iterator i = node.getChildBoundables().iterator(); i.hasNext(); ) {
     Boundable childBoundable = (Boundable) i.next();
     if (childBoundable instanceof AbstractNode) {
       List valuesTreeForChild = itemsTree((AbstractNode) childBoundable);
       // only add if not null (which indicates an item somewhere in this tree
       if (valuesTreeForChild != null) valuesTreeForNode.add(valuesTreeForChild);
     } else if (childBoundable instanceof ItemBoundable) {
       valuesTreeForNode.add(((ItemBoundable) childBoundable).getItem());
     } else {
       Assert.shouldNeverReachHere();
     }
   }
   if (valuesTreeForNode.size() <= 0) return null;
   return valuesTreeForNode;
 }
Esempio n. 6
0
  public Geometry buffer(Geometry g, double distance) {
    PrecisionModel precisionModel = workingPrecisionModel;
    if (precisionModel == null) precisionModel = g.getPrecisionModel();

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

    OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, bufParams);

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

    List bufferSegStrList = curveSetBuilder.getCurves();

    // short-circuit test
    if (bufferSegStrList.size() <= 0) {
      return 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())));

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

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

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

    Geometry resultGeom = geomFact.buildGeometry(resultPolyList);
    return resultGeom;
  }
Esempio n. 7
0
 private List createSubgraphs(PlanarGraph graph) {
   List subgraphList = new ArrayList();
   for (Iterator i = graph.getNodes().iterator(); i.hasNext(); ) {
     Node node = (Node) i.next();
     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.
    */
   Collections.sort(subgraphList, Collections.reverseOrder());
   return subgraphList;
 }
Esempio n. 8
0
 /**
  * Completes the building of the input subgraphs by depth-labelling them, and adds them to the
  * PolygonBuilder. The subgraph list must be sorted in rightmost-coordinate order.
  *
  * @param subgraphList the subgraphs to build
  * @param polyBuilder the PolygonBuilder which will build the final polygons
  */
 private void buildSubgraphs(List subgraphList, PolygonBuilder polyBuilder) {
   List processedGraphs = new ArrayList();
   for (Iterator i = subgraphList.iterator(); i.hasNext(); ) {
     BufferSubgraph subgraph = (BufferSubgraph) i.next();
     Coordinate p = subgraph.getRightmostCoordinate();
     //      int outsideDepth = 0;
     //      if (polyBuilder.containsPoint(p))
     //        outsideDepth = 1;
     SubgraphDepthLocater locater = new SubgraphDepthLocater(processedGraphs);
     int outsideDepth = locater.getDepth(p);
     //      try {
     subgraph.computeDepth(outsideDepth);
     //      }
     //      catch (RuntimeException ex) {
     //        // debugging only
     //        //subgraph.saveDirEdges();
     //        throw ex;
     //      }
     subgraph.findResultEdges();
     processedGraphs.add(subgraph);
     polyBuilder.add(subgraph.getDirectedEdges(), subgraph.getNodes());
   }
 }
 /**
  * Sorts the childBoundables then divides them into groups of size M, where M is the node
  * capacity.
  */
 protected List createParentBoundables(List childBoundables, int newLevel) {
   Assert.isTrue(!childBoundables.isEmpty());
   ArrayList parentBoundables = new ArrayList();
   parentBoundables.add(createNode(newLevel));
   ArrayList sortedChildBoundables = new ArrayList(childBoundables);
   Collections.sort(sortedChildBoundables, getComparator());
   for (Iterator i = sortedChildBoundables.iterator(); i.hasNext(); ) {
     Boundable childBoundable = (Boundable) i.next();
     if (lastNode(parentBoundables).getChildBoundables().size() == getNodeCapacity()) {
       parentBoundables.add(createNode(newLevel));
     }
     lastNode(parentBoundables).addChildBoundable(childBoundable);
   }
   return parentBoundables;
 }
 protected AbstractNode lastNode(List nodes) {
   return (AbstractNode) nodes.get(nodes.size() - 1);
 }