Java 类com.vividsolutions.jts.geom.CoordinateList 实例源码

项目:Earth    文件:EdgeString.java   
private Coordinate[] getCoordinates() {
    if (this.coordinates == null) {
        int forwardDirectedEdges = 0;
        int reverseDirectedEdges = 0;
        CoordinateList coordinateList = new CoordinateList();
        for (Object directedEdge1 : directedEdges) {
            LineMergeDirectedEdge directedEdge = (LineMergeDirectedEdge) directedEdge1;
            if (directedEdge.getEdgeDirection()) {
                forwardDirectedEdges++;
            } else {
                reverseDirectedEdges++;
            }
            coordinateList.add(((LineMergeEdge) directedEdge.getEdge()).getLine()
                            .getCoordinates(), false,
                    directedEdge.getEdgeDirection());
        }
        this.coordinates = coordinateList.toCoordinateArray();
        if (reverseDirectedEdges > forwardDirectedEdges) {
            CoordinateArrays.reverse(this.coordinates);
        }
    }

    return this.coordinates;
}
项目:Earth    文件:LineStringSnapper.java   
/**
 * Snap source vertices to vertices in the target.
 *
 * @param srcCoords the points to snap
 * @param snapPts the points to snap to
 */
private void snapVertices(CoordinateList srcCoords, Coordinate[] snapPts) {
    // try snapping vertices
    // if src is a ring then don't snap final vertex
    int end = this.isClosed ? srcCoords.size() - 1 : srcCoords.size();
    for (int i = 0; i < end; i++) {
        Coordinate srcPt = (Coordinate) srcCoords.get(i);
        Coordinate snapVert = this.findSnapForVertex(srcPt, snapPts);
        if (snapVert != null) {
            // update src with snap pt
            srcCoords.set(i, new Coordinate(snapVert));
            // keep final closing point in synch (rings only)
            if (i == 0 && this.isClosed) {
                srcCoords.set(srcCoords.size() - 1, new Coordinate(snapVert));
            }
        }
    }
}
项目:Earth    文件:Densifier.java   
/**
 * Densifies a coordinate sequence.
 *
 * @param pts
 * @param distanceTolerance
 * @return the densified coordinate sequence
 */
private static Coordinate[] densifyPoints(Coordinate[] pts,
                                          double distanceTolerance, PrecisionModel precModel) {
    LineSegment seg = new LineSegment();
    CoordinateList coordList = new CoordinateList();
    for (int i = 0; i < pts.length - 1; i++) {
        seg.p0 = pts[i];
        seg.p1 = pts[i + 1];
        coordList.add(seg.p0, false);
        double len = seg.getLength();
        int densifiedSegCount = (int) (len / distanceTolerance) + 1;
        if (densifiedSegCount > 1) {
            double densifiedSegLen = len / densifiedSegCount;
            for (int j = 1; j < densifiedSegCount; j++) {
                double segFract = (j * densifiedSegLen) / len;
                Coordinate p = seg.pointAlong(segFract);
                precModel.makePrecise(p);
                coordList.add(p, false);
            }
        }
    }
    coordList.add(pts[pts.length - 1], false);
    return coordList.toCoordinateArray();
}
项目:jts    文件:LineStringSnapper.java   
/**
 * Snap source vertices to vertices in the target.
 *
 * @param srcCoords the points to snap
 * @param snapPts   the points to snap to
 */
private void snapVertices(CoordinateList srcCoords, Coordinate[] snapPts) {
    // try snapping vertices
    // if src is a ring then don't snap final vertex
    int end = isClosed ? srcCoords.size() - 1 : srcCoords.size();
    for (int i = 0; i < end; i++) {
        Coordinate srcPt = (Coordinate) srcCoords.get(i);
        Coordinate snapVert = findSnapForVertex(srcPt, snapPts);
        if (snapVert != null) {
            // update src with snap pt
            srcCoords.set(i, new Coordinate(snapVert));
            // keep final closing point in synch (rings only)
            if (i == 0 && isClosed)
                srcCoords.set(srcCoords.size() - 1, new Coordinate(snapVert));
        }
    }
}
项目:jts    文件:LineStringSnapper.java   
/**
 * Snap segments of the source to nearby snap vertices.
 * Source segments are "cracked" at a snap vertex.
 * A single input segment may be snapped several times
 * to different snap vertices.
 * <p/>
 * For each distinct snap vertex, at most one source segment
 * is snapped to.  This prevents "cracking" multiple segments
 * at the same point, which would likely cause
 * topology collapse when being used on polygonal linework.
 *
 * @param srcCoords the coordinates of the source linestring to be snapped
 * @param snapPts   the target snap vertices
 */
