Skip to content

Latest commit

Β 

History

134 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

PedalSafe πŸš΄β€β™‚οΈ

Smart Cycling Safety & Infrastructure Analysis Platform

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.


πŸ“Œ Features

EPIC 1: Cycling Hazard Visualizer

  • 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

EPIC 2: Safe Route & Infrastructure Planner

  • 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

EPIC 3: Bicycle Amenities Finder

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

EPIC 4: Cycling Rules Quiz

  • Dynamic cycling quiz system
  • Questions retrieved from PostgreSQL
  • Randomized question generation
  • Multiple-choice support

EPIC 5: Night & Visibility Safety Analyzer

Analyze urban lighting infrastructure:

  • Street light mapping
  • Lighting density heatmaps
  • Cluster visualization
  • Route lighting safety score
  • Brightness and condition analysis

EPIC 6: Cycling Safety Score Engine

Advanced safety analytics:

  • Route safety scoring
  • Safety classification levels
  • Geometry visualization
  • Route comparison
  • Statistical analysis dashboard

πŸ—οΈ System Architecture

Frontend (HTML + JS + Mapbox)
        ↓
Flask REST API
        ↓
SQLAlchemy ORM
        ↓
Aurora PostgreSQL + PostGIS
        ↓
OSRM + Mapbox APIs

πŸ› οΈ Tech Stack

Backend

  • Python 3
  • Flask
  • SQLAlchemy
  • PostgreSQL / Aurora
  • PostGIS

APIs & GIS

  • Mapbox API
  • OSRM Routing Engine
  • GeoJSON
  • PostGIS Spatial Functions

Frontend

  • HTML5
  • JavaScript
  • Mapbox GL JS
  • CSS

πŸ“‚ Project Structure

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

βš™οΈ Environment Variables

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_light

πŸš€ Installation

1. Clone Repository

git clone https://github.com/yourusername/pedalsafe.git
cd pedalsafe

2. Create Virtual Environment

python -m venv venv

Windows

venv\Scripts\activate

macOS/Linux

source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Run Application

cd backend
python epic1_app.py

Server starts at:

http://127.0.0.1:9000

🌐 Main Routes

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

πŸ”Œ API Endpoints

EPIC 1 APIs

Endpoint Description
/api/v1/incidents Get cycling incidents
/api/v1/geocode Geocode locations

EPIC 2 APIs

Endpoint Description
/api/v2/plan Safe route planner
/api/v2/routes/within_bbox Routes in viewport
/api/v2/infrastructure/nearby Nearby infrastructure

EPIC 3 APIs

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

EPIC 4 APIs

Endpoint Description
/api/v4/quiz Retrieve quiz questions

EPIC 5 APIs

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

EPIC 6 APIs

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

πŸ—ΊοΈ Spatial Features

The project heavily uses PostGIS functionality:

  • ST_DWithin
  • ST_Intersection
  • ST_Length
  • ST_AsGeoJSON
  • ST_Simplify
  • ST_MakeEnvelope
  • ST_Within

πŸ“Š Example Use Cases

  • Cyclists finding safer routes
  • Urban planners analyzing dangerous cycling zones
  • Infrastructure planning
  • Lighting safety evaluation
  • Smart city research
  • GIS and transport analytics

πŸ”’ Production Deployment

Recommended stack:

Nginx
   ↓
Gunicorn
   ↓
Flask App
   ↓
Aurora PostgreSQL

Run with Gunicorn:

gunicorn -w 4 -b 0.0.0.0:9000 epic1_app:app

πŸ§ͺ Future Improvements

  • Machine learning safety prediction
  • Real-time traffic integration
  • Mobile application
  • User authentication
  • Crowdsourced hazard reporting
  • Weather-aware route planning
  • AI-powered route recommendations

πŸ‘¨β€πŸ’» Authors

  • Surya Krishna Harikrishnan
  • Shen
  • Rocky
  • William Bonasi Babu

πŸ™Œ Acknowledgements

  • Mapbox
  • OSRM
  • PostgreSQL
  • PostGIS
  • Flask Community
  • OpenStreetMap Contributors