Skip to content

JayQueue/GPXCheck

Repository files navigation

GPX Route Roadworks Checker

A Flask web application that analyzes GPX cycling routes and identifies roadworks along the path across multiple European countries. The application provides interactive maps with route visualization, roadwork zone polygons, and suggested detours.

Features

  • Multi-Country Support: Checks roadworks in Belgium (GIPOD), Netherlands (NDW), France (Bison Futé), and UK (StreetManager)
  • Interactive Map: Full-screen map with route visualization and work zone polygons
  • Automatic Detection: Detects which countries your route passes through
  • Street-Following Detours: Generates realistic detour routes using OSRM and OpenRouteService APIs
  • Work Zone Polygons: Displays actual roadwork boundaries instead of just point markers
  • Redis Caching: Optional Redis support for improved performance
  • GPX Export: Download your route with detours as a standard GPX file

Requirements

  • Python 3.8+
  • Flask
  • Redis (optional, for caching)

Installation

  1. Clone the repository:
git clone <repository-url>
cd gpx-detours
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create upload directory:
mkdir uploads
  1. Set up environment variables (optional):
cp .env.example .env
# Edit .env with your settings

Configuration

Environment Variables

Create a .env file in the project root:

# Cache Configuration
CACHE_TYPE=redis  # or 'memory'
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=  # Leave empty if no password
CACHE_DEFAULT_TTL=1800

# Flask Configuration
SECRET_KEY=your-secret-key-here
UPLOAD_FOLDER=uploads
MAX_CONTENT_LENGTH=16777216  # 16MB

# Logging Level
LOG_LEVEL=INFO

Redis Setup (Optional)

For improved caching performance, install and start Redis:

macOS (Homebrew):

brew install redis
brew services start redis

Ubuntu/Debian:

sudo apt update
sudo apt install redis-server
sudo systemctl start redis
sudo systemctl enable redis

Windows: Download and install from Redis for Windows

Usage

  1. Start the application:
python app.py
  1. Open your browser and navigate to http://localhost:5000

  2. Upload a GPX file using the drag-and-drop interface

  3. Select your planned ride date

  4. Click "Analyze Route" to check for roadworks

  5. View results on the interactive map:

    • Blue line: Your original route
    • Red polygons: Roadwork zones
    • Green dashed lines: Suggested detours
    • Orange clusters: Multiple nearby roadworks
  6. Download the enhanced GPX file with detours included

Supported Data Sources

Belgium

  • GIPOD (Geografisch Informatie Platform Openbare Domeinen)
  • API: https://geo.api.vlaanderen.be/GIPOD/ogc/features/v1
  • Coverage: Flanders region roadworks and utility works

Netherlands

  • NDW (Nationale Databank Wegverkeersgegevens)
  • Coverage: National road network incidents and roadworks

France

  • Bison Futé: National road network events
  • Paris OpenData: Construction sites in Paris
  • Coverage: Major roads and urban areas

United Kingdom

  • StreetManager: Street works and traffic management
  • Coverage: England, Wales, Scotland

Development

Project Structure

gpx-detours/
├── app.py                  # Main Flask application
├── config.py              # Configuration management
├── requirements.txt       # Python dependencies
├── adapters/              # Country-specific data adapters
│   ├── __init__.py
│   ├── base_adapter.py
│   ├── belgium_gipod.py
│   ├── france_bison_fute.py
│   ├── netherlands_ndw.py
│   └── uk_streetmanager.py
├── cache/                 # Caching system
│   └── __init__.py
├── core/                  # Core processing modules
│   ├── country_detector.py
│   ├── map_generator.py
│   └── route_processor.py
├── templates/             # HTML templates
│   └── index.html
├── utils/                 # Utility functions
│   └── date_utils.py
└── uploads/              # Temporary GPX file storage

Adding New Countries

  1. Create a new adapter in adapters/ inheriting from CountryAdapter
  2. Implement required methods:
    • get_country_code()
    • get_country_name()
    • get_supported_bbox()
    • _fetch_roadworks_uncached()
    • parse_work_location()
    • get_work_info()
  3. Register the adapter in adapters/__init__.py

Running Tests

# Test individual country adapters
python -c "from adapters.belgium_gipod import BelgiumGIPODAdapter; adapter = BelgiumGIPODAdapter(); print(len(adapter.fetch_roadworks('2025-01-01', '2025-12-31')))"

# Test cache performance
curl http://localhost:5000/debug/cache

# Test specific country
curl http://localhost:5000/test-france

API Endpoints

  • GET / - Main application interface
  • POST /upload - Upload and analyze GPX file
  • GET /cache/stats - Cache performance statistics
  • POST /cache/clear - Clear all cached data
  • GET /debug/cache - Debug cache contents
  • GET /test-france - Test France adapter directly

Performance Considerations

  • Caching: Use Redis for production deployments
  • File Cleanup: Uploaded GPX files are automatically deleted after processing
  • Rate Limiting: Consider implementing rate limiting for production use
  • Timeout Handling: All external API calls have 30-second timeouts

Troubleshooting

Common Issues

No roadworks found:

  • Check if your route passes through supported countries
  • Verify date range (some APIs only show current/future works)
  • Check logs for API connection errors

Slow performance:

  • Enable Redis caching
  • Check network connectivity to external APIs
  • Reduce GPX file complexity (fewer track points)

Cache issues:

  • Clear cache via /cache/clear endpoint
  • Restart Redis if using Redis caching
  • Check Redis connection settings

Logging

The application logs to console by default. Key information includes:

  • Country detection results
  • API response times and cache hit rates
  • Number of roadworks found per country
  • Performance metrics for route analysis

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

License

This project is licensed under the MIT License. See LICENSE file for details.

Acknowledgments

  • OpenStreetMap for map tiles
  • Folium for interactive mapping
  • OSRM and OpenRouteService for routing
  • Government Open Data initiatives for roadworks APIs

About

Check GPX tracks for roadworks

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published