From d313b9d273b2974f1b27cf9a1f224d73dd857cb1 Mon Sep 17 00:00:00 2001 From: highsource Date: Thu, 2 Mar 2017 23:32:47 +0100 Subject: [PATCH] Initial commit --- .gitignore | 3 +++ 00-export-unfiltered-stops.bat | 1 + 01-filter-stops.bat | 7 ++++++ 01-filter-stops.sql | 28 ++++++++++++++++++++++ LICENSE | 25 ++++++++++++++++++++ README.md | 43 ++++++++++++++++++++++++++++++++++ index.js | 5 ++++ package.json | 10 ++++++++ 8 files changed, 122 insertions(+) create mode 100644 .gitignore create mode 100644 00-export-unfiltered-stops.bat create mode 100644 01-filter-stops.bat create mode 100644 01-filter-stops.sql create mode 100644 LICENSE create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3bd6749 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +stops.txt +unfiltered-stops.txt diff --git a/00-export-unfiltered-stops.bat b/00-export-unfiltered-stops.bat new file mode 100644 index 0000000..92d6572 --- /dev/null +++ b/00-export-unfiltered-stops.bat @@ -0,0 +1 @@ +node index.js > unfiltered-stops.txt \ No newline at end of file diff --git a/01-filter-stops.bat b/01-filter-stops.bat new file mode 100644 index 0000000..4970dba --- /dev/null +++ b/01-filter-stops.bat @@ -0,0 +1,7 @@ +psql^ + --username=postgres^ + --dbname VG^ + -f 01-filter-stops.sql^ + --set=stops_input="'%cd%\unfiltered-stops.txt'"^ + --set=stops_output="'%cd%\stops.txt'"^ + --set=selected_rs="'03251,03356,03361,03401,03403,03451,03458,03461,04011,04012'" \ No newline at end of file diff --git a/01-filter-stops.sql b/01-filter-stops.sql new file mode 100644 index 0000000..2f4f961 --- /dev/null +++ b/01-filter-stops.sql @@ -0,0 +1,28 @@ +CREATE TEMPORARY TABLE STOPS (stop_id varchar, stop_name varchar, stop_lon double precision, stop_lat double precision, stop_code varchar); + +COPY + STOPS +FROM + :stops_input + DELIMITER ',' + CSV + HEADER + QUOTE '"'; + +COPY ( + select + stops.* + from + stops, + vg250_krs, + regexp_split_to_table(:selected_rs, ',') as selected_rs + where + ST_contains(vg250_krs.geom, ST_SetSRID(ST_MakePoint(stops.stop_lon, stops.stop_lat), 4326)) and + vg250_krs.rs = selected_rs +) +TO + :stops_output +WITH + CSV + HEADER QUOTE '"' + FORCE QUOTE stop_id, stop_name, stop_code; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cd1cf16 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2017, Alexey Valikov +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ae26a87 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# vbn-stops + +This is a simple script to download all [VBN](https://www.vbn.de) stops as [GTFS-compatible CSV](https://developers.google.com/transit/gtfs/reference/stops-file). + +The script uses the following endpoint: + +``` +https://fahrplaner.vbn.de/hafas/query.exe/dny?performLocating=2&tpl=stop2json&look_stopclass=2147483647&look_minx={minx}&look_miny={miny}&look_maxx={maxx}&look_maxy={maxy} +``` + +It starts from bounding box `(5, 47, 15, 56)` and works down to smaller quadrants. + + +The script produces CSV output in the following format: + +``` +stop_id,stop_name,stop_lon,stop_lat,stop_code +"103204","Emden(Ostfriesl) B 210/Kolonie",7.211847,53.400005,"" +``` + +# Prerequisites + +These scrips use PostGIS to filter stops belonging to administrative regions covered by the transport company. +See [this project](https://github.com/highsource/postgis-verwaltungsgebiete) for a simple way to create a PostGIS database with administrative regions. + +# Usage + +## Windows + +``` +npm install +00-export-unfiltered-stops +01-filter-stops +``` + +# Disclaimer + +Usage of this script may or may not be legal, use on your own risk. +This repository provides only source code, no data. + +# License + +Source code is licensed under [BSD 2-clause license](LICENSE). No license and no guarantees implied on the produced data, produce and use on your own risk. \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..08462d3 --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +const exportStops = require("hafas-export-stops-by-coordinates"); + +const ENDPOINT_BASE_URL_TEMPLATE = "https://fahrplaner.vbn.de/hafas/query.exe/dny?performLocating=2&tpl=stop2json&look_stopclass=2147483647&look_minx={minx}&look_miny={miny}&look_maxx={maxx}&look_maxy={maxy}"; + +exportStops(ENDPOINT_BASE_URL_TEMPLATE, "UTF-8", 5, 47, 15, 56, null, [51, 54, 80, 81, 84, 85, 87, 88]); diff --git a/package.json b/package.json new file mode 100644 index 0000000..15b850a --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "name": "vbn-stops", + "version": "0.0.1", + "main": "index.js", + "files": ["index.js"], + "engines" : {"node": ">=6"}, + "dependencies": { + "hafas-export-stops-by-coordinates": "^0.3.0" + } +}