Med detta API kan du ladda ner filer med planerad kollektivtrafik i Sverige. Informationen som publiceras genom APIet kommer från Samtrafiken i Sverige AB. Samtrafiken har ansvar för att samla in information om planerad kollektivtrafik (tidtabeller) för all kollektivtrafik som bedrivs i Sverige. Detta samlas i ett gemensamt trafikinformationssystem kallat GTI. Uppdraget regleras i en föreskrift från Transportstyrelsen och är en konsekvens av den lagstiftning som trädde i kraft i början av 2012 för kollektivtrafik i Sverige.
Vad är GTFS?
GTFS står för General Transit Feed Specification och är en standard som är framtagen av Google, och för hjälp med formatet så hänvisar vi till deras dokumentation som du finner här.
Detta API innehåller filer enligt detta format.
I dagsläget har specifikationen inte stöd för multipla bytestider på ett stopställe. Detta gör att vi i GTFS-filerna endast har med en bytestid per stopställe, till skillnad från i till exempel ResRobot där det kan vara olika bytestider mellan olika operatörer eller linjer.
Metoder
- feed_info.txt
URL: https://api.trafiklab.se/samtrafiken/gtfs/feed_info.txt
Denna metod returnerar filen feed_info, som visar när sweden.zip senast uppdaterades. Använd denna för att inte ladda ner sweden.zip mer än nödvändigt.
Ingen nyckel krävs.
- sweden.zip
URL: https://api.trafiklab.se/samtrafiken/gtfs/sweden.zip?key=<apinyckel>
Se Innehåll och API-nyckel längre ner.
Innehåll
Sweden.zip innehåller ett antal filer som ingår i GTFS-formatet.
Flera delar i GTFS är inte obligatoriska och all information som omnäms i specifikationen finns inte med i Samtrafikens export (till exempel realtid och prisinformation).
Länkarna nedan går till Googles dokumentation.
| Fil | Beskrivning från Google |
| agency.txt | One or more transit agencies that provide the data in this feed. |
| stops.txt | Individual locations where vehicles pick up or drop off passengers. |
| routes.txt | Transit routes. A route is a group of trips that are displayed to riders as a single service. |
| trips.txt | Trips for each route. A trip is a sequence of two or more stops that occurs at specific time. |
| stop_times.txt | Times that a vehicle arrives at and departs from individual stops for each trip. |
| calendar.txt | Dates for service IDs using a weekly schedule. Specify when service starts and ends, as well as days of the week where service is available. |
| calendar_dates.txt | Exceptions for the service IDs defined in the calendar.txt file. If calendar_dates.txt includes ALL dates of service, this file may be specified instead of calendar.txt. |
| transfers.txt | Rules for making connections at transfer points between routes. |
| feed_info.txt (Även i separat API-metod) | Additional information about the feed itself, including publisher, version, and expiration information. |
Uppdateringar
Filen med all planerad information är förhållandevis stor (ca 40 Mb komprimerad) och kan kräva relativt stor kapacitet för att hantera. Det går därför att se när den version av sweden.zip som finns tillgänglig just nu, är skapad. Detta finns i filen feed_info.txt. Vi rekommenderar att du i dina tillämpningar kontrollerar om någon uppdatering skett och enbart laddar ner hela filen när den är uppdaterad. Filen uppdateras max en gång per dag, men oftast ungefär en gång i veckan.
API-Nyckel
Det krävs en giltig API-nyckel som skickas med som parametern "key" i sweden.zip-metodanropet. En API-nyckel får du genom att skapa ett projekt som använder detta API. Mer om hur du skapar och använder API nycklar hittar du här. För att få en API-nyckel så måste du godkänna de licensvillkor som finns för detta API.
Det finns vissa begränsningar på antalet anrop per minut och per månad. Se vidare under Uppdateringar för hur du minimerar ditt behov av att ladda ner hela filen.
| Nivå | Max anrop/månad | Max anrop/minut |
| Brons | 50 | 1 |
FAQ
Fråga 1: Alla olika fält i filerna är märkta med antingen Required eller Optional enligt Googles protokollspecifikation, men finns det några fält som Samtrafiken kräver inrapportering på som inte protokollet gör (dvs fält märkta Optional som man alltid kan räkna med innehåller information)?
Ja det finns flera fält som är markerade som optional men som alltid innehåller något data:
Agency.txt: agency_lang samt agency_id förstås eftersom vi alltid har flera trafikbolag.
Stops.txt: stop_url
Routes.txt: route_url
Fälten route_desc, route_color, route_text_color är alltid tomma i nuläget.
Trips.txt: trip_headsign - det fältet är i praktiken den sista hållplatsen på turen vilket i sällsynta fall inte överensstämmer med hur turen skyltas i trafiken.
Fälten direction_id, block_id, shape_id är alltid tomma i nuläget.
Stop_times.txt: Inga av optional fälten innehåller alltid data.
Fälten stop_headsign, shape_dist_traveled är alltid tomma i nuläget.
Calendar.txt: Allt är required
Calendar_dates.txt: Allt är required
Transfers.txt: Optional fältet min_transfer_time innehåller inte alltid data.
Fråga 2: Är det något av fälten i de angivna filerna som trafikbolagen inte har möjlighet att rapportera in även om de skulle vilja (dvs fält som man alltid kan räkna med att de INTE innehåller någon information)?
De fält som finns i våra filer idag (vilka de är framgår ifall du studerar rubrikerna i filerna) är de som kommer att gälla för överskådlig framtid. Inga nya fält tillkommer hux-flux även om något/några trafikbolag skulle ha data som passar in i något ytterligare fält. Orsaken till det är bland annat att filerna skapas utifrån data som har bearbetats och ”homogeniserats” först i våra interna trafiksystem på Samtrafiken.
Se för övrigt beskrivningen i fråga 1 på en del av fälten som alltid är tomma i nuläget.
Fråga 3: Hur sker tilldelningen av id:n (route_id, service_id, trip_id etc)? Har de någonting med att göra hur trafikbolagen själva id-sätter internt (i t.ex. REBUS eller liknande) eller är det helt nya id:n?
Stop_id är Samtrafikens rikshållplatsnummer. De flesta trafikbolag har egna/annorlunda idn på hållplatserna. Tågoperatörer som t.ex SJ använder sig dock av samma nummer.
Service_id (i trips.txt): Det är bara en ”pekare” till calendar filerna. Skapas av Samtrafikens trafiksystem.
Trip_id är ett nummer som genereras i Samtrafikens trafiksystem och alltså inte har någon koppling till trafikbolagens nummer.
Route_id skapas/sätts ihop av flera fält från trafikbolagen för att passa Googles definition av en ”route”. I princip sätter vi ihop producentnummer med trafikbolagets linjenummer samt med trafikslaget (tåg,buss etc). Många tågföretag och expressbussbolag har dock unika nummer på varje avgång istället för ett ”linjenummer” (t.ex SJs tåg). Dessa får då en och samma route_id, t.ex ”74_J” eftersom Google inte accepterar att varje avgång har ett unikt nummer.
Terms and conditions for Trafiklab.se APIs
Introduction
Thank you for your interest in the Trafiklab.se API: s. The Trafiklab.se API: s (“ the API: s”) are a collection of API: s to data on public transportation in Sweden (“ the Provided Data”), collected and compiled by Samtrafiken i Sverige Aktiebolag (“ Samtrafiken”) and its partners, provided to you by Samtrafiken for the purpose of encouraging the development of applications, web services and similar developments related to public transportation in Sweden.
Provided that you
- register an account with Trafiklab.se at www.trafiklab.se;
- choose the type of API which best fits the purposes of your intended development (for detailed information on the technical requirements and limitations of each API type, see the technical documentation provided with each respective type of API) ; and
- click to accept these Terms and Conditions below;
trafiken grants you a license to the API of your choice in accordance with the following.
License grant
Subject to the terms and restrictions set forth in these Terms and Conditions, Samtrafiken grants you a worldwide, non-exclusive, non-transferable, non-assignable license to the API, for the purpose of accessing, using and publicly displaying the Provided Data in your application, web server or similar development.
The license is based on the principles of the Creative Commons Attribution-license, and thus allows you to share (copy, distribute and transmit the work) and remix (i. e. alter, adapt and change the work, including integration with other information and/or settings), also for commercial purposes, however provided that you attribute the work as specified in section 4.1 below. Conditions and limitations in addition to the Creative Commons Attribution-license also apply, as provided in these Terms and Conditions.
Said license, or any development based thereon, shall in no way be construed as a limitation of Samtrafiken’ s and its original sources’ right to freely utilize, develop or delete the API, the Provided Data or products or services based thereon.
Technical requirements
In order to secure the availability and performance of the API and the Provided Data, developments based on the API shall be constructed in a manner which minimizes the capacity burden of the API. For this purpose, certain technical requirements and limitations are provided in the technical documentation of each type of API (“ the Technical Documentation”). The Technical Documentation shall be considered an integral part of these Terms and Conditions and, thus, by agreeing to accept these Terms and Conditions you agree to observe the limitations set forth in the Technical Documentation provided for the API of your choice.
Certain technical limitations, such as the number of requests per minute or month, may be improved by reserving a premium account. The prerequisites, terms and conditions for a premium account are stated in the respective Technical Documentation. Changes to other technical limitations, such as technical support, are only provided upon specific agreement with Samtrafiken. Such individual agreements may be discussed and arranged by contacting Samtrafiken at info@trafiklab.se.
Data requests in excess of or otherwise in breach of the technical limitations provided in the respective Technical Documentation may be blocked by Samtrafiken, and Samtrafiken reserves the right to terminate such license to the API in accordance with section 10 below.
Requirements on use
Applications, web services and similar developments which contain information retrieved via the API shall expressly state that the product or service is based on information retrieved from Trafiklab.se and, when practicable, a hyperlink to Trafiklab.se shall be provided.
Unless previously approved in writing by Samtrafiken, the API may not be used for applications, web services or similar developments which offer users the possibility to purchase tickets for public transportation. The approval of such functionality may however be discussed and agreed by contacting Samtrafiken at info@trafiklab.se.
As a condition for using and embedding the API into your application, web service or similar development you further agree that when using the API, you will not:
- copy Provided Data in order to create your own transcript of the Provided Data (the prohibition against copying does, however, not apply to temporary copies for the purpose of caching). Provided Data must always be retrieved via the API;
- assign, transfer or disclose the API key to any third party;
- interfere with, intercept, disrupt, filter or disable any features of the API or the Provided Data;
- transmit any viruses, worms, defects, Trojan horses or any such items of a destructive nature;
- infringe any third party intellectual property rights;
- access or use the API or any Provided Data through any technology or means other than those provided through Trafiklab.se;
- use the API or the Provided Data in a manner which directly or indirectly opposes or obstructs the purpose of Trafiklab.se and of Samtrafiken, i.e. to increase the lawful use of public transportation in Sweden;
- use the API or the Provided Data in a manner which in Samtrafiken’ s reasonable opinion disparages, infringes or dilutes the name, trademarks, logos, domain names and other distinctive brand features of Samtrafiken or its partners;
- use the API or the Provided Data in any other manner than as is legal, proper and in accordance with these Terms and Conditions.
If you are interested in doing anything different than the foregoing, you must first obtain Samtrafiken’ s written consent. If you fail to do so Samtrafiken reserves the right to terminate the API in accordance with section 10 below and, if deemed appropriate by Samtrafiken, to take legal action.
Provision of the API
The API and the Provided Data are provided on an “ as is” and “ as available” basis, with no warranties whatsoever regarding its security, reliability, timeliness, availability or performance. Thus, the Technical Documentation does not contain, and shall not be construed as, any binding commitment that i) the API will at all times meet the service levels set out therein; ii) the API will be uninterrupted, timely, secure or error-free or that iii) any errors in the Provided Data will be corrected, and Samtrafiken makes no such warranty or undertaking.
Samtrafiken may, at its sole discretion, change or release subsequent versions of the API: s, the Provided Data, the Technical Documentation or these Terms and Conditions, and require you to use and comply with the most current version. If a subsequent version is unacceptable to you, you may cancel the API at any time by deleting the API from your application, web service or similar development. If you continue to use the API in your application, web service or similar development you will be deemed to have accepted any updates or modifications. You can always review the most updated version of these Terms and Conditions and the most updated version of the Technical Documentation at www.trafiklab.se, or any successor URL that Samtrafiken may designate from time to time.
Intellectual property
You acknowledge and agree that Samtrafiken and its partners own all legal right, title and interest, including without limitation all intellectual property rights, to the API and the Provided Data, and that you shall not acquire any right, title or interest in the API or the Provided data except as set forth in these Terms and Conditions.
For purposes of these Terms and Conditions, Samtrafiken hereby grants to you a non-transferable, non sub-licenseable, non-exclusive license during the term of these Terms and Conditions to display Samtrafikens trademarks, logotypes and domain names, in order to advertise that you are using the API. You hereby grant Samtrafiken a non-transferable, non sub-licenseable, non-exclusive license during the term of these Terms and Conditions to use your trademarks, logotypes and domain names to advertise that you are using the API. Except as set forth in this section 6, nothing in these Terms and Conditions shall grant or be deemed to grant one party any right, title or interest in the other party’ s name, trademarks, logos, domain names and other distinctive brand features.
Limitation of liability
You understand and agree that you use the API at your own discretion and risk, and agree that Samtrafiken and its partners shall not be liable to you for any direct, indirect or any other damages - including but not limited to damages for loss of data, loss of profits, loss of use or loss of goodwill - resulting from the use or the inability to use the API.
Indemnification
You agree to indemnify and hold harmless Samtrafiken and its agents, employees and partners against any third party claim arising from or otherwise related to your use of the API in violation of these Terms and Conditions, or any other actions connected with your use of the API or Provided Data, including any liability or expense arising from claims, losses, damages, suits, judgments, litigation costs or attorney’ s fees of every nature.
Processing of personal data
You understand and agree that any personal data provided by you to Samtrafiken may be processed by Samtrafiken for the purpose of administrating, supervising and rendering your use of the API more effective. In such processing, Samtrafiken is the controller of the personal data in accordance with Personuppgiftslag (1998:204).
You are entitled to information about Samtrafikens processing of your personal data, and to require that any erroneously processed personal data is corrected, blocked or deleted, by contacting Samtrafiken at info@trafiklab.se.
Term and termination
The term of these Terms and Conditions shall commence on the date upon which you agree to the Terms and Conditions, and shall continue in force thereafter unless terminated or changed as provided herein. Either party may terminate these Terms and Conditions at any time, and Samtrafiken reserves the right to terminate the provision of the API to you with immediate effect in case you use the API in breach of any of these Terms and Conditions. In addition, Samtrafiken reserves the right to change, suspend or discontinue all or any aspect of the API or the Provided Data at any time, for any reason, in which case Samtrafiken will strive to announce such change, suspension or discontinuation within a reasonable time before its implementation.
Upon the termination of these Terms and Conditions for any reason, all license rights granted herein shall terminate, and you must immediately cease to use and delete the API, the Provided Data and trademarks of Samtrafiken.
Miscellaneous
These Terms and Conditions constitute the entire agreement between you and Samtrafiken and govern your use of the API and the Provided Data, superseding any prior agreements between you and Samtrafiken.
These Terms and Conditions may be assigned by Samtrafiken and will inure to the benefit of Samtrafiken, its assignees and successors.
The failure of any party to enforce any right or provision of these Terms and Conditions shall not constitute a waiver of such right or provision. If any provision of these Terms and Conditions is found by a court of competent jurisdiction to be invalid, the parties nevertheless agree that the court should endeavor to give effect to the parties’ intentions as reflected in the provision, and the other provisions of the Terms and Conditions remain in full force and effect.
Governing law
These Terms and Conditions are governed by the laws of Sweden, without regard to its conflict of laws provisions. Any dispute arising from these Terms and Conditions shall be settled in the courts of Sweden, with Stockholm district court as first instance.
