Python module to facilitate the acquisition and analysis of Indego bikeshare data
- Download all CSV files with:
indego scrape
- Move these files from your download folder to a better spot
- Import the CSV files to PostgreSQL with:
indego import-to-sql
TODO:
- Aggregate trips based upon an input polygon shapefile
Create a virtual environment using conda
:
conda env create -f environment.yml
Activate the environment:
conda activate bikeshare-data
Create a .env
file to store configuration parameters:
DEFAULT_DB_URI = postgresql://postgres:password@localhost:5432/indego
DEFAULT_DATA_FOLDER = /path/to/data/dir
STUDY_AREA = "ST_SetSRID(ST_GeomFromText('POLYGON((-75.179070999792 39.9561219999082, ...etc...))'), 4326)"
Make sure that the database defined by DEFAULT_DB_URI
already exists and that the postgis
extension can be (or has been) enabled.
1) Download all CSV files hosted on Indego's data page:
indego scrape-trips
This will download all CSV files to your computer's Downloads
folder. Cut and paste these files into the DEFAULT_DATA_FOLDER
before continuing to the next step.
indego import-to-sql
This imports all CSVs into a single table named raw_trips
with 4.3 million rows (as of 8/2021), and then generates a cleaned up version named trips
. This will take approximately 8 minutes to run.
indego scrape-stations
This creates a spatial table in the database named station_shapes
indego analyze
The study area boundary is defined using WKT to facilitate future integration into a backend API that will communicate with a webmap frontend where users point/click to define a custom study area.
<script src="https://cdn.rawgit.com/mapbox/wellknown/master/wellknown.js"></script>
let my_wkt = wellknown.stringify(data.features[0].geometry);
This returns a well-known-text description of the shape:
POLYGON ((-75.179070999792 39.9561219999082,-75.179121999973 39.9559839999298,-75.1793000003484 39.9559849996663))
To work with spatial queries, wrap the WKT within:
ST_SetSRID(
ST_GeomFromText('my_wkt'),
4326
)