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 incidents — City of Philadelphia, via OpenDataPhilly
(Crime Incidents) and
the PHL Carto SQL API
(phl.carto.com, table
incidents_part1_part2). Downloaded as yearly CSV; the last three years
(2024–2026) are combined to smooth single-year fluctuation.
Walking network — OpenStreetMap, via OSMnx.
Sidewalk / ADA conditions — user-submitted reports only. No open
dataset for Philadelphia sidewalk condition / ADA ramp status was used.
Download the OSM walking graph within ~3.5 km of Penn (UTM-projected, cached as GraphML).
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.
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.
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.
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
Proxy, not prediction. Historical crime density is not future risk.
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.
Fixed area. A ~3.5 km radius around Penn; not city-wide.
Anecdotal sidewalk data. Reports are user-submitted, sparse, unverified.
Simple model. Distance-decayed weighting, single α, no time-of-day
decomposition.
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.
Intersection double-counting. The buffer overlaps at intersections,
amplifying intersection risk by design.
Length + weight only. No turn penalties, signals, grade, or lighting.
Severity weights are judgment calls, not empirically derived.
"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.
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.