An open API service indexing awesome lists of open source software.

https://github.com/dvrpc/gis-lts-calc


https://github.com/dvrpc/gis-lts-calc

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

          

# Level of Traffic Stress (LTS) Calculation

This project calculates Level of Traffic Stress (LTS) scores on the DVRPC model network. It includes a component for conflating speed data from PennDOT and NJDOT to help with more accurate scoring.

## Overview

The workflow:
1. Sets up a PostgreSQL/PostGIS database
2. Loads PennDOT speed limit data (auto-downloaded)
3. Loads NJDOT road network with M values (auto-downloaded)
4. Loads NJDOT speed data (manual CSV from input folder)
5. Loads DVRPC model network shapefile
6. Conflates speed data from PennDOT and NJDOT to model network
7. Calculates LTS scores (1-4)
8. Cleans up temporary files

## Prerequisites

- PostgreSQL with PostGIS extension
- Python 3.9+
- Required tools: `psql`, `ogr2ogr`

## Setup

1. Install Python dependencies:
```bash
pip install -r requirements.txt
```

2. Create a `.env` file with your configuration:
```env
# PostgreSQL Connection
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_password
POSTGRES_DB=lts

# Model Network Shapefile (without .shp extension)
NETWORK_SHAPEFILE=input/bike_network_dec1_2025_link
```

3. Place your model network shapefile in the `input/` directory and update `NETWORK_SHAPEFILE` in `.env`

4. Copy the lookup tables:
```bash
cp -r lookups.example/ lookups/
```

5. Download NJDOT speed data:
- Visit https://njsld.org/NJDOT/SLD/DataBrowser/Speed
- Click the Export button to download as CSV
- Save the file as `input/Speed.csv`

### Required Model Network Shapefile Fields

Your shapefile must contain these fields:
- `no` (numeric) - Segment ID
- `fromnodeno` (numeric) - From node ID
- `tonodeno` (numeric) - To node ID
- `typeno` (varchar) - Road type code (72, 79 for residential)
- `numlanes` (numeric) - Number of lanes
- `bike_fac~1` (numeric) - Bike facility type (0-9)
- `vcur_prt~2` (varchar) - Speed field (e.g., "25mph")
- `geom` - Geometry (LineString)

## Usage

Run the complete workflow:
```bash
python3 run.py
```

## Output

Final table: `output.model_network_with_lts`

Contains all original bike network fields plus:
- `vehiclespeed`: Speed limit (from PennDOT or original data)
- `final_speed_source`: Source of speed data (penndot or original)
- `lts`: Level of Traffic Stress score (1-4)

## Files

- `run.py` - Main workflow script
- `sql/` - SQL scripts
- `conflate_speed_data.sql` - conflate DOT speed
- `calculate_lts.sql` - LTS calculation using DVRPC methodology
- `njdot_speed_to_geometry.sql` - NJDOT speed csv geometry mapping
- `lookups/` - Lookup tables for LTS calculation (gitignored, copy from `lookups.example/`)
- `lookups.example/` - Example lookup tables (tracked in git)
- `old_lts.py` - Reference: Original LTS methodology from Visum
- `requirements.txt` - Python dependencies
- `.env` - Database configuration (create this)

## Customizing LTS Scoring

The LTS calculation uses two lookup tables in the `lookups/` folder that can be adjusted to modify scoring:

### Setup

Copy the example lookup files to create your local versions:
```bash
cp -r lookups.example/ lookups/
```

### lts_lookup.csv

This table defines the LTS score for each combination of road characteristics and bike facility type. Each row specifies:
- Lane count ranges (`min_lanes`, `max_lanes`)
- Speed ranges (`min_speed`, `max_speed`)
- Whether the rule applies to residential roads (`is_residential`)
- LTS scores (1-4) for each bike facility type

You can adjust the LTS values in the facility columns to change how different road/facility combinations are scored.

### bike_facility_lookup.csv

This table maps bike facility codes from your network data to the column names used in `lts_lookup.csv`. Modify this if your network uses different facility codes or if you want to reclassify certain facility types.

## Bike Facility Codes

The `bike_fac~1` field should use these codes:
- `0` - No bike facility
- `1` - Sharrows
- `2` - Bike Lane
- `3` - Buffered Bike Lane
- `4` - Multi-use Trail
- `5` - Signed Bike Route
- `6` - Protected Bike Lane
- `9` - Opposite direction of one-way street