private void addLine(Coordinate[] pts) {
   SegmentString segStr = new BasicSegmentString(pts, null);
   List segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);
   for (Iterator i = segChains.iterator(); i.hasNext(); ) {
     MonotoneChain mc = (MonotoneChain) i.next();
     index.insert(mc.getEnvelope(), mc);
   }
 }
Ejemplo 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);
 }
Ejemplo n.º 3
0
  private void computeNodedEdges(List bufferSegStrList, PrecisionModel precisionModel) {
    Noder noder = getNoder(precisionModel);
    noder.computeNodes(bufferSegStrList);
    Collection nodedSegStrings = noder.getNodedSubstrings();
    // DEBUGGING ONLY
    // BufferDebug.saveEdges(nodedEdges, "run" + BufferDebug.runCount + "_nodedEdges");

    for (Iterator i = nodedSegStrings.iterator(); i.hasNext(); ) {
      SegmentString segStr = (SegmentString) i.next();
      Label oldLabel = (Label) segStr.getData();
      Edge edge = new Edge(segStr.getCoordinates(), new Label(oldLabel));
      insertUniqueEdge(edge);
    }
    // saveEdges(edgeList.getEdges(), "run" + runCount + "_collapsedEdges");
  }
Ejemplo n.º 4
0
 /**
  * A trivial intersection is an apparent self-intersection which in fact is simply the point
  * shared by adjacent line segments. Note that closed edges require a special check for the point
  * shared by the beginning and end segments.
  */
 private boolean isTrivialIntersection(
     SegmentString e0, int segIndex0, SegmentString e1, int segIndex1) {
   if (e0 == e1) {
     if (li.getIntersectionNum() == 1) {
       if (isAdjacentSegments(segIndex0, segIndex1)) return true;
       if (e0.isClosed()) {
         int maxSegIndex = e0.size() - 1;
         if ((segIndex0 == 0 && segIndex1 == maxSegIndex)
             || (segIndex1 == 0 && segIndex0 == maxSegIndex)) {
           return true;
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 5
0
  /**
   * This method is called by clients of the {@link SegmentIntersector} class to process
   * intersections for two segments of the {@link SegmentString}s being intersected. Note that some
   * clients (such as {@link MonotoneChain}s) may optimize away this call for segment pairs which
   * they have determined do not intersect (e.g. by an disjoint envelope test).
   */
  public void processIntersections(
      SegmentString e0, int segIndex0, SegmentString e1, int segIndex1) {
    // don't bother intersecting a segment with itself
    if (e0 == e1 && segIndex0 == segIndex1) return;

    Coordinate p00 = e0.getCoordinates()[segIndex0];
    Coordinate p01 = e0.getCoordinates()[segIndex0 + 1];
    Coordinate p10 = e1.getCoordinates()[segIndex1];
    Coordinate p11 = e1.getCoordinates()[segIndex1 + 1];

    li.computeIntersection(p00, p01, p10, p11);
    // if (li.hasIntersection() && li.isProper()) Debug.println(li);

    if (li.hasIntersection()) {
      if (li.isInteriorIntersection()) {
        for (int intIndex = 0; intIndex < li.getIntersectionNum(); intIndex++) {
          interiorIntersections.add(li.getIntersection(intIndex));
        }
        ((NodedSegmentString) e0).addIntersections(li, segIndex0, 0);
        ((NodedSegmentString) e1).addIntersections(li, segIndex1, 1);
      }
    }
  }
Ejemplo n.º 6
0
  /**
   * This method is called by clients of the {@link SegmentIntersector} class to process
   * intersections for two segments of the {@link SegmentStrings} being intersected. Note that some
   * clients (such as {@link MonotoneChain}s) may optimize away this call for segment pairs which
   * they have determined do not intersect (e.g. by an disjoint envelope test).
   */
  public void processIntersections(
      SegmentString e0, int segIndex0, SegmentString e1, int segIndex1) {
    if (e0 == e1 && segIndex0 == segIndex1) return;
    numTests++;
    Coordinate p00 = e0.getCoordinates()[segIndex0];
    Coordinate p01 = e0.getCoordinates()[segIndex0 + 1];
    Coordinate p10 = e1.getCoordinates()[segIndex1];
    Coordinate p11 = e1.getCoordinates()[segIndex1 + 1];

    li.computeIntersection(p00, p01, p10, p11);
    // if (li.hasIntersection() && li.isProper()) Debug.println(li);
    if (li.hasIntersection()) {
      // intersectionFound = true;
      numIntersections++;
      if (li.isInteriorIntersection()) {
        numInteriorIntersections++;
        hasInterior = true;
        // System.out.println(li);
      }
      // if the segments are adjacent they have at least one trivial intersection,
      // the shared endpoint.  Don't bother adding it if it is the
      // only intersection.
      if (!isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
        hasIntersection = true;
        ((NodedSegmentString) e0).addIntersections(li, segIndex0, 0);
        ((NodedSegmentString) e1).addIntersections(li, segIndex1, 1);
        if (li.isProper()) {
          numProperIntersections++;
          // Debug.println(li.toString());  Debug.println(li.getIntersection(0));
          // properIntersectionPoint = (Coordinate) li.getIntersection(0).clone();
          hasProper = true;
          hasProperInterior = true;
        }
      }
    }
  }