Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed Mar 2, 2017
0 parents commit d313b9d
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
stops.txt
unfiltered-stops.txt
1 change: 1 addition & 0 deletions 00-export-unfiltered-stops.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node index.js > unfiltered-stops.txt
7 changes: 7 additions & 0 deletions 01-filter-stops.bat
Original file line number Diff line number Diff line change
@@ -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'"
28 changes: 28 additions & 0 deletions 01-filter-stops.sql
Original file line number Diff line number Diff line change
@@ -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;
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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]);
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit d313b9d

Please sign in to comment.