6
6
import com .conveyal .gtfs .model .*;
7
7
import com .conveyal .gtfs .model .Calendar ;
8
8
import com .conveyal .gtfs .validator .Validator ;
9
- import com .conveyal .gtfs .stats .FeedStats ;
10
9
import com .conveyal .gtfs .validator .service .GeoUtils ;
11
10
import com .google .common .collect .*;
12
11
import com .google .common .eventbus .EventBus ;
13
12
import com .google .common .util .concurrent .ExecutionError ;
14
13
import com .vividsolutions .jts .algorithm .ConvexHull ;
15
14
import com .vividsolutions .jts .geom .*;
16
15
import com .vividsolutions .jts .index .strtree .STRtree ;
17
- import com .vividsolutions .jts .simplify .DouglasPeuckerSimplifier ;
18
16
import org .geotools .referencing .GeodeticCalculator ;
19
17
import org .mapdb .BTreeMap ;
20
- import org .mapdb .Bind ;
21
18
import org .mapdb .DB ;
22
19
import org .mapdb .DBMaker ;
23
20
import org .mapdb .Fun ;
33
30
import java .io .IOError ;
34
31
import java .io .IOException ;
35
32
import java .io .OutputStream ;
36
- import java .time .LocalDate ;
37
- import java .time .ZoneId ;
38
33
import java .time .format .DateTimeFormatter ;
39
- import java .time .temporal .ChronoUnit ;
40
34
import java .util .*;
41
- import java .util .concurrent .ConcurrentMap ;
42
35
import java .util .concurrent .ConcurrentNavigableMap ;
43
36
import java .util .concurrent .ExecutionException ;
44
37
import java .util .concurrent .TimeUnit ;
45
38
import java .util .stream .Collectors ;
46
- import java .util .stream .IntStream ;
47
39
import java .util .stream .StreamSupport ;
48
40
import java .util .zip .ZipEntry ;
49
41
import java .util .zip .ZipFile ;
@@ -86,13 +78,14 @@ public class GTFSFeed implements Cloneable, Closeable {
86
78
87
79
// public final ConcurrentMap<String, Long> stopCountByStopTime;
88
80
89
- /* Map from stop (stop_id) to stopTimes tuples (trip_id, stop_sequence) */
90
- public final NavigableSet <Tuple2 <String , Tuple2 >> stopStopTimeSet ;
91
- public final ConcurrentMap <String , Long > stopCountByStopTime ;
92
-
93
- public final NavigableSet <Tuple2 <String , String >> tripsPerService ;
94
-
95
- public final NavigableSet <Tuple2 <String , String >> servicesPerDate ;
81
+ // TODO: Remove these indexes from GTFSFeed.
82
+ // /* Map from stop (stop_id) to stopTimes tuples (trip_id, stop_sequence) */
83
+ // public final NavigableSet<Tuple2<String, Tuple2>> stopStopTimeSet;
84
+ // public final ConcurrentMap<String, Long> stopCountByStopTime;
85
+ //
86
+ // public final NavigableSet<Tuple2<String, String>> tripsPerService;
87
+ //
88
+ // public final NavigableSet<Tuple2<String, String>> servicesPerDate;
96
89
97
90
/* A fare is a fare_attribute and all fare_rules that reference that fare_attribute. */
98
91
public final Map <String , Fare > fares ;
@@ -196,29 +189,6 @@ else if (feedId == null || feedId.isEmpty()) {
196
189
for (GTFSError error : errors ) {
197
190
LOG .info ("{}" , error );
198
191
}
199
- LOG .info ("Building stop to stop times index" );
200
- Bind .histogram (stop_times , stopCountByStopTime , (key , stopTime ) -> stopTime .stop_id );
201
- Bind .secondaryKeys (stop_times , stopStopTimeSet , (key , stopTime ) -> new String [] {stopTime .stop_id });
202
- LOG .info ("Building trips per service index" );
203
- Bind .secondaryKeys (trips , tripsPerService , (key , trip ) -> new String [] {trip .service_id });
204
- LOG .info ("Building services per date index" );
205
- Bind .secondaryKeys (services , servicesPerDate , (key , service ) -> {
206
-
207
- LocalDate startDate = service .calendar != null
208
- ? service .calendar .start_date
209
- : service .calendar_dates .keySet ().stream ().sorted ().findFirst ().get ();
210
- LocalDate endDate = service .calendar != null
211
- ? service .calendar .end_date
212
- : service .calendar_dates .keySet ().stream ().sorted ().reduce ((first , second ) -> second ).get ();
213
- // end date for Period.between is not inclusive
214
- int daysOfService = (int ) ChronoUnit .DAYS .between (startDate , endDate .plus (1 , ChronoUnit .DAYS ));
215
- return IntStream .range (0 , daysOfService )
216
- .mapToObj (offset -> startDate .plusDays (offset ))
217
- .filter (service ::activeOn )
218
- .map (date -> date .format (dateFormatter ))
219
- .toArray (size -> new String [size ]);
220
- });
221
-
222
192
loaded = true ;
223
193
}
224
194
@@ -264,15 +234,7 @@ public void toFile (String file) {
264
234
throw new RuntimeException (e );
265
235
}
266
236
}
267
- // public void validate (EventBus eventBus, Validator... validators) {
268
- // if (eventBus == null) {
269
- //
270
- // }
271
- // for (Validator validator : validators) {
272
- // validator.getClass().getSimpleName();
273
- // validator.validate(this, false);
274
- // }
275
- // }
237
+
276
238
public void validate (boolean repair , Validator ... validators ) {
277
239
long startValidation = System .currentTimeMillis ();
278
240
for (Validator validator : validators ) {
@@ -298,11 +260,6 @@ public void validate () {
298
260
/////////////////
299
261
}
300
262
301
- public FeedStats calculateStats () {
302
- FeedStats feedStats = new FeedStats (this );
303
- return feedStats ;
304
- }
305
-
306
263
/**
307
264
* Static factory method returning a new instance of GTFSFeed containing the contents of
308
265
* the GTFS file at the supplied filesystem path.
@@ -604,87 +561,6 @@ public double getTripSpeed (String trip_id, boolean straightLine) {
604
561
return distance / time ; // meters per second
605
562
}
606
563
607
- /** Get list of stop_times for a given stop_id. */
608
- public List <StopTime > getStopTimesForStop (String stop_id ) {
609
- SortedSet <Tuple2 <String , Tuple2 >> index = this .stopStopTimeSet
610
- .subSet (new Tuple2 <>(stop_id , null ), new Tuple2 (stop_id , Fun .HI ));
611
-
612
- return index .stream ()
613
- .map (tuple -> this .stop_times .get (tuple .b ))
614
- .collect (Collectors .toList ());
615
- }
616
-
617
- public List <Trip > getTripsForService (String service_id ) {
618
- SortedSet <Tuple2 <String , String >> index = this .tripsPerService
619
- .subSet (new Tuple2 <>(service_id , null ), new Tuple2 (service_id , Fun .HI ));
620
-
621
- return index .stream ()
622
- .map (tuple -> this .trips .get (tuple .b ))
623
- .collect (Collectors .toList ());
624
- }
625
-
626
- /** Get list of services for each date of service. */
627
- public List <Service > getServicesForDate (LocalDate date ) {
628
- String dateString = date .format (dateFormatter );
629
- SortedSet <Tuple2 <String , String >> index = this .servicesPerDate
630
- .subSet (new Tuple2 <>(dateString , null ), new Tuple2 (dateString , Fun .HI ));
631
-
632
- return index .stream ()
633
- .map (tuple -> this .services .get (tuple .b ))
634
- .collect (Collectors .toList ());
635
- }
636
-
637
- public List <LocalDate > getDatesOfService () {
638
- return this .servicesPerDate .stream ()
639
- .map (tuple -> LocalDate .parse (tuple .a , dateFormatter ))
640
- .collect (Collectors .toList ());
641
- }
642
-
643
- /** Get list of distinct trips (filters out multiple visits by a trip) a given stop_id. */
644
- public List <Trip > getDistinctTripsForStop (String stop_id ) {
645
- return getStopTimesForStop (stop_id ).stream ()
646
- .map (stopTime -> this .trips .get (stopTime .trip_id ))
647
- .distinct ()
648
- .collect (Collectors .toList ());
649
- }
650
-
651
- /** Get the likely time zone for a stop using the agency of the first stop time encountered for the stop. */
652
- public ZoneId getAgencyTimeZoneForStop (String stop_id ) {
653
- StopTime stopTime = getStopTimesForStop (stop_id ).iterator ().next ();
654
-
655
- Trip trip = this .trips .get (stopTime .trip_id );
656
- Route route = this .routes .get (trip .route_id );
657
- Agency agency = route .agency_id != null ? this .agency .get (route .agency_id ) : this .agency .get (0 );
658
-
659
- return ZoneId .of (agency .agency_timezone );
660
- }
661
-
662
- // TODO: code review
663
- public Geometry getMergedBuffers () {
664
- if (this .mergedBuffers == null ) {
665
- // synchronized (this) {
666
- Collection <Geometry > polygons = new ArrayList <>();
667
- for (Stop stop : this .stops .values ()) {
668
- if (getStopTimesForStop (stop .stop_id ).isEmpty ()) {
669
- continue ;
670
- }
671
- if (stop .stop_lat > -1 && stop .stop_lat < 1 || stop .stop_lon > -1 && stop .stop_lon < 1 ) {
672
- continue ;
673
- }
674
- Point stopPoint = gf .createPoint (new Coordinate (stop .stop_lon , stop .stop_lat ));
675
- Polygon stopBuffer = (Polygon ) stopPoint .buffer (.01 );
676
- polygons .add (stopBuffer );
677
- }
678
- Geometry multiGeometry = gf .buildGeometry (polygons );
679
- this .mergedBuffers = multiGeometry .union ();
680
- if (polygons .size () > 100 ) {
681
- this .mergedBuffers = DouglasPeuckerSimplifier .simplify (this .mergedBuffers , .001 );
682
- }
683
- // }
684
- }
685
- return this .mergedBuffers ;
686
- }
687
-
688
564
public Polygon getConvexHull () {
689
565
if (this .convexHull == null ) {
690
566
synchronized (this ) {
@@ -788,11 +664,6 @@ private GTFSFeed (DB db) {
788
664
789
665
tripPatternMap = db .getTreeMap ("patternForTrip" );
790
666
791
- stopCountByStopTime = db .getTreeMap ("stopCountByStopTime" );
792
- stopStopTimeSet = db .getTreeSet ("stopStopTimeSet" );
793
- tripsPerService = db .getTreeSet ("tripsPerService" );
794
- servicesPerDate = db .getTreeSet ("servicesPerDate" );
795
-
796
667
errors = db .getTreeSet ("errors" );
797
668
}
798
669
}
0 commit comments