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; } }
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(); }
/** * 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(); }
} 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));
public void visit(QuadEdge[] triEdges) { coordList.clear(); for (int i = 0; i < 3; i++) { Vertex v = triEdges[i].orig(); coordList.add(v.getCoordinate()); } if (coordList.size() > 0) { coordList.closeRing(); Coordinate[] pts = coordList.toCoordinateArray(); if (pts.length != 4) { //checkTriangleSize(pts); return; } triCoords.add(pts); } }
/** * 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; }
/** * 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; }
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); }
/** * 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); }
/** * Terminate the current LineString. */ public void endLine() { if (coordList == null) { return; } if (ignoreInvalidLines && coordList.size() < 2) { coordList = null; return; } Coordinate[] rawPts = coordList.toCoordinateArray(); Coordinate[] pts = rawPts; if (fixInvalidLines) pts = validCoordinateSequence(rawPts); coordList = null; LineString line = null; try { line = geomFact.createLineString(pts); } catch (IllegalArgumentException ex) { // exception is due to too few points in line. // only propagate if not ignoring short lines if (! ignoreInvalidLines) throw ex; } if (line != null) lines.add(line); }
/** * Adds a coordinate to the end of the list. * * @param coord The coordinates * @param allowRepeated if set to false, repeated coordinates are collapsed */ public void add(Coordinate coord, boolean allowRepeated) { // don't add duplicate coordinates if (! allowRepeated) { if (size() >= 1) { Coordinate last = (Coordinate) get(size() - 1); if (last.equals2D(coord)) return; } } super.add(coord); }
private Coordinate[] getBoundary(int level, Coordinate origin, double width) { double y = origin.y; // for all levels beyond 0 need to vertically shift shape by height of one "arm" to centre it if (level > 0) { y += THIRD_HEIGHT * width; } Coordinate p0 = new Coordinate(origin.x, y); Coordinate p1 = new Coordinate(origin.x + width/2, y + width * HEIGHT_FACTOR); Coordinate p2 = new Coordinate(origin.x + width, y); addSide(level, p0, p1); addSide(level, p1, p2); addSide(level, p2, p0); coordList.closeRing(); return coordList.toCoordinateArray(); }
/** * 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)); } } }
private void addLine(CoordinateList line) { lines.add(factory.createLineString(line.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(); }
/** * 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; }
/** * 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; }