private void snapSegments(CoordinateList srcCoords, Coordinate[] snapPts) {
    // guard against empty input
    if (snapPts.length == 0) return;

    int distinctPtCount = snapPts.length;

    // check for duplicate snap pts when they are sourced from a linear ring.
    // TODO: Need to do this better - need to check *all* snap points for dups (using a Set?)
    if (snapPts[0].equals2D(snapPts[snapPts.length - 1]))
        distinctPtCount = snapPts.length - 1;

    for (int i = 0; i < distinctPtCount; i++) {
        Coordinate snapPt = snapPts[i];
        int index = findSegmentIndexToSnap(snapPt, srcCoords);
        /**
         * If a segment to snap to was found, "crack" it at the snap pt.
         * The new pt is inserted immediately into the src segment list,
         * so that subsequent snapping will take place on the modified segments.
         * Duplicate points are not added.
         */
        if (index >= 0) {
            srcCoords.add(index + 1, new Coordinate(snapPt), false);
        }
    }
}
项目:hortonmachine    文件:GeometryTranslator.java   
/**
 * Builds a line feature from a dwg polyline 3D.
 * 
 * TODO handle these as contourlines
 * 
 */
public SimpleFeature convertDwgPolyline3D( String typeName, String layerName,
        DwgPolyline3D polyline3d, int id ) {
    double[][] ptos = polyline3d.getPts();
    CoordinateList coordList = new CoordinateList();
    if (ptos != null) {
        for( int j = 0; j < ptos.length; j++ ) {
            Coordinate coord = new Coordinate(ptos[j][0], ptos[j][1], ptos[j][2]);
            coordList.add(coord);
        }

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName(typeName);
        b.setCRS(crs);
        b.add(THE_GEOM, LineString.class);
        b.add(LAYER, String.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
        Object[] values = new Object[]{lineString, layerName};
        builder.addAll(values);
        return builder.buildFeature(typeName + "." + id);
    }
    return null;
}
项目:hortonmachine    文件:GeometryTranslator.java   
/**
 * Builds a line feature from a dwg polyline 2D.
 * 
 */
public SimpleFeature convertDwgPolyline2D( String typeName, String layerName,
        DwgPolyline2D polyline2d, int id ) {
    Point2D[] ptos = polyline2d.getPts();
    CoordinateList coordList = new CoordinateList();
    if (ptos != null) {
        for( int j = 0; j < ptos.length; j++ ) {
            Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
            coordList.add(coord);
        }

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName(typeName);
        b.setCRS(crs);
        b.add(THE_GEOM, LineString.class);
        b.add(LAYER, String.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
        Object[] values = new Object[]{lineString, layerName};
        builder.addAll(values);
        return builder.buildFeature(typeName + "." + id);
    }
    return null;
}
项目:hortonmachine    文件:GeometryTranslator.java   
/**
 * Builds a line feature from a dwg polyline 2D.
 * 
 */
public SimpleFeature convertDwgLwPolyline( String typeName, String layerName,
        DwgLwPolyline lwPolyline, int id ) {
    Point2D[] ptos = lwPolyline.getVertices();
    if (ptos != null) {
        CoordinateList coordList = new CoordinateList();
        for( int j = 0; j < ptos.length; j++ ) {
            Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
            coordList.add(coord);
        }

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName(typeName);
        b.setCRS(crs);
        b.add(THE_GEOM, LineString.class);
        b.add(LAYER, String.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
        Object[] values = new Object[]{lineString, layerName};
        builder.addAll(values);
        return builder.buildFeature(typeName + "." + id);
    }
    return null;
}
项目:hortonmachine    文件:GeometryTranslator.java   
/**
 * Builds a point feature from a dwg point.
 */
public SimpleFeature convertDwgPoint( String typeName, String layerName, DwgPoint point, int id ) {
    double[] p = point.getPoint();
    Point2D pto = new Point2D.Double(p[0], p[1]);

    CoordinateList coordList = new CoordinateList();
    Coordinate coord = new Coordinate(pto.getX(), pto.getY(), 0.0);
    coordList.add(coord);

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, MultiPoint.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry points = gF.createMultiPoint(coordList.toCoordinateArray());
    Object[] values = new Object[]{points, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
项目:hortonmachine    文件:GeometryTranslator.java   
/**
 * Builds a line feature from a dwg line.
 * 
 */
public SimpleFeature convertDwgLine( String typeName, String layerName, DwgLine line, int id ) {
    double[] p1 = line.getP1();
    double[] p2 = line.getP2();
    Point2D[] ptos = new Point2D[]{new Point2D.Double(p1[0], p1[1]),
            new Point2D.Double(p2[0], p2[1])};
    CoordinateList coordList = new CoordinateList();
    for( int j = 0; j < ptos.length; j++ ) {
        Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
        coordList.add(coord);
    }

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, LineString.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
    Object[] values = new Object[]{lineString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
项目:hortonmachine    文件:DxfVERTEX.java   
public static DxfGroup readEntity(RandomAccessFile raf, CoordinateList coordList)
                                                        throws IOException {
    Coordinate coord;
    double x=Double.NaN, y=Double.NaN, z=Double.NaN;
    DxfGroup group;
    try {
        while (null != (group = DxfGroup.readGroup(raf)) && group.getCode()!=0) {
            if (group.getCode()==10) x = group.getDoubleValue();
            else if (group.getCode()==20) y = group.getDoubleValue();
            else if (group.getCode()==30) z = group.getDoubleValue();
            else {}
        }
        if (!Double.isNaN(x) && !Double.isNaN(y)) {
            coordList.add(new Coordinate(x,y,z));
        }
    } catch (IOException ioe) {throw ioe;}
    return group;
}
项目:geodroid_master_update    文件:EdgeString.java   
private Coordinate[] getCoordinates() {
  if (coordinates == null) {
    int forwardDirectedEdges = 0;
    int reverseDirectedEdges = 0;
    CoordinateList coordinateList = new CoordinateList();
    for (Iterator i = directedEdges.iterator(); i.hasNext();) {
      LineMergeDirectedEdge directedEdge = (LineMergeDirectedEdge) i.next();
      if (directedEdge.getEdgeDirection()) {
        forwardDirectedEdges++;
      }
      else {
        reverseDirectedEdges++;
      }
      coordinateList.add(((LineMergeEdge) directedEdge.getEdge()).getLine()
                          .getCoordinates(), false,
        directedEdge.getEdgeDirection());
    }
    coordinates = coordinateList.toCoordinateArray();
    if (reverseDirectedEdges > forwardDirectedEdges) {
      CoordinateArrays.reverse(coordinates);
    }
  }

  return coordinates;
}
项目:jeql    文件:GeodeticDensifier.java   
public Geometry densify(double maxSegLenDeg)
{
  double maxSegLenRad = MathFunction.toRadians(maxSegLenDeg);

  Coordinate p0 = line.getCoordinates()[0];
  Coordinate p1 = line.getCoordinates()[1];

  CoordinateList coords = new CoordinateList();

  Coordinate dc1 = GeodeticCoord.toCartesian(p1);
  //coords.add(dc0);
  densify(GeodeticCoord.toCartesian(p0), GeodeticCoord.toCartesian(p1), maxSegLenRad, coords);
  coords.add(dc1);

  // convert back to geo
  Coordinate[] dcPts = coords.toCoordinateArray();
  for (int i = 0; i < dcPts.length; i++) {
    dcPts[i] = GeodeticCoord.toGeodetic(dcPts[i]);
  }
  return line.getFactory().createLineString(dcPts);
}
项目:jeql    文件:PlacemarkParser.java   
private Coordinate[] parseCoordinates(String coordStr, boolean closeRing) {
  StreamTokenizer st = new StreamTokenizer(new StringReader(coordStr));
  st.parseNumbers();

  CoordinateList coordinates = new CoordinateList();
  try {
    coordinates.add(parseCoordinate(st));
    while (hasMoreTokens(st)) {
      coordinates.add(parseCoordinate(st));
    }
  } catch (IOException ex) {
    // should never happen - throw illegal state exception
    throw new IllegalStateException(
        "IOException during coordinate string parsing");
  }
  // close ring if required
  if (closeRing) 
    coordinates.closeRing();

  return coordinates.toCoordinateArray();
  /*
   * System.out.println(coordStr); // TODO: parse it! return new Coordinate[] {
   * new Coordinate(),new Coordinate(),new Coordinate(),new Coordinate() };
   */
}
项目:terraingis    文件:EdgeString.java   
private Coordinate[] getCoordinates() {
  if (coordinates == null) {
    int forwardDirectedEdges = 0;
    int reverseDirectedEdges = 0;
    CoordinateList coordinateList = new CoordinateList();
    for (Iterator i = directedEdges.iterator(); i.hasNext();) {
      LineMergeDirectedEdge directedEdge = (LineMergeDirectedEdge) i.next();
      if (directedEdge.getEdgeDirection()) {
        forwardDirectedEdges++;
      }
      else {
        reverseDirectedEdges++;
      }
      coordinateList.add(((LineMergeEdge) directedEdge.getEdge()).getLine()
                          .getCoordinates(), false,
        directedEdge.getEdgeDirection());
    }
    coordinates = coordinateList.toCoordinateArray();
    if (reverseDirectedEdges > forwardDirectedEdges) {
      CoordinateArrays.reverse(coordinates);
    }
  }

  return coordinates;
}
项目:Earth    文件:EdgeRing.java   
/**
 * 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 (this.ringPts == null) {
        CoordinateList coordList = new CoordinateList();
        for (Object aDeList : deList) {
            DirectedEdge de = (DirectedEdge) aDeList;
            PolygonizeEdge edge = (PolygonizeEdge) de.getEdge();
            addEdge(edge.getLine().getCoordinates(), de.getEdgeDirection(), coordList);
        }
        this.ringPts = coordList.toCoordinateArray();
    }
    return this.ringPts;
}
项目:Earth    文件:EdgeRing.java   
private static void addEdge(Coordinate[] coords, boolean isForward, CoordinateList coordList) {
    if (isForward) {
        for (Coordinate coord : coords) {
            coordList.add(coord, false);
        }
    } else {
        for (int i = coords.length - 1; i >= 0; i--) {
            coordList.add(coords[i], false);
        }
    }
}
项目:Earth    文件:LineStringSnapper.java   
/**
 * Snaps the vertices and segments of the source LineString
 * to the given set of snap vertices.
 *
 * @param snapPts the vertices to snap to
 * @return a list of the snapped points
 */
public Coordinate[] snapTo(Coordinate[] snapPts) {
    CoordinateList coordList = new CoordinateList(this.srcPts);

    this.snapVertices(coordList, snapPts);
    this.snapSegments(coordList, snapPts);

    Coordinate[] newPts = coordList.toCoordinateArray();
    return newPts;
}
项目:Earth    文件:LineStringSnapper.java   
/**
 * Snap segments of the source to nearby snap vertices.
 * Source segments are "cracked" at a snap vertex.
 * A single input segment may be snapped several times
 * to different snap vertices.
 * <p>
 * For each distinct snap vertex, at most one source segment
 * is snapped to.  This prevents "cracking" multiple segments
 * at the same point, which would likely cause
 * topology collapse when being used on polygonal linework.
 *
 * @param srcCoords the coordinates of the source linestring to be snapped
 * @param snapPts the target snap vertices
 */
private void snapSegments(CoordinateList srcCoords, Coordinate[] snapPts) {
    // guard against empty input
    if (snapPts.length == 0) {
        return;
    }

    int distinctPtCount = snapPts.length;

    // check for duplicate snap pts when they are sourced from a linear ring.
    // TODO: Need to do this better - need to check *all* snap points for dups (using a Set?)
    if (snapPts[0].equals2D(snapPts[snapPts.length - 1])) {
        distinctPtCount = snapPts.length - 1;
    }

    for (int i = 0; i < distinctPtCount; i++) {
        Coordinate snapPt = snapPts[i];
        int index = this.findSegmentIndexToSnap(snapPt, srcCoords);
        /**
         * If a segment to snap to was found, "crack" it at the snap pt.
         * The new pt is inserted immediately into the src segment list,
         * so that subsequent snapping will take place on the modified segments.
         * Duplicate points are not added.
         */
        if (index >= 0) {
            srcCoords.add(index + 1, new Coordinate(snapPt), false);
        }
    }
}
项目:Earth    文件:LineStringSnapper.java   
/**
 * Finds a src segment which snaps to (is close to) the given snap point.
 * <p>
 * Only a single segment is selected for snapping.
 * This prevents multiple segments snapping to the same snap vertex,
 * which would almost certainly cause invalid geometry
 * to be created.
 * (The heuristic approach to snapping used here
 * is really only appropriate when
 * snap pts snap to a unique spot on the src geometry.)
 * <p>
 * Also, if the snap vertex occurs as a vertex in the src coordinate list,
 * no snapping is performed.
 *
 * @param snapPt the point to snap to
 * @param srcCoords the source segment coordinates
 * @return the index of the snapped segment
 * or -1 if no segment snaps to the snap point
 */
private int findSegmentIndexToSnap(Coordinate snapPt, CoordinateList srcCoords) {
    double minDist = Double.MAX_VALUE;
    int snapIndex = -1;
    for (int i = 0; i < srcCoords.size() - 1; i++) {
        this.seg.p0 = (Coordinate) srcCoords.get(i);
        this.seg.p1 = (Coordinate) srcCoords.get(i + 1);

        /**
         * Check if the snap pt is equal to one of the segment endpoints.
         *
         * If the snap pt is already in the src list, don't snap at all.
         */
        if (this.seg.p0.equals2D(snapPt) || this.seg.p1.equals2D(snapPt)) {
            if (this.allowSnappingToSourceVertices) {
                continue;
            } else {
                return -1;
            }
        }

        double dist = this.seg.distance(snapPt);
        if (dist < this.snapTolerance && dist < minDist) {
            minDist = dist;
            snapIndex = i;
        }
    }
    return snapIndex;
}
项目:Earth    文件:BufferInputLineSimplifier.java   
private Coordinate[] collapseLine() {
        CoordinateList coordList = new CoordinateList();
        for (int i = 0; i < this.inputLine.length; i++) {
            if (this.isDeleted[i] != DELETE) {
                coordList.add(this.inputLine[i]);
            }
        }
//    if (coordList.size() < inputLine.length)      System.out.println("Simplified " + (inputLine.length - coordList.size()) + " pts");
        return coordList.toCoordinateArray();
    }
项目:Earth    文件:DouglasPeuckerLineSimplifier.java   
public Coordinate[] simplify() {
    this.usePt = new boolean[this.pts.length];
    for (int i = 0; i < this.pts.length; i++) {
        this.usePt[i] = true;
    }
    this.simplifySection(0, this.pts.length - 1);
    CoordinateList coordList = new CoordinateList();
    for (int i = 0; i < this.pts.length; i++) {
        if (this.usePt[i]) {
            coordList.add(new Coordinate(this.pts[i]));
        }
    }
    return coordList.toCoordinateArray();
}
项目:Earth    文件:QuadEdgeSubdivision.java   
/**
     * Gets the Voronoi cell around a site specified
     * by the origin of a QuadEdge.
     * <p>
     * The userData of the polygon is set to be the {@link Coordinate}
     * of the site.  This allows attaching external
     * data associated with the site to this cell polygon.
     *
     * @param qe a quadedge originating at the cell site
     * @param geomFact a factory for building the polygon
     * @return a polygon indicating the cell extent
     */
    public Polygon getVoronoiCellPolygon(QuadEdge qe, GeometryFactory geomFact) {
        List cellPts = new ArrayList();
        QuadEdge startQE = qe;
        do {
//      Coordinate cc = circumcentre(qe);
            // use previously computed circumcentre
            Coordinate cc = qe.rot().orig().getCoordinate();
            cellPts.add(cc);

            // move to next triangle CW around vertex
            qe = qe.oPrev();
        } while (qe != startQE);

        CoordinateList coordList = new CoordinateList();
        coordList.addAll(cellPts, false);
        coordList.closeRing();

        if (coordList.size() < 4) {
            System.out.println(coordList);
            coordList.add(coordList.get(coordList.size() - 1), true);
        }

        Coordinate[] pts = coordList.toCoordinateArray();
        Polygon cellPoly = geomFact.createPolygon(geomFact.createLinearRing(pts), null);

        Vertex v = startQE.orig();
        cellPoly.setUserData(v.getCoordinate());
        return cellPoly;
    }
项目:Earth    文件:DelaunayTriangulationBuilder.java   
/**
 * Extracts the unique {@link Coordinate}s from the given {@link Geometry}.
 *
 * @param geom the geometry to extract from
 * @return a List of the unique Coordinates
 */
public static CoordinateList extractUniqueCoordinates(Geometry geom) {
    if (geom == null) {
        return new CoordinateList();
    }

    Coordinate[] coords = geom.getCoordinates();
    return unique(coords);
}
项目:Earth    文件:ConvexHull.java   
private Coordinate[] computeOctRing(Coordinate[] inputPts) {
    Coordinate[] octPts = this.computeOctPts(inputPts);
    CoordinateList coordList = new CoordinateList();
    coordList.add(octPts, false);

    // points must all lie in a line
    if (coordList.size() < 3) {
        return null;
    }
    coordList.closeRing();
    return coordList.toCoordinateArray();
}
项目:Earth    文件:LinearGeometryBuilder.java   
/**
 * Adds a point to the current line.
 *
 * @param pt the Coordinate to add
 */
public void add(Coordinate pt, boolean allowRepeatedPoints) {
    if (this.coordList == null) {
        this.coordList = new CoordinateList();
    }
    this.coordList.add(pt, allowRepeatedPoints);
    this.lastPt = pt;
}
项目:jts    文件:LineStringSnapper.java   
/**
 * Snaps the vertices and segments of the source LineString
 * to the given set of snap vertices.
 *
 * @param snapPts the vertices to snap to
 * @return a list of the snapped points
 */
public Coordinate[] snapTo(Coordinate[] snapPts) {
    CoordinateList coordList = new CoordinateList(srcPts);

    snapVertices(coordList, snapPts);
    snapSegments(coordList, snapPts);

    Coordinate[] newPts = coordList.toCoordinateArray();
    return newPts;
}
项目:jts    文件:LineStringSnapper.java   
/**
 * Finds a src segment which snaps to (is close to) the given snap point.
 * <p/>
 * Only a single segment is selected for snapping.
 * This prevents multiple segments snapping to the same snap vertex,
 * which would almost certainly cause invalid geometry
 * to be created.
 * (The heuristic approach to snapping used here
 * is really only appropriate when
 * snap pts snap to a unique spot on the src geometry.)
 * <p/>
 * Also, if the snap vertex occurs as a vertex in the src coordinate list,
 * no snapping is performed.
 *
 * @param snapPt    the point to snap to
 * @param srcCoords the source segment coordinates
 * @return the index of the snapped segment
 * or -1 if no segment snaps to the snap point
 */
private int findSegmentIndexToSnap(Coordinate snapPt, CoordinateList srcCoords) {
    double minDist = Double.MAX_VALUE;
    int snapIndex = -1;
    for (int i = 0; i < srcCoords.size() - 1; i++) {
        seg.p0 = (Coordinate) srcCoords.get(i);
        seg.p1 = (Coordinate) srcCoords.get(i + 1);

        /**
         * Check if the snap pt is equal to one of the segment endpoints.
         *
         * If the snap pt is already in the src list, don't snap at all.
         */
        if (seg.p0.equals2D(snapPt) || seg.p1.equals2D(snapPt)) {
            if (allowSnappingToSourceVertices)
                continue;
            else
                return -1;
        }

        double dist = seg.distance(snapPt);
        if (dist < snapTolerance && dist < minDist) {
            minDist = dist;
            snapIndex = i;
        }
    }
    return snapIndex;
}
项目:jts    文件:BufferInputLineSimplifier.java   
private Coordinate[] collapseLine() {
        CoordinateList coordList = new CoordinateList();
        for (int i = 0; i < inputLine.length; i++) {
            if (isDeleted[i] != DELETE)
                coordList.add(inputLine[i]);
        }
//    if (coordList.size() < inputLine.length)      System.out.println("Simplified " + (inputLine.length - coordList.size()) + " pts");
        return coordList.toCoordinateArray();
    }
项目:jts    文件:DouglasPeuckerLineSimplifier.java   
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();
}
项目:jts    文件:VWLineSimplifier.java   
public Coordinate[] getCoordinates() {
    CoordinateList coords = new CoordinateList();
    VWLineSimplifier.VWVertex curr = this;
    do {
        coords.add(curr.pt, false);
        curr = curr.next;
    } while (curr != null);
    return coords.toCoordinateArray();
}
项目:hortonmachine    文件:GeometryTranslator.java   
/**
 * Builds a polygon feature from a dwg solid.
 * 
 */
public SimpleFeature convertDwgSolid( String typeName, String layerName, DwgSolid solid, int id ) {
    double[] p1 = solid.getCorner1();
    double[] p2 = solid.getCorner2();
    double[] p3 = solid.getCorner3();
    double[] p4 = solid.getCorner4();
    Point2D[] ptos = new Point2D[]{new Point2D.Double(p1[0], p1[1]),
            new Point2D.Double(p2[0], p2[1]), new Point2D.Double(p3[0], p3[1]),
            new Point2D.Double(p4[0], p4[1])};
    CoordinateList coordList = new CoordinateList();
    for( int j = 0; j < ptos.length; j++ ) {
        Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY());
        coordList.add(coord);
    }
    coordList.closeRing();

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, Polygon.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    LinearRing linearRing = gF.createLinearRing(coordList.toCoordinateArray());
    Geometry polygon = gF.createPolygon(linearRing, null);
    Object[] values = new Object[]{polygon, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
项目:hortonmachine    文件:GeometryTranslator.java   
/**
 * Builds a line feature from a dwg arc.
 */
public SimpleFeature convertDwgArc( String typeName, String layerName, DwgArc arc, int id ) {
    double[] c = arc.getCenter();
    Point2D center = new Point2D.Double(c[0], c[1]);
    double radius = (arc).getRadius();
    double initAngle = Math.toDegrees((arc).getInitAngle());
    double endAngle = Math.toDegrees((arc).getEndAngle());
    Point2D[] ptos = GisModelCurveCalculator.calculateGisModelArc(center, radius, initAngle,
            endAngle);
    CoordinateList coordList = new CoordinateList();
    for( int j = 0; j < ptos.length; j++ ) {
        Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
        coordList.add(coord);
    }

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, LineString.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
    Object[] values = new Object[]{lineString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
项目:jeql    文件:GeomFunction.java   
public static Geometry lineConnect(Geometry geom)
{
  CoordinateList pts = new CoordinateList();
  pts.add(geom.getCoordinates(), true);
  return geom.getFactory().createLineString(
        CoordinateArrays.toCoordinateArray(pts));
}
项目:jeql    文件:GeomFunction.java   
static Coordinate[] connectPts(Geometry geom, boolean close)
{
  CoordinateList pts = new CoordinateList();
  pts.add(geom.getCoordinates(), true);
  if (close) pts.closeRing();
  return CoordinateArrays.toCoordinateArray(pts);
}
项目:jeql    文件:GeomFunction.java   
public static Geometry lineConnectNoRepeated(Geometry geom)
{
  CoordinateList pts = new CoordinateList();
  pts.add(geom.getCoordinates(), false);
  return geom.getFactory().createLineString(
        CoordinateArrays.toCoordinateArray(pts));
}
项目:jeql    文件:VoronoiCommand.java   
private List extractCoordinates(RowIterator i, int geomIndex)
{
  CoordinateList coordList = new CoordinateList();
  while (true) {
    Row row = i.next();
    if (row == null)
      break;
    Geometry g = (Geometry) row.getValue(geomIndex);
    Coordinate[] pts = g.getCoordinates();
    coordList.add(pts, false);
  }
  return coordList;
}
项目:jeql    文件:MultiCoordinateList.java   
private CoordinateList current()
{
  if (currListIndex > coordLists.size() - 1) {
    CoordinateList cl = new CoordinateList();
    coordLists.add(cl);
  }
  return (CoordinateList) coordLists.get(currListIndex);
}
项目:jeql    文件:MultiCoordinateList.java   
public Coordinate[][] toCoordinateArrays()
{
  Coordinate[][] arrays = new Coordinate[coordLists.size()][];
  for (int i = 0; i < coordLists.size(); i++) {
    arrays[i] = ((CoordinateList) coordLists.get(i)).toCoordinateArray();
  }
  return arrays;
}
项目:jeql    文件:GeodeticDensifier.java   
private void densify(Coordinate dc0, Coordinate dc1, double maxSegLen, CoordinateList coords)
{
  Coordinate mid = GeodeticCoord.midPtDC(dc0, dc1);
  double dist = GeodeticCoord.distance3D(dc0, mid);
  if (dist < maxSegLen) {
    coords.add(dc0, false);
    coords.add(mid, false);
    return;
  }
  // else recursively densify
  densify(dc0, mid, maxSegLen, coords);
  densify(mid, dc1, maxSegLen, coords);
}