Find the flattest route between any two points in SF
Navigating San Francisco's Hills: An Overview of Flatten SF
Created by Drew Edwards, Flatten SF is a specialized routing tool designed to help users identify the least strenuous paths between any two locations within the city of San Francisco.
🛠️ Core Functionality
The application allows users to input a starting point (From) and a destination (To). For cyclists, there is a specific toggle to Prefer calm streets, which adjusts the routing logic based on street safety and comfort.
The tool provides real-time data on:
- Total distance (Shortest)
- Total elevation gain (Flattest)
- Maximum steepness encountered
⚙️ How the Engine Works
Routes are calculated locally within your web browser. The system analyzes over
160,000individual street segments, leveraging high-resolution USGS 1m lidar elevation data combined with the Overture / OpenStreetMap street graph.
The Trade-off Slider
The interface features a slider that manages the tension between distance and vertical climb. It identifies the "Pareto frontier"—routes where no other path is simultaneously shorter and flatter.
The Logic:
- Moving the slider right: The route will either stay the same length or get longer, but it will never increase in climbing.
- The Limit: The flattest possible route is determined by a specific cost ratio: If a detour exceeds this ratio, the system stops considering it a viable route.
Understanding "Climbing"
It is important to note that the tool measures cumulative gain.
Net elevation difference between start and end Total ascent.
🚲 Cycling & "Comfort" Metrics
When the "Prefer calm streets" option is enabled, the algorithm stops measuring raw distance and starts measuring "comfort distance." This is calculated by applying a multiplier to the actual length of the street segment:
| Street Type | Comfort Weight | Description |
|---|---|---|
| Protected Lane/Path | 0.8 | SFMTA bikeway network |
| Quiet Street | 1.0 | Standard residential/low traffic |
| Busy Arterial | 1.4 to 2.0 | High traffic, no dedicated lane |
// Conceptual logic for comfort distance
function calculateComfortDistance(length, streetType) {
const weights = {
'protected': 0.8,
'quiet': 1.0,
'arterial': 1.7 // average of 1.4 - 2.0
};
return length * weights[streetType];
}
🗺️ Data Architecture
The search functionality is entirely offline. All necessary data—including street intersections, specific addresses, and points of interest within San Francisco—are embedded directly into the page.