SafePath

Methodology, data sources & limitations

← Back to map

What this is

SafePath overlays a "safety data layer" (crime history, user-reported sidewalk/accessibility issues) onto the walking network around the University of Pennsylvania, then finds a safer route — not just the shortest one. It is a Penn summer-program final project spanning Pandas (data prep), Graph (routing), and Flask (web).

Why not just the shortest route?

The shortest path treats every street as equal. It isn't — crime clusters heavily on a handful of corridors (Mantua, the Market St corridor, Point Breeze in this dataset), so the straight-line path often cuts straight through a high-risk block to save a few meters. Two measured examples: Penn Park → Mill Creek drops from 10 high-risk segments to 0 for +106 m; Van Pelt → 30th St drops from 4 to 0 for +40 m. When origin or destination sits inside a hot corridor itself, the safest route can't fully escape it — see "can't be routed around" below the route comparison — but it still cuts high-risk walking distance (one measured case: 115 m → 56 m, −52%).

Rule of thumb while walking any route here: stay alert near intersections (risk is deliberately weighted higher there — see buffer overlap below), prefer lit main streets after dark over quiet parallel blocks even if SafePath doesn't flag them (no time-of-day or lighting data yet), and treat a "high-risk" tag as elevated historical incident density, not a guarantee something will happen there.

Data sources

Crime data © City of Philadelphia / Philadelphia Police Department. Map data © OpenStreetMap contributors. Light basemap: OpenFreeMap Positron © OpenMapTiles.

Method

  1. Download the OSM walking graph within ~3.5 km of Penn (UTM-projected, cached as GraphML).
  2. Buffer each street edge by 120 m and assign each crime point to every covering edge, weighted by distance: a point right on the edge counts fully, one at the buffer edge decays to zero. This spreads risk onto the 2–3 nearest parallel streets (after network-KDE practice) rather than only the closest one.
  3. Weight each crime by a severity score (violent > property > order) and sum the distance-decayed contributions per edge. This sum is the edge's raw risk; it is not divided by edge length — because the 120 m buffer means a short crosswalk segment and a long street sitting in the same crime field collect nearly the same crime mass, so dividing by length would mostly measure "how short is the edge", not "how dangerous". Normalize each edge to its percentile rank (ties averaged), so mid-risk blocks keep a visible penalty and Dijkstra sees the full dynamic range. Trade-off: rank normalization discards magnitude — the riskiest and the merely-risky block become the same rank-distance apart — but the p90 high-risk threshold is itself rank-based, so the two are semantically consistent.
  4. safety_weight = length × (1 + α · risk_norm) with α = 1.5. The riskiest edge is penalized to 2.5× its true length; a zero-crime edge keeps its true length.
  5. Run Dijkstra twice on the same graph — once on length (shortest), once on safety_weight (safest). User-reported issues multiply the nearest edge's safety weight, so submitted reports change future routes.

The map offers two toggleable risk layers (top-right control): risk-colored streets (each street shaded green→yellow→red by risk) and a crime-density heatmap. Together they make where the danger concentrates visible — the core of the product.

Limitations

  1. Proxy, not prediction. Historical crime density is not future risk.
  2. Snapshot, not real-time. Crime risk is a static snapshot from the local CSV (2024–2026, 3 years combined); it only updates when someone re-runs prep_data.py by hand — there is no scheduled refresh and the optional Carto API is not wired to live data in this MVP. Routes themselves are computed live on every request (no caching), so a submitted report takes effect on the very next route request — it's the crime layer that's frozen, not the routing.
  3. Fixed area. A ~3.5 km radius around Penn; not city-wide.
  4. Anecdotal sidewalk data. Reports are user-submitted, sparse, unverified.
  5. Simple model. Distance-decayed weighting, single α, no time-of-day decomposition.
  6. Detours are short, but the route really does change. Central Philly is a tight grid, so switching to a parallel street costs almost nothing in distance — measured detours run about +3% (and up to +18% on the worst pairs), while 48–85% of the individual segments differ. Judge the split by which streets it takes, not by how much longer it is. User reports are an additional source of divergence (they bump one segment hard), not the only one.
  7. Intersection double-counting. The buffer overlaps at intersections, amplifying intersection risk by design.
  8. Length + weight only. No turn penalties, signals, grade, or lighting.
  9. Severity weights are judgment calls, not empirically derived.
  10. "Use my location" needs a secure context. The report locator uses navigator.geolocation, which browsers only expose over HTTPS (or localhost, as in this local demo). Deploy behind HTTPS for the button to work in production; manual coordinate entry is the fallback.
  11. The basemap is a free third-party service. Background streets come from OpenFreeMap's public tile server (no key, no SLA) and are drawn with WebGL. If that server is down or WebGL is disabled, the background stays blank; routes and risk layers still draw on top.
← Back to map