forked from CxAalto/gtfspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_filter.py
31 lines (24 loc) Β· 981 Bytes
/
example_filter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import datetime
import os
from example_import import load_or_import_example_gtfs
from gtfspy.gtfs import GTFS
from gtfspy.filter import FilterExtract
G = load_or_import_example_gtfs()
assert isinstance(G, GTFS)
filtered_database_path = "test_db_kuopio.week.sqlite"
# remove the old file, if exists
if os.path.exists(filtered_database_path):
os.remove(filtered_database_path)
# filter by time and 3 kilometers from the city center
week_start = G.get_weekly_extract_start_date()
week_end = week_start + datetime.timedelta(days=7)
fe = FilterExtract(G, filtered_database_path, start_date=week_start, end_date=week_end,
buffer_lat=62.8930796, buffer_lon=27.6671316, buffer_distance_km=3)
fe.create_filtered_copy()
assert (os.path.exists(filtered_database_path))
G = GTFS(filtered_database_path)
# visualize the routes of the filtered database
from gtfspy import mapviz
from matplotlib import pyplot as plt
mapviz.plot_route_network_from_gtfs(G)
plt.show()