Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gtfs parser interface #81

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Smaller number of rules is prefered.

3. stop_name and distance

- unifying stops having same stop_name and near to each in certain extent - 0.01 degree in terms of lonlat-plane
- unifying stops having same stop_name and near to each in certain extent - 0.003 degree in terms of lonlat-plane
- new stop_id is the first stop's one in grouped stops ordered by stop_id ascending.

#### unifying result
Expand Down
15 changes: 9 additions & 6 deletions gtfs_go_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import tempfile
import urllib
import uuid
import csv

from PyQt5.QtCore import *
from PyQt5.QtGui import *
Expand Down Expand Up @@ -227,7 +228,7 @@ def execution(self):
"aggregated_csv": "",
}

gtfs = gtfs_parser.GTFS(feed_info["path"])
gtfs = gtfs_parser.GTFSFactory(feed_info["path"])

if self.ui.simpleCheckbox.isChecked():
routes_geojson = {
Expand Down Expand Up @@ -277,7 +278,7 @@ def execution(self):
"type": "FeatureCollection",
"features": aggregator.read_interpolated_stops(),
}

stop_relations = aggregator.read_stop_relations()
# write
written_files["aggregated_routes"] = os.path.join(
output_dir, "aggregated_routes.geojson"
Expand All @@ -301,12 +302,13 @@ def execution(self):
with open(
written_files["aggregated_csv"],
mode="w",
encoding="cp932",
encoding="utf-8",
errors="ignore",
newline='',
) as f:
aggregator.gtfs["stops"][
["stop_id", "stop_name", "similar_stop_id", "similar_stop_name"]
].to_csv(f, index=False)
writer = csv.DictWriter(f, fieldnames=stop_relations[0].keys())
writer.writeheader()
writer.writerows(stop_relations)

self.show_geojson(
feed_info["group"],
Expand Down Expand Up @@ -424,6 +426,7 @@ def show_geojson(
os.path.basename(aggregated_csv).split(".")[0],
"ogr",
)
aggregated_csv_vlayer.setProviderEncoding("UTF-8")

QgsProject.instance().addMapLayer(aggregated_csv_vlayer, False)
group.insertLayer(0, aggregated_csv_vlayer)
Expand Down