Esempio n. 1
0
  /**
   * Add the given line to the graph
   *
   * @param wrappedLine is MasonGeometry wrapping a JTS line
   * @note Some code copied from JTS PolygonizeGraph.addEdge() and hacked to fit
   */
  private void addLineString(MasonGeometry wrappedLine) {
    LineString line = (LineString) wrappedLine.geometry;

    if (line.isEmpty()) {
      return;
    }

    Coordinate[] linePts = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());

    if (linePts.length < 2) {
      return;
    }

    Coordinate startPt = linePts[0];
    Coordinate endPt = linePts[linePts.length - 1];

    Node nStart = getNode(startPt); // nodes added as necessary side-effect
    Node nEnd = getNode(endPt);

    GeomPlanarGraphEdge edge = new GeomPlanarGraphEdge(line);

    GeomPlanarGraphDirectedEdge de0 =
        new GeomPlanarGraphDirectedEdge(nStart, nEnd, linePts[1], true);
    GeomPlanarGraphDirectedEdge de1 =
        new GeomPlanarGraphDirectedEdge(nEnd, nStart, linePts[linePts.length - 2], false);

    edge.setDirectedEdges(de0, de1);

    edge.setAttributes(wrappedLine.getAttributes());

    add(edge);
  }