/** * Returns a trip geometry object (LineString) for a given trip id. * If the trip has a shape reference, this will be used for the geometry. * Otherwise, the ordered stoptimes will be used. * * @param trip_id trip id of desired trip geometry * @return the LineString representing the trip geometry. * @see LineString */ public LineString getTripGeometry(String trip_id){ CoordinateList coordinates = new CoordinateList(); LineString ls = null; Trip trip = trips.get(trip_id); // If trip has shape_id, use it to generate geometry. if (trip.shape_id != null) { Shape shape = getShape(trip.shape_id); if (shape != null) ls = shape.geometry; } // Use the ordered stoptimes. if (ls == null) { ls = getStraightLineForStops(trip_id); } return ls; }
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 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; }
public static CoordinateList unique(Coordinate[] coords) { Coordinate[] coordsCopy = CoordinateArrays.copyDeep(coords); Arrays.sort(coordsCopy); CoordinateList coordList = new CoordinateList(coordsCopy, false); return coordList; }
/** * If the coordinate array argument has repeated points, * constructs a new array containing no repeated points. * Otherwise, returns the argument. * @see #hasRepeatedPoints(Coordinate[]) */ public static Coordinate[] removeRepeatedPoints(Coordinate[] coord) { if (! hasRepeatedPoints(coord)) return coord; CoordinateList coordList = new CoordinateList(coord, false); 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(); } }
/** * 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); }
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(); }
/** * 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; }
/** * Extracts the coordinates which intersect an {@link Envelope}. * * @param coordinates the coordinates to scan * @param env the envelope to intersect with * @return an array of the coordinates which intersect the envelope */ public static Coordinate[] intersection(Coordinate[] coordinates, Envelope env) { CoordinateList coordList = new CoordinateList(); for (int i = 0; i < coordinates.length; i++) { if (env.intersects(coordinates[i])) coordList.add(coordinates[i], true); } return coordList.toCoordinateArray(); } }
/** * Computes the list of coordinates which are contained in this ring. * The coordinates 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; }
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; }
/** * 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(); }
private void checkIntersection(String[] inputWKT, String expectedWKT) { List input = readList(inputWKT); Geometry expected = read(expectedWKT); Coordinate[] pts = expected.getCoordinates(); CoordinateList intPtsExpected = new CoordinateList(pts); List segStrings = toSegmentStrings(input); List intPtsActual = FastNodingValidator.computeIntersections(segStrings); boolean isSameNumberOfIntersections = intPtsExpected.size() == intPtsActual.size(); assertTrue(isSameNumberOfIntersections); checkIntersections(intPtsActual, intPtsExpected); }
private void buildRing(HalfEdge eStartRing) { CoordinateList line = new CoordinateList(); HalfEdge e = eStartRing; line.add(e.orig().copy(), false); // scan along the path until a node is found (if one exists) while (e.sym().degree() == 2) { HalfEdge eNext = e.next(); // check if edges form a ring - if so, we're done if (eNext == eStartRing) break; // add point to line, and move to next edge line.add(eNext.orig().copy(), false); e = eNext; } // add final node line.add(e.dest().copy(), false); // store the scanned line addLine(line); }
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); }