PedalSafe is a Flask-based geospatial web application designed to improve urban cycling safety through route planning, hazard analysis, infrastructure visualization, amenity discovery, street-light analytics, and safety scoring.
The platform integrates PostgreSQL/PostGIS, Aurora, Mapbox, and OSRM to deliver intelligent cycling insights for urban environments such as Melbourne.
- Visualize cyclist crash incidents on an interactive map
- Filter incidents by:
- Geographic bounding box
- Time range
- Severity
- Color-coded hazard indicators
- Real-time API querying from PostgreSQL/Aurora
- Bicycle-safe route planning using OSRM
- Multiple route alternatives
- Route safety scoring
- Infrastructure overlap analysis
- Geocoding support using Mapbox
- Infrastructure visualization:
- Protected bike lanes
- Shared paths
- Buffered lanes
- Separated cycling paths
Search and discover cycling-related amenities:
- Bicycle parking
- Water fountains
- Rest areas
- Safety barriers
- Recreation areas
- Waste bins
- Greenery zones
Features include:
- Type filtering
- Bounding-box search
- Route-based amenity discovery
- Distance-to-route calculations
- Dynamic cycling quiz system
- Questions retrieved from PostgreSQL
- Randomized question generation
- Multiple-choice support
Analyze urban lighting infrastructure:
- Street light mapping
- Lighting density heatmaps
- Cluster visualization
- Route lighting safety score
- Brightness and condition analysis
Advanced safety analytics:
- Route safety scoring
- Safety classification levels
- Geometry visualization
- Route comparison
- Statistical analysis dashboard
Frontend (HTML + JS + Mapbox)
β
Flask REST API
β
SQLAlchemy ORM
β
Aurora PostgreSQL + PostGIS
β
OSRM + Mapbox APIs
- Python 3
- Flask
- SQLAlchemy
- PostgreSQL / Aurora
- PostGIS
- Mapbox API
- OSRM Routing Engine
- GeoJSON
- PostGIS Spatial Functions
- HTML5
- JavaScript
- Mapbox GL JS
- CSS
project-root/
β
βββ app/
β βββ pedalsafe/
β β
β βββ __pycache__/
β β
β βββ data/
β β
β βββ templates/
β β βββ assets/
β β
β βββ course.html
β βββ epic1.html
β βββ epic2.html
β βββ epic3.html
β βββ epic4.html
β βββ epic5.html
β βββ epic6.html
β βββ epic_selector1.html
β βββ epic_selector2.html
β βββ epic_selector3.html
β βββ index1.html
β βββ index2.html
β βββ index3.html
β β
β βββ .env
β βββ README.md
β βββ pedalsafe_app.py
β βββ requirements.txt
β
βββ .gitignore
βββ README.md
Create a .env file inside /backend.
# Database
DB_HOST=your-host
DB_PORT=5432
DB_NAME=your-db
DB_USER=your-user
DB_PASSWORD=your-password
DB_SSLMODE=require
# Optional full URL
DATABASE_URL=
# Mapbox
MAPBOX_TOKEN=your-mapbox-token
# OSRM
OSRM_BASE_URL=https://router.project-osrm.org
# Tables
CRASH_TABLE=cyclist_crashes
STREET_FURNITURE_TABLE=street_furniture
STREET_LIGHTS_TABLE=street_lightgit clone https://github.com/yourusername/pedalsafe.git
cd pedalsafepython -m venv venvvenv\Scripts\activatesource venv/bin/activatepip install -r requirements.txtcd backend
python epic1_app.pyServer starts at:
http://127.0.0.1:9000
| Route | Description |
|---|---|
/ |
Main application |
/hazards |
Hazard visualizer |
/routes |
Safe route planner |
/amenities |
Amenities finder |
/quiz |
Cycling rules quiz |
/streetlights |
Lighting analyzer |
/safetyscore |
Safety scoring dashboard |
| Endpoint | Description |
|---|---|
/api/v1/incidents |
Get cycling incidents |
/api/v1/geocode |
Geocode locations |
| Endpoint | Description |
|---|---|
/api/v2/plan |
Safe route planner |
/api/v2/routes/within_bbox |
Routes in viewport |
/api/v2/infrastructure/nearby |
Nearby infrastructure |
| Endpoint | Description |
|---|---|
/api/v3/amenities/search |
Search amenities |
/api/v3/amenities/by_type |
Amenities by type |
/api/v3/amenities/along_route |
Amenities along route |
/api/v3/amenities/all_types |
All amenity samples |
| Endpoint | Description |
|---|---|
/api/v4/quiz |
Retrieve quiz questions |
| Endpoint | Description |
|---|---|
/api/v5/street-lights |
Street light data |
/api/v5/lighting-density |
Lighting heatmap |
/api/v5/street-lights-clustered |
Clustered lighting |
/api/v5/route-lighting-score |
Route lighting score |
| Endpoint | Description |
|---|---|
/api/v6/safety-scores |
Route safety scores |
/api/v6/safety-breakdown/<route_id> |
Score breakdown |
/api/v6/route-geometries |
Route geometries |
/api/v6/safety-statistics |
Safety statistics |
The project heavily uses PostGIS functionality:
ST_DWithinST_IntersectionST_LengthST_AsGeoJSONST_SimplifyST_MakeEnvelopeST_Within
- Cyclists finding safer routes
- Urban planners analyzing dangerous cycling zones
- Infrastructure planning
- Lighting safety evaluation
- Smart city research
- GIS and transport analytics
Recommended stack:
Nginx
β
Gunicorn
β
Flask App
β
Aurora PostgreSQL
Run with Gunicorn:
gunicorn -w 4 -b 0.0.0.0:9000 epic1_app:app- Machine learning safety prediction
- Real-time traffic integration
- Mobile application
- User authentication
- Crowdsourced hazard reporting
- Weather-aware route planning
- AI-powered route recommendations
- Surya Krishna Harikrishnan
- Shen
- Rocky
- William Bonasi Babu
- Mapbox
- OSRM
- PostgreSQL
- PostGIS
- Flask Community
- OpenStreetMap Contributors