The stops play an important role for many other queries. They can be taken from Didok (description) or from the station list (description).
Technical aspects
Using CKAN API enables you to initiate a simple search. Please note that you need to have an API key for this.
Sample query using the station list
Search for stops with Lausanne in the name:
- Find the resource ID for the current resource from the “bhlist” using CKAN API:
1 |
https://api.opentransportdata.swiss/ckan-api/package_show?id=bhlist |
- The resource with the ID “Station list” is used. The “id” will the be used in the second step.
123456789101112131415161718192021222324252627282930313233343536{// headers"resources": [// other resources{//..."package_id": "695c7af6-d486-4cde-9bf0-a92fdd581a4e",//..."id": "bb43413d-c89c-49e8-869f-5575e63db9bb",//..."name": {"fr": "Station list","de": "Station list","en": "Station list","it": "Station list"},"language": [],"rights": "","url": "https:\/\/opentransportdata.swiss\/dataset\/695c7af6-d486-4cde-9bf0-a92fdd581a4e\/resource\/bb43413d-c89c-49e8-869f-5575e63db9bb\/download\/bahnhof.csv","created": "2016-11-08T12:53:53.025251","modified": "","webstore_url": null,"last_modified": "2016-11-08T12:53:52.974681","position": 1,"revision_id": "ca65cd4a-dbc5-4948-89d2-73e7532a7401","identifier": "Station list","resource_type": null}]//...}}
Use the query “https://opentransportdata.swiss/api/action/datastore_search?resource_id=<resource-id>&q=<search_string>”
1https://api.opentransportdata.swiss/ckan-api/datastore_search?resource_id=bb43413d-c89c-49e8-869f-5575e63db9bb&q=Lausanne
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253{"help": "https:\/\/opentransportdata.swiss\/api\/3\/action\/help_show?name=datastore_search","success": true,"result": {"resource_id": "bb43413d-c89c-49e8-869f-5575e63db9bb","fields": [{"type": "int4","id": "_id"},{"type": "numeric","id": "StationID"},{"type": "text","id": "Station"},{"type": "int8","id": "_full_count"},{"type": "float4","id": "rank"}],"q": "Lausanne","records": [{"Station": "Lausanne$<1>$LS$<4>$Losanna$<4>$LS$<3>","StationID": "8501120","_id": 828,"_full_count": "211","rank": 0.0573088},// more records{"Station": "Lausanne-Ouchy$<1>$LSO$<3>","StationID": "8501075","_id": 789,"_full_count": "211","rank": 0.0573088}],"_links": {"start": "\/api\/action\/datastore_search?q=Lausanne&resource_id=bb43413d-c89c-49e8-869f-5575e63db9bb","next": "\/api\/action\/datastore_search?q=Lausanne&offset=100&resource_id=bb43413d-c89c-49e8-869f-5575e63db9bb"},"total": 211}}
Sample query using DiDok
We are looking for “Domodossola” using an SQL query.
- Identification of resource in “DiDok”:
1 |
https://api.opentransportdata.swiss/ckan-api/package_show?id=didok |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
{ //... "resources": [ { "url_type": "upload", "cache_last_updated": null, "issued": "2016-11-08T12:59:39.053524", "package_id": "f26dee75-1ed0-4c07-ac19-c98249e94bc5", "relations": "[]", "datastore_active": true, "id": "079e10fc-c212-4fc8-a75d-d02028f1539c", //... "identifier": "Didok.xlsx", //... } ] } |
- We will now search for Domodossola using the ID in the resource with the identifier “Didok.xlsx”.
1 |
https://api.opentransportdata.swiss/ckan-apin/datastore_search_sql?sql=SELECT * from "079e10fc-c212-4fc8-a75d-d02028f1539c" WHERE "Dst-Bezeichnung-offiziell" LIKE 'Domodossola' |
- The code which is currently valid for a resource must be inserted instead of “079e10fc-c212-4fc8-a75d-d02028f1539c”.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798{"help": "https:\/\/opentransportdata.swiss\/api\/3\/action\/help_show?name=datastore_search_sql","success": true,"result": {"records": [{"Dst-Bezeichung-offiziell": "Domodossola","GO-Nr": "11","GO-Abk": "FFS","VD": "","VPP": "*","KOORDY": "666.299999999999954525264911353588104248046875","KOORDX": "107.4500000000000028421709430404007434844970703125","Dst-Nr.": "1607","_full_text": "'1':6 '107.4500000000000028421709430404007434844970703125':8 '11':1 '1607':5 '270':3 '666.299999999999954525264911353588104248046875':9 '9998':7 'domodossola':10 'ffs':4","Dst-Abk": "DO","VPG": "","BP": "*","KZ": "1","_id": 6602,"Dst-Bezeichnung lang": "","Gde-Nr": "9998","KOORDZ": "270"}],"fields": [{"type": "int4","id": "_id"},{"type": "tsvector","id": "_full_text"},{"type": "numeric","id": "Dst-Nr."},{"type": "numeric","id": "KZ"},{"type": "text","id": "Dst-Bezeichung-offiziell"},{"type": "text","id": "Dst-Bezeichnung lang"},{"type": "text","id": "Dst-Abk"},{"type": "numeric","id": "GO-Nr"},{"type": "text","id": "GO-Abk"},{"type": "numeric","id": "Gde-Nr"},{"type": "text","id": "BP"},{"type": "text","id": "VPP"},{"type": "text","id": "VPG"},{"type": "text","id": "VD"},{"type": "numeric","id": "KOORDY"},{"type": "numeric","id": "KOORDX"},{"type": "numeric","id": "KOORDZ"}],"sql": "SELECT * from \"079e10fc-c212-4fc8-a75d-d02028f1539c\" WHERE \"Dst-Bezeichung-offiziell\" LIKE 'Domodossola'"}}More detailed information