gtfs-parser 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/PKG-INFO +5 -2
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/gtfs_parser/parse.py +45 -26
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/pyproject.toml +2 -2
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/LICENSE +0 -0
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/README.md +0 -0
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/gtfs_parser/__init__.py +0 -0
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/gtfs_parser/__main__.py +0 -0
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/gtfs_parser/aggregate.py +0 -0
- {gtfs_parser-0.2.0 → gtfs_parser-0.2.2}/gtfs_parser/gtfs.py +0 -0
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gtfs_parser
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: parse and aggregate GTFS
|
|
5
5
|
Home-page: https://github.com/MIERUNE
|
|
6
6
|
License: MIT
|
|
7
7
|
Author: MIERUNE Inc.
|
|
8
|
-
Requires-Python:
|
|
8
|
+
Requires-Python: >=3.9.0
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
15
|
Requires-Dist: pandas (>=1.3.3)
|
|
13
16
|
Project-URL: Repository, https://github.com/MIERUNE/gtfs-parser
|
|
14
17
|
Description-Content-Type: text/markdown
|
|
@@ -14,13 +14,15 @@ def read_stops(gtfs: GTFS, ignore_no_route=False) -> list:
|
|
|
14
14
|
list: [description]
|
|
15
15
|
"""
|
|
16
16
|
# get unique list of route_id related to each stop
|
|
17
|
-
stop_trip_route_df =
|
|
18
|
-
gtfs.
|
|
17
|
+
stop_trip_route_df = pd.merge(
|
|
18
|
+
gtfs.stop_times[["trip_id", "stop_id"]],
|
|
19
|
+
gtfs.trips[["trip_id", "route_id"]],
|
|
19
20
|
on="trip_id",
|
|
20
21
|
)
|
|
21
22
|
stop_route_df = stop_trip_route_df[["stop_id", "route_id"]].drop_duplicates()
|
|
22
|
-
route_ids_on_stops =
|
|
23
|
-
|
|
23
|
+
route_ids_on_stops = (
|
|
24
|
+
stop_route_df.groupby("stop_id")["route_id"].apply(list).rename("route_ids")
|
|
25
|
+
)
|
|
24
26
|
# outer join route_ids to stop
|
|
25
27
|
route_stop = gtfs.stops.join(route_ids_on_stops, on="stop_id", how="left")
|
|
26
28
|
|
|
@@ -74,17 +76,24 @@ def read_routes(gtfs: GTFS, ignore_shapes=False) -> list:
|
|
|
74
76
|
|
|
75
77
|
def __read_route_shapes(gtfs):
|
|
76
78
|
# get_shapeids_on route
|
|
77
|
-
shape_ids_on_routes =
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
shape_ids_on_routes = (
|
|
80
|
+
gtfs.trips[["route_id", "shape_id"]]
|
|
81
|
+
.drop_duplicates()
|
|
82
|
+
.dropna(subset=["shape_id"])
|
|
83
|
+
.sort_values(["route_id", "shape_id"])
|
|
84
|
+
)
|
|
80
85
|
|
|
81
86
|
# get shape coordinate
|
|
82
87
|
shapes_df = gtfs.shapes.copy()
|
|
83
|
-
shapes_df["shape_pt"] = list(
|
|
88
|
+
shapes_df["shape_pt"] = list(
|
|
89
|
+
zip(shapes_df["shape_pt_lon"], shapes_df["shape_pt_lat"])
|
|
90
|
+
)
|
|
84
91
|
shapes_df = shapes_df.sort_values(["shape_id", "shape_pt_sequence"])
|
|
85
|
-
shape_lines =
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
shape_lines = (
|
|
93
|
+
shapes_df.groupby("shape_id")["shape_pt"]
|
|
94
|
+
.apply(lambda x: x.tolist())
|
|
95
|
+
.rename("line")
|
|
96
|
+
)
|
|
88
97
|
|
|
89
98
|
# merge
|
|
90
99
|
route_line_df = pd.merge(shape_ids_on_routes, shape_lines, on="shape_id")
|
|
@@ -98,11 +107,13 @@ def __read_route_shapes(gtfs):
|
|
|
98
107
|
]
|
|
99
108
|
if len(unloaded_shape_lines) > 0:
|
|
100
109
|
# fill id, name with shape_id, line to multiline
|
|
101
|
-
multiline_df = pd.DataFrame(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
110
|
+
multiline_df = pd.DataFrame(
|
|
111
|
+
{
|
|
112
|
+
"route_id": None,
|
|
113
|
+
"route_name": unloaded_shape_lines.index,
|
|
114
|
+
"multiline": unloaded_shape_lines.apply(lambda x: [x]),
|
|
115
|
+
}
|
|
116
|
+
)
|
|
106
117
|
|
|
107
118
|
unloaded_features = __route_multiline_df_to_features(multiline_df)
|
|
108
119
|
features.extend(unloaded_features)
|
|
@@ -112,15 +123,19 @@ def __read_route_shapes(gtfs):
|
|
|
112
123
|
def __read_routes_ignore_shapes(gtfs):
|
|
113
124
|
# generate stop patterns
|
|
114
125
|
sorted_stop_times = gtfs.stop_times.sort_values(["trip_id", "stop_sequence"])
|
|
115
|
-
trip_stop_pattern =
|
|
126
|
+
trip_stop_pattern = (
|
|
127
|
+
sorted_stop_times.groupby("trip_id")["stop_id"]
|
|
128
|
+
.agg(tuple)
|
|
129
|
+
.rename("stop_pattern")
|
|
130
|
+
)
|
|
116
131
|
|
|
117
132
|
# unique stop pattens by route_id
|
|
118
133
|
route_trip_stop_pattern = pd.merge(
|
|
119
|
-
trip_stop_pattern,
|
|
120
|
-
gtfs.trips[["trip_id", "route_id"]],
|
|
121
|
-
on='trip_id'
|
|
134
|
+
trip_stop_pattern, gtfs.trips[["trip_id", "route_id"]], on="trip_id"
|
|
122
135
|
)
|
|
123
|
-
route_stop_patterns = route_trip_stop_pattern[
|
|
136
|
+
route_stop_patterns = route_trip_stop_pattern[
|
|
137
|
+
["route_id", "stop_pattern"]
|
|
138
|
+
].drop_duplicates()
|
|
124
139
|
|
|
125
140
|
# explode stop patterns to stop ids
|
|
126
141
|
route_stop_patterns["stop_id"] = route_stop_patterns["stop_pattern"]
|
|
@@ -130,7 +145,7 @@ def __read_routes_ignore_shapes(gtfs):
|
|
|
130
145
|
stop_geoms = pd.Series(
|
|
131
146
|
data=zip(gtfs.stops["stop_lon"], gtfs.stops["stop_lat"]),
|
|
132
147
|
name="stop_pt",
|
|
133
|
-
index=gtfs.stops["stop_id"]
|
|
148
|
+
index=gtfs.stops["stop_id"],
|
|
134
149
|
)
|
|
135
150
|
|
|
136
151
|
# join geomtry to route stops
|
|
@@ -142,15 +157,19 @@ def __read_routes_ignore_shapes(gtfs):
|
|
|
142
157
|
).sort_values("order")
|
|
143
158
|
|
|
144
159
|
# Point -> LineString: group by route_id and stop_pattern
|
|
145
|
-
route_lines = route_stop_geoms.groupby(["route_id", "stop_pattern"])["stop_pt"].agg(
|
|
160
|
+
route_lines = route_stop_geoms.groupby(["route_id", "stop_pattern"])["stop_pt"].agg(
|
|
161
|
+
list
|
|
162
|
+
)
|
|
146
163
|
return __route_lines_to_features(route_lines, gtfs.routes)
|
|
147
164
|
|
|
148
165
|
|
|
149
166
|
def __route_lines_to_features(route_lines, routes):
|
|
150
167
|
# group by route_id into MultiLineString
|
|
151
|
-
multilines =
|
|
152
|
-
|
|
153
|
-
|
|
168
|
+
multilines = (
|
|
169
|
+
route_lines.groupby(["route_id"])
|
|
170
|
+
.apply(lambda x: x.tolist())
|
|
171
|
+
.rename("multiline")
|
|
172
|
+
)
|
|
154
173
|
# join route_id and route_name
|
|
155
174
|
multiline_df = pd.merge(
|
|
156
175
|
multilines,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "gtfs_parser"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "parse and aggregate GTFS"
|
|
5
5
|
authors = ["MIERUNE Inc.", "Kanahiro IGUCHI"]
|
|
6
6
|
license = "MIT"
|
|
@@ -10,7 +10,7 @@ readme = "README.md"
|
|
|
10
10
|
packages = [{include = "gtfs_parser"}]
|
|
11
11
|
|
|
12
12
|
[tool.poetry.dependencies]
|
|
13
|
-
python = "3.9
|
|
13
|
+
python = ">=3.9.0"
|
|
14
14
|
pandas = ">=1.3.3"
|
|
15
15
|
|
|
16
16
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|