public LineString getStraightLineForStops(String trip_id) { CoordinateList coordinates = new CoordinateList(); LineString ls = null; Trip trip = trips.get(trip_id); Iterable<StopTime> stopTimes; stopTimes = getOrderedStopTimesForTrip(trip.trip_id); if (Iterables.size(stopTimes) > 1) { for (StopTime stopTime : stopTimes) { Stop stop = stops.get(stopTime.stop_id); Double lat = stop.stop_lat; Double lon = stop.stop_lon; coordinates.add(new Coordinate(lon, lat)); } ls = gf.createLineString(coordinates.toCoordinateArray()); } // set ls equal to null if there is only one stopTime to avoid an exception when creating linestring else{ ls = null; } return ls; }
/** * Construct a line string from CurveMembers coordinates. * * @param node * @return */ public static CoordinateList extractCurveMemberCoordinates(Node node) { List curveMembers = node.getChildren("curveMember"); CoordinateList clist = new CoordinateList(); for (int i = 0; i < curveMembers.size(); i++) { List curves = ((Node) curveMembers.get(i)).getChildren(MultiLineString.class); for (int j = 0; j < curves.size(); j++) { MultiLineString mls = (MultiLineString) ((Node) curves.get(j)).getValue(); clist.add(mls.getCoordinates(), false); } } return clist; } }
/** * Adds an array of coordinates to the list. * @param coord The coordinates * @param allowRepeated if set to false, repeated coordinates are collapsed * @return true (as by general collection contract) */ public boolean add(Coordinate[] coord, boolean allowRepeated) { add(coord, allowRepeated, true); return true; }
/** * Adds a coordinate to the list. * @param obj The coordinate to add * @param allowRepeated if set to false, repeated coordinates are collapsed * @return true (as by general collection contract) */ public boolean add(Object obj, boolean allowRepeated) { add((Coordinate) obj, allowRepeated); return true; }
private void addSegment(Coordinate p0, Coordinate p1) { coordList.add(p1); }
/** * Adds a section of an array of coordinates to the list. * @param coord The coordinates * @param allowRepeated if set to false, repeated coordinates are collapsed * @param start the index to start from * @param end the index to add up to but not including * @return true (as by general collection contract) */ public boolean add(Coordinate[] coord, boolean allowRepeated, int start, int end) { int inc = 1; if (start > end) inc = -1; for (int i = start; i != end; i += inc) { add(coord[i], allowRepeated); } return true; }
/** Add an array of coordinates * @param coll The coordinates * @param allowRepeated if set to false, repeated coordinates are collapsed * @return true (as by general collection contract) */ public boolean addAll(Collection<? extends Coordinate> coll, boolean allowRepeated) { boolean isChanged = false; for (Iterator<? extends Coordinate> i = coll.iterator(); i.hasNext(); ) { add(i.next(), allowRepeated); isChanged = true; } return isChanged; }
/** * Adds a point to the current line. * * @param pt the Coordinate to add */ public void add(Coordinate pt, boolean allowRepeatedPoints) { if (coordList == null) coordList = new CoordinateList(); coordList.add(pt, allowRepeatedPoints); lastPt = pt; }
/** * Constructs a new list from an array of Coordinates, allowing repeated points. * (I.e. this constructor produces a {@link CoordinateList} with exactly the same set of points * as the input array.) * * @param coord the initial coordinates */ public CoordinateList(Coordinate[] coord) { ensureCapacity(coord.length); add(coord, true); }
/** * Constructs a new list from an array of Coordinates, * allowing caller to specify if repeated points are to be removed. * * @param coord the array of coordinates to load into the list * @param allowRepeated if <code>false</code>, repeated points are removed */ public CoordinateList(Coordinate[] coord, boolean allowRepeated) { ensureCapacity(coord.length); add(coord, allowRepeated); }
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(); }
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(); } }
/** * Returns a deep copy of this <tt>CoordinateList</tt> instance. * * @return a clone of this <tt>CoordinateList</tt> instance */ public Object clone() { CoordinateList clone = (CoordinateList) super.clone(); for (int i = 0; i < this.size(); i++) { clone.add(i, (Coordinate) this.get(i).clone()); } return clone; } }
/** * Ensure this coordList is a ring, by adding the start point if necessary */ public void closeRing() { if (size() > 0) { Coordinate duplicate = get(0).copy(); add(duplicate, false); } }
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); } }
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(); }
private Coordinate[] computeOctRing(Coordinate[] inputPts) { Coordinate[] octPts = 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(); }
private Coordinate[] computeOctRing(Coordinate[] inputPts) { Coordinate[] octPts = 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(); }
static Coordinate[] round(CoordinateSequence seq, PrecisionModel pm) { if (seq.size() == 0) return new Coordinate[0]; CoordinateList coordList = new CoordinateList(); // copy coordinates and reduce for (int i = 0; i < seq.size(); i++) { Coordinate coord = new Coordinate( seq.getOrdinate(i, Coordinate.X), seq.getOrdinate(i, Coordinate.Y) ); pm.makePrecise(coord); coordList.add(coord, false); } Coordinate[] coord = coordList.toCoordinateArray(); //TODO: what if seq is too short? return coord; }