Skip to content

Commit

Permalink
Merge pull request #81 from takohei/update_gtfs_parser_interface
Browse files Browse the repository at this point in the history
Update gtfs parser interface
  • Loading branch information
Kanahiro authored May 8, 2024
2 parents e67d0db + 2d6b617 commit 8740cac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
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

0 comments on commit 8740cac

Please sign in to comment.