s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
153 lines • 4.63 kB
JavaScript
import { parseCSVAsRecord } from '../../';
/**
* # Stop Information
*
* ## Details
* **Conditionally Required** - Stops where vehicles pick up or drop off riders.
* Also defines stations, entrances, etc.
*/
export class GTFSStop {
/**
* **Required**
* Identifies a location: stop/platform, station, entrance/exit, generic node, or boarding area.
* Must be unique across:
* - stops.stop_id
* - locations.geojson id
* - location_groups.location_group_id
* Multiple routes may use the same `stop_id`.
*/
id;
/**
* **Optional**
* Short text or a number that identifies the location for riders.
*/
code;
/**
* **Conditionally Required**
* Name of the location. Required if `location_type` is 0, 1, or 2. Optional otherwise.
*/
name;
/**
* **Optional**
* Readable version of the stop_name for text-to-speech systems.
*/
ttsName;
/**
* **Optional**
* Description providing useful information about the location.
* Should not be a duplicate of `name`.
*/
desc;
/**
* **Conditionally Required**
* Latitude of the location. Required if `location_type` is 0, 1, or 2. Optional otherwise.
*/
lat;
/**
* **Conditionally Required**
* Longitude of the location. Required if `location_type` is 0, 1, or 2. Optional otherwise.
*/
lon;
/**
* **Optional**
* Identifies the fare zone for a stop.
*/
zoneId;
/**
* **Optional**
* URL of a web page about this location.
*/
url;
/**
* **Optional**
* Location type. Valid options:
* 0 or empty = Stop/Platform,
* 1 = Station,
* 2 = Entrance/Exit,
* 3 = Generic Node,
* 4 = Boarding Area.
*/
locationType;
/**
* **Conditionally Required**
* Defines hierarchy between different locations. Required if `location_type` is 2, 3, or 4.
*/
parentStation;
/**
* **Optional**
* Timezone of the location. Inherits from parent station if not specified.
*/
timezone;
/**
* **Optional**
* Indicates whether wheelchair boardings are possible at this location.
* For parentless stops: 0 = no info, 1 = possible, 2 = not possible.
* For child stops, entrance/exits: inherits or overrides parent station accessibility.
*/
wheelchairBoarding;
/**
* **Optional**
* Level of the location. References levels.level_id.
*/
levelId;
/**
* **Optional**
* Platform identifier for a platform stop.
*/
platformCode;
/** @param data - the parsed GTFS CSV data */
constructor(data) {
this.id = data.stop_id;
this.code = data.stop_code;
this.name = data.stop_name;
this.ttsName = data.tts_stop_name;
this.desc = data.stop_desc;
this.lat = data.stop_lat !== undefined ? parseFloat(data.stop_lat) : undefined;
this.lon = data.stop_lon !== undefined ? parseFloat(data.stop_lon) : undefined;
this.zoneId = data.zone_id;
this.url = data.stop_url;
this.locationType =
data.location_type !== undefined ? parseInt(data.location_type, 10) : undefined;
this.parentStation = data.parent_station;
this.timezone = data.stop_timezone;
this.wheelchairBoarding =
data.wheelchair_boarding !== undefined ? parseInt(data.wheelchair_boarding, 10) : undefined;
this.levelId = data.level_id;
this.platformCode = data.platform_code;
}
/**
* Returns the properties of this stop
* @returns - the properties of this stop
*/
properties() {
return {
id: this.id,
code: this.code ?? '',
name: this.name ?? '',
ttsName: this.ttsName ?? '',
desc: this.desc ?? '',
zoneId: this.zoneId ?? '',
url: this.url ?? '',
locationType: this.locationType ?? -1,
parentStation: this.parentStation ?? '',
timezone: this.timezone ?? '',
wheelchairBoarding: this.wheelchairBoarding ?? -1,
levelId: this.levelId ?? '',
platformCode: this.platformCode ?? '',
};
}
}
/**
* @param input - the input string to parse from
* @returns - an array of Stops
*/
export function parseGTFSStops(input) {
const data = parseCSVAsRecord(input);
const res = {};
for (const d of data) {
const stop = new GTFSStop(d);
res[stop.id] = stop;
}
return res;
}
//# sourceMappingURL=stops.js.map