@Override public EncodedPolylineBean marshal(LineString arg) throws Exception { if (arg == null) { return null; } Coordinate[] lineCoords = arg.getCoordinates(); List<Coordinate> coords = Arrays.asList(lineCoords); return PolylineEncoder.createEncodings(coords); }
/** * Equirectangular project a polyline. * @param lineString * @param cosLat cos(lat) of the projection center point. * @return The projected polyline. Coordinates in radians. */ private static LineString equirectangularProject(LineString lineString, double cosLat) { Coordinate[] coords = lineString.getCoordinates(); Coordinate[] coords2 = new Coordinate[coords.length]; for (int i = 0; i < coords.length; i++) { coords2[i] = new Coordinate(Math.toRadians(coords[i].x) * cosLat, Math.toRadians(coords[i].y)); } return GeometryUtils.getGeometryFactory().createLineString(coords2); }
if (lineString == null) return null; if (lineString.getCoordinates().length == 2) return STRAIGHT_LINE; double x0 = reverse ? xb : xa; double x1 = reverse ? xa : xb; double y1 = reverse ? ya : yb; Coordinate[] c = lineString.getCoordinates();
/** * Compute the (approximated) length of a polyline * @param lineString The polyline in (longitude, latitude degrees). * @return The (approximated) length, in meters, of the linestring. */ public static final double fastLength(LineString lineString) { // Warn: do not use LineString.getCentroid() as it is broken // for degenerated geometry (same first/last point). Coordinate[] coordinates = lineString.getCoordinates(); double middleY = (coordinates[0].y + coordinates[coordinates.length - 1].y) / 2.0; double cosLat = FastMath.cos(Math.toRadians(middleY)); return equirectangularProject(lineString, cosLat).getLength() * RADIUS_OF_EARTH_IN_M; }
private Ring toRing(Polygon polygon, HashMap<Coordinate, OSMNode> nodeMap) { List<OSMNode> shell = new ArrayList<OSMNode>(); for (Coordinate coord : polygon.getExteriorRing().getCoordinates()) { OSMNode node = nodeMap.get(coord); if (node == null) { throw new RingConstructionException(); } shell.add(node); } Ring ring = new Ring(shell, true); // now the holes for (int i = 0; i < polygon.getNumInteriorRing(); ++i) { LineString interior = polygon.getInteriorRingN(i); List<OSMNode> hole = new ArrayList<OSMNode>(); for (Coordinate coord : interior.getCoordinates()) { OSMNode node = nodeMap.get(coord); if (node == null) { throw new RingConstructionException(); } hole.add(node); } ring.holes.add(new Ring(hole, true)); } return ring; }
/** * Generate a {@link CoordinateArrayListSequence} based on an {@link Edge} array. * * @param edges The array of input edges * @return The coordinates of the points on the edges */ private static CoordinateArrayListSequence makeCoordinates(Edge[] edges) { CoordinateArrayListSequence coordinates = new CoordinateArrayListSequence(); for (Edge edge : edges) { LineString geometry = edge.getGeometry(); if (geometry != null) { if (coordinates.size() == 0) { coordinates.extend(geometry.getCoordinates()); } else { coordinates.extend(geometry.getCoordinates(), 1); // Avoid duplications } } } return coordinates; }
for (Coordinate coord : geom.getCoordinates()) {
coordinates.addAll(Arrays.asList(e.getGeometry().getCoordinates())); edgesForRoute.edgesForRoute.put(route, e);
org.geojson.Polygon p = new org.geojson.Polygon(); List<LngLatAlt> shell = new ArrayList<LngLatAlt>(); for (Coordinate c : polygons[i].getExteriorRing().getCoordinates()) { shell.add(new LngLatAlt(c.x, c.y));
if (geometry != null) { try { for (Coordinate c : geometry.getCoordinates()) { if (Double.isNaN(c.x)) { System.out.println("X DOOM");
public static EncodedPolylineBean createEncodings(Geometry geometry) { if (geometry instanceof LineString) { LineString string = (LineString) geometry; Coordinate[] coordinates = string.getCoordinates(); return createEncodings(new CoordinateList(coordinates)); } else if (geometry instanceof MultiLineString) { MultiLineString mls = (MultiLineString) geometry; return createEncodings(new CoordinateList(mls.getCoordinates())); } else { throw new IllegalArgumentException(geometry.toString()); } }
LinearRing ring = factory.createLinearRing(line.getCoordinates()); lrholelist.add(ring);
if (geometry != null) { if (coordinates.size() == 0) { coordinates.extend(geometry.getCoordinates()); } else { coordinates.extend(geometry.getCoordinates(), 1); // Avoid duplications
final double exteriorArea = CGAlgorithms.signedArea(exteriorRing.getCoordinates()); if(((int) Math.round(exteriorArea)) == 0) { continue; CoordinateArrays.reverse(exteriorRing.getCoordinates()); final double interiorArea = CGAlgorithms.signedArea(nextInteriorRing.getCoordinates()); if(((int)Math.round(interiorArea)) == 0) { continue; CoordinateArrays.reverse(nextInteriorRing.getCoordinates());
public final void insert(LineString geom, final Object item) { Coordinate[] coord = geom.getCoordinates(); final TLongSet keys = new TLongHashSet(coord.length * 8); for (int i = 0; i < coord.length - 1; i++) { // TODO Cut the segment if longer than bin size // to reduce the number of wrong bins Envelope env = new Envelope(coord[i], coord[i + 1]); visit(env, true, new BinVisitor<T>() { @Override public boolean visit(List<T> bin, long mapKey) { keys.add(mapKey); return false; } }); } keys.forEach(new TLongProcedure() { @SuppressWarnings("unchecked") @Override public boolean execute(long key) { // Note: bins have been initialized in the previous visit bins.get(key).add((T) item); nEntries++; return true; } }); nObjects++; }
private void drawEdgeFast(Edge e) { Coordinate[] coords = e.getGeometry().getCoordinates(); Coordinate c0 = coords[0]; Coordinate c1 = coords[coords.length - 1]; line((float) toScreenX(c0.x), (float) toScreenY(c0.y), (float) toScreenX(c1.x), (float) toScreenY(c1.y)); }
/** * Generates a geometry for the full pattern. * This is done by concatenating the shapes of all the constituent hops. * It could probably just come from the full shapes.txt entry for the trips in the route, but given all the details * in how the individual hop geometries are constructed we just recombine them here. */ public void makeGeometry() { CoordinateArrayListSequence coordinates = new CoordinateArrayListSequence(); if (patternHops != null && patternHops.length > 0) { for (int i = 0; i < patternHops.length; i++) { LineString geometry = patternHops[i].getGeometry(); if (geometry != null) { if (coordinates.size() == 0) { coordinates.extend(geometry.getCoordinates()); } else { coordinates.extend(geometry.getCoordinates(), 1); // Avoid duplicate coords at stops } } } // The CoordinateArrayListSequence is easy to append to, but is not serializable. // It might be possible to just mark it serializable, but it is not particularly compact either. // So we convert it to a packed coordinate sequence, since that is serializable and smaller. // FIXME It seems like we could simply accumulate the coordinates into an array instead of using the CoordinateArrayListSequence. PackedCoordinateSequence packedCoords = new PackedCoordinateSequence.Double(coordinates.toCoordinateArray(), 2); this.geometry = GeometryUtils.getGeometryFactory().createLineString(packedCoords); } }
private int drawEdge(Edge e) { if (e.getGeometry() == null) return 0; // do not attempt to draw geometry-less edges Coordinate[] coords = e.getGeometry().getCoordinates(); beginShape(); for (int i = 0; i < coords.length; i++) vertex((float) toScreenX(coords[i].x), (float) toScreenY(coords[i].y)); endShape(); return coords.length; // should be used to count segments, not edges drawn }
if (geometry != null) { if (coordinates.size() == 0) { coordinates.extend(geometry.getCoordinates()); } else { coordinates.extend(geometry.getCoordinates(), 1);
private LineString getSegmentGeometry(Graph graph, FeedScopedId shapeId, LocationIndexedLine locationIndexedLine, LinearLocation startIndex, LinearLocation endIndex, double startDistance, double endDistance, StopTime st0, StopTime st1) { ShapeSegmentKey key = new ShapeSegmentKey(shapeId, startDistance, endDistance); LineString geometry = geometriesByShapeSegmentKey.get(key); if (geometry == null) { geometry = (LineString) locationIndexedLine.extractLine(startIndex, endIndex); // Pack the resulting line string CoordinateSequence sequence = new PackedCoordinateSequence.Double(geometry .getCoordinates(), 2); geometry = _geometryFactory.createLineString(sequence); if (!isValid(geometry, st0.getStop(), st1.getStop())) { LOG.warn(graph.addBuilderAnnotation(new BogusShapeGeometryCaught(shapeId, st0, st1))); //fall back to trivial geometry geometry = createSimpleGeometry(st0.getStop(), st1.getStop()); } geometriesByShapeSegmentKey.put(key, (LineString) geometry); } return geometry; }