private ShapePoint doMap(org.onebusaway.gtfs.model.ShapePoint rhs) { ShapePoint lhs = new ShapePoint(); lhs.setShapeId(AgencyAndIdMapper.mapAgencyAndId(rhs.getShapeId())); lhs.setSequence(rhs.getSequence()); lhs.setLat(rhs.getLat()); lhs.setLon(rhs.getLon()); lhs.setDistTraveled(rhs.getDistTraveled()); // Skip mapping of proxy // private transient StopTimeProxy proxy; if (rhs.getProxy() != null) { throw new IllegalStateException("Did not expect proxy to be set! Data: " + rhs); } return lhs; } }
private List<ShapePoint> deduplicateShapePoints(List<ShapePoint> shapePoints) { List<ShapePoint> deduplicated = new ArrayList<ShapePoint>(); ShapePoint prev = null; for (ShapePoint shapePoint : shapePoints) { if (prev == null || !(prev.getLat() == shapePoint.getLat() && prev.getLon() == shapePoint.getLon())) { deduplicated.add(shapePoint); } prev = shapePoint; } return deduplicated; } }
private List<ShapePoint> deduplicateShapePoints(List<ShapePoint> shapePoints) { List<ShapePoint> deduplicated = new ArrayList<ShapePoint>(); ShapePoint prev = null; for (ShapePoint shapePoint : shapePoints) { if (prev == null || !(prev.getLat() == shapePoint.getLat() && prev.getLon() == shapePoint.getLon())) { deduplicated.add(shapePoint); } prev = shapePoint; } return deduplicated; } }
private int closest(List<ShapePoint> shapePoints, ShapePoint point, int index) { int minIndex = -1; double minValue = Double.POSITIVE_INFINITY; for (int i = index; i < shapePoints.size(); i++) { ShapePoint p = shapePoints.get(i); double dy = p.getLat() - point.getLat(); double dx = p.getLon() - point.getLon(); double d = Math.sqrt(dy * dy + dx * dx); if (d < minValue) { minIndex = i; minValue = d; } } return minIndex; }
/**** * Private Methods ****/ private List<ShapePoint> deduplicateShapePoints(List<ShapePoint> shapePoints) { List<ShapePoint> deduplicated = new ArrayList<ShapePoint>(); ShapePoint prev = null; for (ShapePoint shapePoint : shapePoints) { if (prev == null || !(prev.getLat() == shapePoint.getLat() && prev.getLon() == shapePoint.getLon())) { deduplicated.add(shapePoint); } prev = shapePoint; } return deduplicated; } }
public static PathBean getShapePointsAsPathBean(List<ShapePoint> points) { double[] lat = new double[points.size()]; double[] lon = new double[points.size()]; int index = 0; for (ShapePoint point : points) { lat[index] = point.getLat(); lon[index] = point.getLon(); index++; } return new PathBean(lat, lon); } }
public static PathBean getShapePointsAsPathBean(List<ShapePoint> points) { double[] lat = new double[points.size()]; double[] lon = new double[points.size()]; int index = 0; for (ShapePoint point : points) { lat[index] = point.getLat(); lon[index] = point.getLon(); index++; } return new PathBean(lat, lon); } }
private List<ProjectedPoint> getShapePointsForShapeId( Map<AgencyAndId, List<ProjectedPoint>> shapePointCache, AgencyAndId shapeId) { List<ProjectedPoint> points = shapePointCache.get(shapeId); if (points == null) { List<ShapePoint> shapePoints = _dao.getShapePointsForShapeId(shapeId); Collections.sort(shapePoints); points = new ArrayList<ProjectedPoint>(); for (ShapePoint shapePoint : shapePoints) points.add(ProjectedPointFactory.forward(shapePoint.getLat(), shapePoint.getLon())); shapePointCache.put(shapeId, points); } return points; }
private int getClosestShapePointToStop(List<ShapePoint> points, Stop stop) { int minIndex = -1; double minDistance = Double.POSITIVE_INFINITY; for (int i = 0; i < points.size(); ++i) { ShapePoint point = points.get(i); double dx = point.getLon() - stop.getLon(); double dy = point.getLat() - stop.getLat(); double d = Math.sqrt(dx * dx + dy * dy); if (d < minDistance) { minIndex = i; minDistance = d; } } return minIndex; }
private int getClosestShapePointToStop(List<ShapePoint> points, Stop stop) { int minIndex = -1; double minDistance = Double.POSITIVE_INFINITY; for (int i = 0; i < points.size(); ++i) { ShapePoint point = points.get(i); double dx = point.getLon() - stop.getLon(); double dy = point.getLat() - stop.getLat(); double d = Math.sqrt(dx * dx + dy * dy); if (d < minDistance) { minIndex = i; minDistance = d; } } return minIndex; }
@Override public String toString() { return "<ShapePoint " + getShapeId() + " #" + getSequence() + " (" + getLat() + "," + getLon() + ")>"; }
@Override public String toString() { return "<ShapePoint " + getShapeId() + " #" + getSequence() + " (" + getLat() + "," + getLon() + ")>"; }
private LineString getLineStringForShapeId(AgencyAndId shapeId) { LineString geometry = _geometriesByShapeId.get(shapeId); if (geometry != null) return geometry; List<ShapePoint> points = _dao.getShapePointsForShapeId(shapeId); Coordinate[] coordinates = new Coordinate[points.size()]; double[] distances = new double[points.size()]; boolean hasAllDistances = true; int i = 0; for (ShapePoint point : points) { coordinates[i] = new Coordinate(point.getLon(), point.getLat()); distances[i] = point.getDistTraveled(); if (!point.isDistTraveledSet()) hasAllDistances = false; i++; } /** * If we don't have distances here, we can't calculate them ourselves because we can't * assume the units will match */ if (!hasAllDistances) { distances = null; } CoordinateSequence sequence = new PackedCoordinateSequence.Float(coordinates, 2); geometry = _factory.createLineString(sequence); _geometriesByShapeId.put(shapeId, geometry); _distancesByShapeId.put(shapeId, distances); return geometry; }
/**** * {@link List} Interface ****/ @Override public boolean add(ShapePoint shapePoint) { int index = size; size++; ensureCapacity(size); shapeIds[index] = shapePoint.getShapeId(); sequences[index] = shapePoint.getSequence(); lats[index] = shapePoint.getLat(); lons[index] = shapePoint.getLon(); distTraveled[index] = shapePoint.getDistTraveled(); return true; }
/**** * {@link List} Interface ****/ @Override public boolean add(ShapePoint shapePoint) { int index = size; size++; ensureCapacity(size); shapeIds[index] = shapePoint.getShapeId(); sequences[index] = shapePoint.getSequence(); lats[index] = shapePoint.getLat(); lons[index] = shapePoint.getLon(); distTraveled[index] = shapePoint.getDistTraveled(); return true; }
private ShapePoints getShapePointsForShapeIdNonCached(AgencyAndId shapeId) { List<ShapePoint> shapePoints = _gtfsDao.getShapePointsForShapeId(shapeId); shapePoints = deduplicateShapePoints(shapePoints); if (shapePoints.isEmpty()) return null; int n = shapePoints.size(); double[] lat = new double[n]; double[] lon = new double[n]; double[] distTraveled = new double[n]; int i = 0; for (ShapePoint shapePoint : shapePoints) { lat[i] = shapePoint.getLat(); lon[i] = shapePoint.getLon(); i++; } ShapePoints result = new ShapePoints(); result.setShapeId(shapeId); result.setLats(lat); result.setLons(lon); result.setDistTraveled(distTraveled); result.ensureDistTraveled(); return result; }
nsp.setShapeId(newShapeId); nsp.setSequence(newIndex++); nsp.setLat(sp.getLat()); nsp.setLon(sp.getLon());
private ShapePoints getShapePointsForShapeIdNonCached(AgencyAndId shapeId) { List<ShapePoint> shapePoints = _gtfsDao.getShapePointsForShapeId(shapeId); shapePoints = deduplicateShapePoints(shapePoints); if (shapePoints.isEmpty()) return null; int n = shapePoints.size(); double[] lat = new double[n]; double[] lon = new double[n]; double[] distTraveled = new double[n]; int i = 0; for (ShapePoint shapePoint : shapePoints) { lat[i] = shapePoint.getLat(); lon[i] = shapePoint.getLon(); i++; } ShapePoints result = new ShapePoints(); result.setShapeId(shapeId); result.setLats(lat); result.setLons(lon); result.setDistTraveled(distTraveled); result.ensureDistTraveled(); return result; }
@Cacheable public ShapePoints getShapePointsForShapeId(AgencyAndId shapeId) { List<ShapePoint> shapePoints = _gtfsDao.getShapePointsForShapeId(shapeId); shapePoints = deduplicateShapePoints(shapePoints); if (shapePoints.isEmpty()) return null; int n = shapePoints.size(); double[] lat = new double[n]; double[] lon = new double[n]; double[] distTraveled = new double[n]; int i = 0; for (ShapePoint shapePoint : shapePoints) { lat[i] = shapePoint.getLat(); lon[i] = shapePoint.getLon(); i++; } ShapePoints result = new ShapePoints(); result.setShapeId(shapeId); result.setLats(lat); result.setLons(lon); result.setDistTraveled(distTraveled); result.ensureDistTraveled(); return result; }