def test_get_shapes_intersecting_geometry(self): feed = cairns.copy() path = DATA_DIR/'cairns_square_stop_750070.geojson' polygon = sh_shape(json.load(path.open())['features'][0]['geometry']) pshapes = get_shapes_intersecting_geometry(feed, polygon) shape_ids = ['120N0005', '1200010', '1200001'] self.assertEqual(set(pshapes['shape_id'].unique()), set(shape_ids))
def test_get_stops_intersecting_polygon(self): feed = cairns.copy() with (DATA_DIR/'cairns_square_stop_750070.geojson').open() as src: polygon = sh_shape(json.load(src)['features'][0]['geometry']) pstops = get_stops_intersecting_polygon(feed, polygon) stop_ids = ['750070'] self.assertEqual(pstops['stop_id'].values, stop_ids)
def test_shapes_to_geojson(self): feed = cairns.copy() collection = shapes_to_geojson(feed) geometry_by_shape = build_geometry_by_shape(feed, use_utm=False) for f in collection['features']: shape = f['properties']['shape_id'] geom = sh_shape(f['geometry']) self.assertTrue(geom.equals(geometry_by_shape[shape]))
def test_get_shapes_geojson(self): feed = copy(cairns) collection = json.loads(feed.get_shapes_geojson()) geometry_by_shape = feed.get_geometry_by_shape(use_utm=False) for f in collection['features']: shape = f['properties']['shape_id'] geom = sh_shape(f['geometry']) self.assertTrue(geom.equals(geometry_by_shape[shape]))
def test_restrict_by_polygon(self): feed1 = cairns.copy() with (DATA_DIR/'cairns_square_stop_750070.geojson').open() as src: polygon = sh_shape(json.load(src)['features'][0]['geometry']) feed2 = restrict_by_polygon(feed1, polygon) # Should have correct routes rsns = ['120', '120N'] self.assertEqual(set(feed2.routes['route_short_name']), set(rsns)) # Should have correct trips route_ids = feed1.routes[feed1.routes['route_short_name'].isin( rsns)]['route_id'] trip_ids = feed1.trips[feed1.trips['route_id'].isin( route_ids)]['trip_id'] self.assertEqual(set(feed2.trips['trip_id']), set(trip_ids)) # Should have correct shapes shape_ids = feed1.trips[feed1.trips['trip_id'].isin( trip_ids)]['shape_id'] self.assertEqual(set(feed2.shapes['shape_id']), set(shape_ids)) # Should have correct stops stop_ids = feed1.stop_times[feed1.stop_times['trip_id'].isin( trip_ids)]['stop_id'] self.assertEqual(set(feed2.stop_times['stop_id']), set(stop_ids))
def test_compute_screen_line_counts(self): feed = cairns.copy() # Add distances to feed trip_stats = compute_trip_stats(feed, compute_dist_from_shapes=True) feed = append_dist_to_stop_times(feed, trip_stats) # Pick date date = get_first_week(feed)[0] # Load screen line with (DATA_DIR/'cairns_screen_line.geojson').open() as src: line = json.load(src) line = sh_shape(line['features'][0]['geometry']) f = compute_screen_line_counts(feed, line, date) # Should have correct columns expect_cols = set([ 'trip_id', 'route_id', 'route_short_name', 'crossing_time', 'orientation', ]) self.assertEqual(set(f.columns), expect_cols) # Should have correct routes rsns = ['120', '120N'] self.assertEqual(set(f['route_short_name']), set(rsns)) # Should have correct number of trips expect_num_trips = 34 self.assertEqual(f['trip_id'].nunique(), expect_num_trips) # Should have correct orientations for ori in [-1, 1]: self.assertEqual(f[f['orientation'] == 1].shape[0], expect_num_trips)