/** * Latitude of the location where this instruction should take place. */ double getFirstLat() { return points.getLatitude(0); }
@Override public double getLat(int index) { return getLatitude(index); }
@Override public double getLatitude(int index) { if (index > getSize()) throw new ArrayIndexOutOfBoundsException(ERR_MSG + " index:" + index + ", size:" + getSize()); return wrappedPointList.getLatitude(fromOffset + index); }
@Override public double getLatitude(int nodeId) { if (isVirtualNode(nodeId)) return virtualNodes.getLatitude(nodeId - mainNodes); return mainNodeAccess.getLatitude(nodeId); }
@Override public int hashCode() { int hash = 5; for (int i = 0; i < getSize(); i++) { hash = 73 * hash + (int) Math.round(getLatitude(i) * 1000000); hash = 73 * hash + (int) Math.round(getLongitude(i) * 1000000); } hash = 73 * hash + this.getSize(); return hash; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < getSize(); i++) { if (i > 0) sb.append(", "); sb.append('('); sb.append(getLatitude(i)); sb.append(','); sb.append(getLongitude(i)); if (this.is3D()) { sb.append(','); sb.append(getElevation(i)); } sb.append(')'); } return sb.toString(); }
List<List<Double>> createList(PointList pl, List<Integer> integs) { List<List<Double>> list = new ArrayList<>(); for (int i : integs) { List<Double> entryList = new ArrayList<>(2); entryList.add(pl.getLatitude(i)); entryList.add(pl.getLongitude(i)); list.add(entryList); } return list; }
public GHPoint3D toGHPoint(int index) { return new GHPoint3D(getLatitude(index), getLongitude(index), getElevation(index)); }
public static String encodePolyline(PointList poly, boolean includeElevation, double precision) { StringBuilder sb = new StringBuilder(); int size = poly.getSize(); int prevLat = 0; int prevLon = 0; int prevEle = 0; for (int i = 0; i < size; i++) { int num = (int) Math.floor(poly.getLatitude(i) * precision); encodeNumber(sb, num - prevLat); prevLat = num; num = (int) Math.floor(poly.getLongitude(i) * precision); encodeNumber(sb, num - prevLon); prevLon = num; if (includeElevation) { num = (int) Math.floor(poly.getElevation(i) * 100); encodeNumber(sb, num - prevEle); prevEle = num; } } return sb.toString(); }
/** * Calculates the 2D bounding box of this route */ public BBox calcBBox2D() { check("calcRouteBBox"); BBox bounds = BBox.createInverse(false); for (int i = 0; i < pointList.getSize(); i++) { bounds.update(pointList.getLatitude(i), pointList.getLongitude(i)); } return bounds; }
public void add(PointList points) { ensureMutability(); int newSize = size + points.getSize(); incCap(newSize); for (int i = 0; i < points.getSize(); i++) { int tmp = size + i; latitudes[tmp] = points.getLatitude(i); longitudes[tmp] = points.getLongitude(i); if (is3D) elevations[tmp] = points.getElevation(i); } size = newSize; }
/** * This method fills the edgeIds hash with edgeIds found inside the specified geometry */ public void fillEdgeIDs(GHIntHashSet edgeIds, Geometry geometry, EdgeFilter filter) { if (geometry instanceof Point) { GHPoint point = GHPoint.create((Point) geometry); findClosestEdgeToPoint(edgeIds, point, filter); } else if (geometry instanceof LineString) { PointList pl = PointList.fromLineString((LineString) geometry); // TODO do map matching or routing int lastIdx = pl.size() - 1; if (pl.size() >= 2) { double meanLat = (pl.getLatitude(0) + pl.getLatitude(lastIdx)) / 2; double meanLon = (pl.getLongitude(0) + pl.getLongitude(lastIdx)) / 2; findClosestEdge(edgeIds, meanLat, meanLon, filter); } } else if (geometry instanceof MultiPoint) { for (Coordinate coordinate : geometry.getCoordinates()) { findClosestEdge(edgeIds, coordinate.y, coordinate.x, filter); } } }
/** * Clones this PointList. If this PointList was immutable, the cloned will be mutable. If this PointList was a * ShallowImmutablePointList, the cloned PointList will be a regular PointList. */ public PointList clone(boolean reverse) { PointList clonePL = new PointList(getSize(), is3D()); if (is3D()) for (int i = 0; i < getSize(); i++) { clonePL.add(getLatitude(i), getLongitude(i), getElevation(i)); } else for (int i = 0; i < getSize(); i++) { clonePL.add(getLatitude(i), getLongitude(i)); } if (reverse) clonePL.reverse(); return clonePL; }
private PathLayer createPathLayer(PathWrapper response) { Style style = Style.builder() .fixed(true) .generalization(Style.GENERALIZATION_SMALL) .strokeColor(0x9900cc33) .strokeWidth(4 * getResources().getDisplayMetrics().density) .build(); PathLayer pathLayer = new PathLayer(mapView.map(), style); List<GeoPoint> geoPoints = new ArrayList<>(); PointList pointList = response.getPoints(); for (int i = 0; i < pointList.getSize(); i++) geoPoints.add(new GeoPoint(pointList.getLatitude(i), pointList.getLongitude(i))); pathLayer.setPoints(geoPoints); return pathLayer; }
static GHPoint getPointForOrientationCalculation(EdgeIteratorState edgeIteratorState, NodeAccess nodeAccess) { double tmpLat; double tmpLon; PointList tmpWayGeo = edgeIteratorState.fetchWayGeometry(3); if (tmpWayGeo.getSize() <= 2) { tmpLat = nodeAccess.getLatitude(edgeIteratorState.getAdjNode()); tmpLon = nodeAccess.getLongitude(edgeIteratorState.getAdjNode()); } else { tmpLat = tmpWayGeo.getLatitude(1); tmpLon = tmpWayGeo.getLongitude(1); } return new GHPoint(tmpLat, tmpLon); } }
public static void assertPList(PointList expected, PointList list) { assertEquals("size of point lists is not equal", expected.getSize(), list.getSize()); for (int i = 0; i < expected.getSize(); i++) { assertEquals(expected.getLatitude(i), list.getLatitude(i), 1e-4); assertEquals(expected.getLongitude(i), list.getLongitude(i), 1e-4); } }
@Override public boolean equals(Object obj) { if (obj == null) return false; PointList other = (PointList) obj; if (this.isEmpty() && other.isEmpty()) return true; if (this.getSize() != other.getSize() || this.is3D() != other.is3D()) return false; for (int i = 0; i < size(); i++) { if (!equalsEps(getLatitude(i), other.getLatitude(i))) return false; if (!equalsEps(getLongitude(i), other.getLongitude(i))) return false; if (this.is3D() && !equalsEps(getElevation(i), other.getElevation(i))) return false; } return true; }
public LineString toLineString(boolean includeElevation) { GeometryFactory gf = new GeometryFactory(); Coordinate[] coordinates = new Coordinate[getSize() == 1 ? 2 : getSize()]; for (int i = 0; i < getSize(); i++) { coordinates[i] = includeElevation ? new Coordinate( round6(getLongitude(i)), round6(getLatitude(i)), round2(getElevation(i))) : new Coordinate( round6(getLongitude(i)), round6(getLatitude(i))); } // special case as just 1 point is not supported in the specification #1412 if (getSize() == 1) coordinates[1] = coordinates[0]; return gf.createLineString(coordinates); }
@Test public void testParse() { PointList pointList = new PointList(); pointList.parse2DJSON("[[11.571499218899739,49.945605917549265],[11.571664621792689,49.94570668665409]]"); assertEquals(49.945605917549265, pointList.getLatitude(0), 1e-6); assertEquals(11.571499218899739, pointList.getLongitude(0), 1e-6); assertEquals(49.94570668665409, pointList.getLatitude(1), 1e-6); assertEquals(11.571664621792689, pointList.getLongitude(1), 1e-6); }
private byte[] createWayGeometryBytes(PointList pillarNodes, boolean reverse) { int len = pillarNodes.getSize(); int dim = nodeAccess.getDimension(); int totalLen = len * dim * 4 + 4; byte[] bytes = new byte[totalLen]; bitUtil.fromInt(bytes, len, 0); if (reverse) pillarNodes.reverse(); int tmpOffset = 4; boolean is3D = nodeAccess.is3D(); for (int i = 0; i < len; i++) { double lat = pillarNodes.getLatitude(i); bitUtil.fromInt(bytes, Helper.degreeToInt(lat), tmpOffset); tmpOffset += 4; bitUtil.fromInt(bytes, Helper.degreeToInt(pillarNodes.getLongitude(i)), tmpOffset); tmpOffset += 4; if (is3D) { bitUtil.fromInt(bytes, Helper.eleToInt(pillarNodes.getElevation(i)), tmpOffset); tmpOffset += 4; } } return bytes; }