private void writeStopIntoSequence(Stop stop) throws IOException { if (preStop != null) { GHResponse resp = preStop.road(stop); if (shapePtSequence != -1) { PointList points = resp.getPoints(); for (GHPoint3D point : points) { shapePtLat = point.lat; shapePtLon = point.lon; writeShape(); shapePtSequence++; } } time = time.add(new TimeString(resp.getTime())).add(TimeString.seconds(30)); } else { if (shapesFile.get("shape_id").contains(shapeId())) { shapePtSequence = -1; } else { log.println("Writing shape: " + shapeId()); shapePtSequence = 0; } } stopId = stop.stopId(); writeStopTime(); preStop = stop; sequence++; }
private Stack<Stop> fetchStopSequence(String key) throws IOException { if (stopSequences.containsKey(key)) { return stopSequences.get(key); } Stack<Stop> stopSequence = new Stack<Stop>(); url = DBC.URL + '/' + DBC.GOOGLE_MAPS_EXTENSION + DBC.STOP_SEQUENCE_EXTENSION + routeShortName() + "&direction=" + direction.toChar(); Document doc = makeTmpJSoupDoc(url); Elements data = doc.getElementsByTag("data"); if (!data.isEmpty()) { Elements pois = data.get(0).getElementsByTag("poi"); for (Element poi : pois) { String address = poi.getElementsByTag("address").get(0).html() + ", " + poi.getElementsByTag("location").get(0).html(); double lat = Double.parseDouble(poi.getElementsByTag("lat").get(0).html()); double lon = Double.parseDouble(poi.getElementsByTag("lng").get(0).html()); int code = Integer.parseInt(poi.getElementsByTag("stopnumber").get(0).html()); Stop stop = new Stop(code, lat, lon, address, agency); if (!StopSiteCrawler.stopsFile.get("stop_code").contains(code)) { stop.write(); } stopSequence.push(stop); } } stopSequences.put(key, stopSequence); return stopSequence; }
@Override protected void writeStopSequence() throws IOException { log.println("Writing stop sequence: " + tripId()); time = new TimeString(0); preStop = null; sequence = 1; String key = routeId() + "_" + directionId(); Stack<Stop> stopSequence = fetchStopSequence(key); int i = 0; if (from != null) { while (i < stopSequence.size() && !Stop.overlap(stopSequence.get(i).getAddress(), from)) { i++; } } if (to == null) { for (; i < stopSequence.size(); i++) { boolean bypass = false; for (String stop : this.bypass) { if (Stop.overlap(stopSequence.get(i).getAddress(), stop)) { bypass = true; break; } } if (!bypass) { writeStopIntoSequence(stopSequence.get(i)); } } } else { for (; i < stopSequence.size(); i++) { boolean bypass = false; for (String stop : this.bypass) { if (Stop.overlap(stopSequence.get(i).getAddress(), stop)) { bypass = true; break; } } if (!bypass) { writeStopIntoSequence(stopSequence.get(i)); } if (Stop.overlap(stopSequence.get(i).getAddress(), to)) { break; } } } }