@Override public boolean hasNext() { return counter < getSize(); }
/** * This method returns the length of an Instruction. The length of an instruction is defined by [the * index of the first point of the next instruction] - [the index of the first point of this instruction]. * <p> * In general this will just resolve to the size of the PointList, except for {@link ViaInstruction} and * {@link FinishInstruction}, which are only virtual instructions, in a sense that they don't provide * a turn instruction, but only an info ("reached via point or destination"). * <p> * See #1216 and #1138 */ public int getLength() { return points.getSize(); }
@Override public int getNodes() { return virtualNodes.getSize() + mainNodes; }
public ShallowImmutablePointList(int fromOffset, int toOffset, PointList wrappedPointList) { if (fromOffset > toOffset) throw new IllegalArgumentException("from must be smaller or equal to end"); if (fromOffset < 0 || toOffset > wrappedPointList.getSize()) throw new IllegalArgumentException("Illegal interval: " + fromOffset + ", " + toOffset); this.fromOffset = fromOffset; this.toOffset = toOffset; this.wrappedPointList = wrappedPointList; }
@Override public GHPoint3D next() { if (counter >= getSize()) throw new NoSuchElementException(); GHPoint3D point = PointList.this.toGHPoint(counter); counter++; return point; }
@Override public PointList fetchWayGeometry(int mode) { if (pointList.getSize() == 0) return PointList.EMPTY; // due to API we need to create a new instance per call! if (mode == 3) return pointList.clone(false); else if (mode == 1) return pointList.copy(0, pointList.getSize() - 1); else if (mode == 2) return pointList.copy(1, pointList.getSize()); else if (mode == 0) { if (pointList.getSize() == 1) return PointList.EMPTY; return pointList.copy(1, pointList.getSize() - 1); } throw new UnsupportedOperationException("Illegal mode:" + mode); }
@Override public void next(EdgeIteratorState eb, int index, int prevEdgeId) { PointList pl = eb.fetchWayGeometry(2); for (int j = 0; j < pl.getSize(); j++) { points.add(pl, j); } }
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; }
@Override public String toString() { String str = "nodes:" + pointList.getSize() + "; " + pointList.toString(); if (instructions != null && !instructions.isEmpty()) str += ", " + instructions.toString(); if (hasErrors()) str += ", " + errors.toString(); return str; }
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); }
/** * 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; }
private void setWayGeometryAtGeoRef(PointList pillarNodes, long edgePointer, boolean reverse, long geoRef) { int len = pillarNodes.getSize(); int dim = nodeAccess.getDimension(); long geoRefPosition = (long) geoRef * 4; int totalLen = len * dim * 4 + 4; ensureGeometry(geoRefPosition, totalLen); byte[] wayGeometryBytes = createWayGeometryBytes(pillarNodes, reverse); wayGeometry.setBytes(geoRefPosition, wayGeometryBytes, wayGeometryBytes.length); edges.setInt(edgePointer + E_GEO, Helper.toSignedInt(geoRef)); }
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); } }
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); } }
@Test public void testBresenhamToLeft() { BresenhamLine.calcPoints( 47.57383, 9.61984, 47.57382, 9.61890, emitter, 47, 9, 0.00647, 0.00964); assertEquals(points.toString(), 1, points.getSize()); } }
@Test public void testPathSimplify() { PointList pointList = new PointList(); pointList.parse2DJSON(points1); assertEquals(32, pointList.getSize()); new DouglasPeucker().setMaxDistance(.5).simplify(pointList); // Arrays.asList(2, 4, 6, 7, 8, 9, 12, 14, 15, 17, 18, 19, 20, 22, 24, 27, 28, 29, 31, 33), assertEquals(20, pointList.getSize()); }
@Test public void testSimplifyCheckPointOrder() { PointList pointList = new PointList(); pointList.parse2DJSON(points2); assertEquals(13, pointList.getSize()); new DouglasPeucker().setMaxDistance(.5).simplify(pointList); assertEquals(11, pointList.getSize()); assertFalse(pointList.toString(), pointList.toString().contains("NaN")); assertEquals("(50.203764443183644,9.961074440801317), (50.20318963087774,9.960999562464645), (50.202952888673984,9.96094144793469), (50.20267889356641,9.96223002587773), (50.201853928011374,9.961859918278305), " + "(50.20138565901039,9.961668810881722), (50.20128507617008,9.96216874485095), (50.20088553877664,9.961953795595925), (50.200686794534775,9.961899033827313), (50.20014066696481,9.961716680863127), (50.199798499043254,9.961588158344957)", pointList.toString()); } }
public static String getNodeInfo(Graph g, int nodeId, EdgeFilter filter) { EdgeIterator iter = g.createEdgeExplorer(filter).setBaseNode(nodeId); NodeAccess na = g.getNodeAccess(); String str = nodeId + ":" + na.getLatitude(nodeId) + "," + na.getLongitude(nodeId) + "\n"; while (iter.next()) { str += " ->" + iter.getAdjNode() + " (" + iter.getDistance() + ") pillars:" + iter.fetchWayGeometry(0).getSize() + ", edgeId:" + iter.getEdge() + "\t" + BitUtil.BIG.toBitString(iter.getFlags(), 8) + "\n"; } return str; }