https://github.com/zorapeteri/gtfs-polygon-filter
Filters routes in a GTFS feed that overlap with a GeoJSON polygon
https://github.com/zorapeteri/gtfs-polygon-filter
Last synced: about 1 year ago
JSON representation
Filters routes in a GTFS feed that overlap with a GeoJSON polygon
- Host: GitHub
- URL: https://github.com/zorapeteri/gtfs-polygon-filter
- Owner: zorapeteri
- License: mit
- Created: 2023-06-30T22:47:05.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-01T09:10:31.000Z (almost 3 years ago)
- Last Synced: 2025-03-03T11:46:15.299Z (over 1 year ago)
- Language: JavaScript
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## gtfs-polygon-filter
Filters routes in a GTFS feed based on whether they overlap with a GeoJSON Polygon (or MultiPolygon).
It includes a route in the returned array, if `overlapRatio` (0.5 by default) of the stops on the route are within the bounds of any of the provided polygons.
Works with [`node-gtfs`](https://github.com/blinktaginc/node-gtfs), requires an already open database connection to work.
### install
`npm i gtfs-polygon-filter`
### use
```js
import gtfsPolygonFilter from 'gtfs-polygon-filter'
import { openDb } from 'gtfs'
import totallyAwesomePolygyon from './somewhere'
openDb(config) // see how to do this in node-gtfs readme
const routesThatAreAtLeastTwoThirdsInsideMyPolygon = await gtfsPolygonFilter({
polygon: totallyAwesomePolygon,
routesFilter: {
agency_id: '123', // gets passed into gtfs/getRoutes, to avoid looping through all routes in GTFS feed
},
overlapRatio: 0.67,
})
// [
// {
// route_id: 'cool_route',
// agency_id: '123',
// route_short_name: 'Cool Route',
// ...
// },
// ]
```
More detailed example [here](https://github.com/zorapeteri/gtfs-polygon-filter/tree/main/example)