public LinearRing nextLinearRing(final Envelope envelope) {
   LinearRing result;
   do {
     final CoordinateList cl = new CoordinateList(nextLineString(envelope).getCoordinates());
     cl.closeRing();
     result = gf.createLinearRing(cl.toCoordinateArray());
   } while (!result.isValid());
   return result;
 }
Пример #2
0
 private static void addEdge(Coordinate[] coords, boolean isForward, CoordinateList coordList) {
   if (isForward) {
     for (int i = 0; i < coords.length; i++) {
       coordList.add(coords[i], false);
     }
   } else {
     for (int i = coords.length - 1; i >= 0; i--) {
       coordList.add(coords[i], false);
     }
   }
 }
 public Coordinate[] simplify() {
   usePt = new boolean[pts.length];
   for (int i = 0; i < pts.length; i++) {
     usePt[i] = true;
   }
   simplifySection(0, pts.length - 1);
   CoordinateList coordList = new CoordinateList();
   for (int i = 0; i < pts.length; i++) {
     if (usePt[i]) coordList.add(new Coordinate(pts[i]));
   }
   return coordList.toCoordinateArray();
 }
Пример #4
0
 /**
  * Computes the list of coordinates which are contained in this ring. The coordinatea are computed
  * once only and cached.
  *
  * @return an array of the {@link Coordinate}s in this ring
  */
 private Coordinate[] getCoordinates() {
   if (ringPts == null) {
     CoordinateList coordList = new CoordinateList();
     for (Iterator i = deList.iterator(); i.hasNext(); ) {
       DirectedEdge de = (DirectedEdge) i.next();
       PolygonizeEdge edge = (PolygonizeEdge) de.getEdge();
       addEdge(edge.getLine().getCoordinates(), de.getEdgeDirection(), coordList);
     }
     ringPts = coordList.toCoordinateArray();
   }
   return ringPts;
 }
Пример #5
0
  private void densify(Coordinate p0, Coordinate p1, double segLength) {
    double origLen = p1.distance(p0);
    int nPtsToAdd = (int) Math.floor(origLen / segLength);

    double delx = p1.x - p0.x;
    double dely = p1.y - p0.y;

    double segLenFrac = segLength / origLen;
    for (int i = 0; i <= nPtsToAdd; i++) {
      double addedPtFrac = i * segLenFrac;
      Coordinate pt = new Coordinate(p0.x + addedPtFrac * delx, p0.y + addedPtFrac * dely);
      newCoords.add(pt, false);
    }
    newCoords.add(new Coordinate(p1), false);
  }
Пример #6
0
  public Geometry densify(double segLength) {
    newCoords = new CoordinateList();

    CoordinateSequence seq = inputLine.getCoordinateSequence();

    Coordinate p0 = new Coordinate();
    Coordinate p1 = new Coordinate();
    seq.getCoordinate(0, p0);
    newCoords.add(new Coordinate(p0));

    for (int i = 0; i < seq.size() - 1; i++) {
      seq.getCoordinate(i, p0);
      seq.getCoordinate(i + 1, p1);
      densify(p0, p1, segLength);
    }
    Coordinate[] newPts = newCoords.toCoordinateArray();
    return inputLine.getFactory().createLineString(newPts);
  }
  public Coordinate[] edit(Coordinate[] coordinates, Geometry geom) {
    if (coordinates.length == 0) return null;

    Coordinate[] reducedCoords = new Coordinate[coordinates.length];
    // copy coordinates and reduce
    for (int i = 0; i < coordinates.length; i++) {
      Coordinate coord = new Coordinate(coordinates[i]);
      targetPM.makePrecise(coord);
      reducedCoords[i] = coord;
    }
    // remove repeated points, to simplify returned geometry as much as possible
    CoordinateList noRepeatedCoordList = new CoordinateList(reducedCoords, false);
    Coordinate[] noRepeatedCoords = noRepeatedCoordList.toCoordinateArray();

    /**
     * Check to see if the removal of repeated points collapsed the coordinate List to an invalid
     * length for the type of the parent geometry. It is not necessary to check for Point collapses,
     * since the coordinate list can never collapse to less than one point. If the length is
     * invalid, return the full-length coordinate array first computed, or null if collapses are
     * being removed. (This may create an invalid geometry - the client must handle this.)
     */
    int minLength = 0;
    if (geom instanceof LineString) minLength = 2;
    if (geom instanceof LinearRing) minLength = 4;

    Coordinate[] collapsedCoords = reducedCoords;
    if (removeCollapsed) collapsedCoords = null;

    // return null or orginal length coordinate array
    if (noRepeatedCoords.length < minLength) {
      return collapsedCoords;
    }

    // ok to return shorter coordinate array
    return noRepeatedCoords;
  }