carto-routing-od-analysis
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRouting and Origin-Destination Analysis
路径规划与起讫点(OD)分析
Builds CARTO Workflows that compute routes, travel time/distance matrices, and isoline catchment areas. Supports driving and walking modes. Also covers OD flow pattern analysis using spatial indexing.
Prerequisites: Load for the development process, JSON structure, and validation commands.
carto-create-workflow构建可计算路线、出行时间/距离矩阵以及等值线服务区的CARTO工作流。支持驾车和步行模式,还涵盖基于空间索引的OD流量模式分析。
前提条件:加载以获取开发流程、JSON结构和验证命令。
carto-create-workflowInstructions
操作说明
Three main workflow patterns exist. Choose based on the use case:
| Pattern | Component | Use when |
|---|---|---|
| Isoline/Isochrone | | You need catchment polygons around locations (e.g. "everywhere reachable within 10 min") |
| OD Matrix | | You need travel time/distance between every origin-destination pair (analytics, no geometry) |
| Route Creation | | You need actual route line geometries between OD pairs (visualization, detailed path) |
存在三种主要工作流模式,请根据使用场景选择:
| 模式 | 组件 | 使用场景 |
|---|---|---|
| 等值线/等时线 | | 需要生成位置周边的服务区多边形(例如:“10分钟内可达的所有区域”) |
| OD矩阵 | | 需要计算每一对起讫点之间的出行时间/距离(仅分析,无需几何图形) |
| 路线生成 | | 需要起讫点对之间的实际路线几何图形(用于可视化、详细路径展示) |
Pattern A: Isoline/Isochrone Generation
模式A:等值线/等时线生成
Pipeline:
Source Points -> (Filter) -> Isolines -> (Polyfill / Enrich) -> Save流程:
源点数据 -> (过滤) -> 等值线生成 -> (Polyfill / 数据丰富) -> 保存Step A1: Load Source Points
步骤A1:加载源点数据
Use to load locations (stores, stations, facilities).
native.gettablebynameSuccess: Table with a geometry column and a unique location identifier.
使用加载位置数据(门店、站点、设施等)。
native.gettablebyname成功标志:包含几何列和唯一位置标识符的表格。
Step A2: Generate Isolines
步骤A2:生成等值线
Use with:
native.isolines| Input | Description | Example |
|---|---|---|
| Travel mode | |
| What the range measures | |
| Threshold value | Seconds for time (e.g. |
Success: Each input point has an associated polygon geometry representing the reachable area.
使用,配置参数如下:
native.isolines| 输入项 | 描述 | 示例 |
|---|---|---|
| 出行模式 | |
| 范围度量类型 | |
| 阈值 | 时间单位为秒(例如 |
成功标志:每个输入点都对应一个代表可达区域的多边形几何图形。
Step A3: Post-Processing (optional)
步骤A3:后处理(可选)
Common follow-ups after isoline generation:
- Polyfill + Enrich: Convert isoline polygons to H3 with , then enrich with demographics or POI data (see trade-area-analysis skill).
native.h3polyfill - Overlap analysis: Use to find which isolines overlap, identifying areas served by multiple locations.
native.spatialjoin - Coverage union: Use to merge all isoline polygons into a single coverage footprint.
native.dissolve
等值线生成后的常见后续操作:
- Polyfill + 数据丰富:使用将等值线多边形转换为H3网格,然后结合人口统计或POI数据进行丰富(参考商圈分析技能)。
native.h3polyfill - 重叠分析:使用查找重叠的等值线,识别被多个位置覆盖的区域。
native.spatialjoin - 覆盖范围合并:使用将所有等值线多边形合并为单个覆盖范围。
native.dissolve
Step A4: Save
步骤A4:保存
Use to persist isoline polygons or enriched results.
native.saveastableSuccess: Validated workflow uploadable via .
carto workflows create使用保存等值线多边形或丰富后的结果。
native.saveastable成功标志:验证通过的工作流可通过上传。
carto workflows createPattern B: OD Matrix (Travel Time/Distance)
模式B:OD矩阵(出行时间/距离)
Pipeline:
Origins Table -> ┐
├-> OD Matrix -> (Filter/Aggregate) -> Save
Destinations Table -> ┘流程:
起点表 -> ┐
├-> OD矩阵生成 -> (过滤/聚合) -> 保存
终点表 -> ┘Step B1: Load Origins and Destinations
步骤B1:加载起点和终点数据
Use two nodes -- one for origins, one for destinations. Both need geometry columns.
native.gettablebynameSuccess: Two tables, each with point geometries and unique identifiers.
使用两个节点——一个加载起点数据,一个加载终点数据。两者都需要包含几何列。
native.gettablebyname成功标志:两个包含点几何图形和唯一标识符的表格。
Step B2: Compute OD Matrix
步骤B2:计算OD矩阵
Use with:
native.routesodmatrix| Input | Description |
|---|---|
| |
| Origins input | Connected from the origins table node |
| Destinations input | Connected from the destinations table node |
Output columns: , , , .
origin_iddestination_idduration_sdistance_mSuccess: One row per origin-destination pair with travel time and distance.
使用,配置参数如下:
native.routesodmatrix| 输入项 | 描述 |
|---|---|
| |
| 起点输入 | 连接到起点表节点 |
| 终点输入 | 连接到终点表节点 |
输出列:、、、。
origin_iddestination_idduration_sdistance_m成功标志:每一对起讫点对应一行数据,包含出行时间和距离。
Step B3: Filter or Aggregate (optional)
步骤B3:过滤或聚合(可选)
Common post-processing:
- Nearest destination: Use to find the minimum
native.groupbyper origin, then join back to get the nearest destination.duration_s - Threshold filter: Use to keep only pairs within a time/distance limit (e.g.
native.wherefor 30-min threshold).duration_s < 1800 - Accessibility score: Count destinations reachable within a threshold per origin using .
native.groupby
常见后处理操作:
- 最近终点:使用找到每个起点对应的最小
native.groupby,然后关联回数据获取最近的终点。duration_s - 阈值过滤:使用保留时间/距离在阈值内的配对(例如
native.where即30分钟阈值)。duration_s < 1800 - 可达性评分:使用统计每个起点在阈值内可达的终点数量。
native.groupby
Step B4: Save
步骤B4:保存
Use .
native.saveastableSuccess: Validated workflow uploadable via .
carto workflows create使用保存结果。
native.saveastable成功标志:验证通过的工作流可通过上传。
carto workflows createPattern C: Route Geometries
模式C:路线几何图形
Pipeline:
Origins Table -> ┐
├-> Routes -> Save
Destinations Table -> ┘流程:
起点表 -> ┐
├-> 路线生成 -> 保存
终点表 -> ┘Step C1: Load Origins and Destinations
步骤C1:加载起点和终点数据
Same as Pattern B -- two nodes with point geometries.
native.gettablebyname与模式B相同——两个节点,包含点几何图形。
native.gettablebynameStep C2: Compute Routes
步骤C2:计算路线
Use with:
native.routes| Input | Description |
|---|---|
| |
| Origins input | Connected from the origins table node |
| Destinations input | Connected from the destinations table node |
Output: Route line geometries with and attributes.
duration_sdistance_mSuccess: One route geometry per OD pair, visualizable on a map.
使用,配置参数如下:
native.routes| 输入项 | 描述 |
|---|---|
| |
| 起点输入 | 连接到起点表节点 |
| 终点输入 | 连接到终点表节点 |
输出:包含和属性的路线几何图形。
duration_sdistance_m成功标志:每一对起讫点对应一条路线几何图形,可在地图上可视化展示。
Step C3: Save
步骤C3:保存
Use .
native.saveastableSuccess: Validated workflow uploadable via .
carto workflows create使用保存结果。
native.saveastable成功标志:验证通过的工作流可通过上传。
carto workflows createPattern D: OD Flow Analysis (Grid-Based)
模式D:OD流量分析(基于网格)
For analyzing trip/movement patterns at scale (e.g. taxi trips, bike rides, commute flows) without calling routing APIs.
Pipeline:
Trip Data -> H3 (origin) + H3 (destination) -> Group By (origin_h3, dest_h3) -> Save用于大规模分析出行/移动模式(例如出租车行程、骑行、通勤流量),无需调用路径规划API。
流程:
出行数据 -> H3(起点) + H3(终点) -> 分组(origin_h3, dest_h3) -> 保存Step D1: Load Trip Data
步骤D1:加载出行数据
Use . The table should have both origin and destination coordinates (e.g. pickup_lon/lat, dropoff_lon/lat).
native.gettablebyname使用加载数据。表格需包含起点和终点坐标(例如上车经纬度、下车经纬度)。
native.gettablebynameStep D2: Index Origins and Destinations to H3
步骤D2:将起点和终点索引到H3网格
Use to compute H3 cells for both origin and destination points:
native.selectexpression- Origin H3: derive from pickup coordinates
- Destination H3: derive from dropoff coordinates
Alternatively, if the data has separate geometry columns, use for each.
native.h3frompoint使用为起点和终点计算H3网格单元:
native.selectexpression- 起点H3:由上车坐标推导
- 终点H3:由下车坐标推导
若数据已包含单独的几何列,可分别使用计算。
native.h3frompointStep D3: Aggregate Flows
步骤D3:聚合流量
Use to count trips per (origin_h3, destination_h3) pair:
native.groupby- Group by:
origin_h3, destination_h3 - Aggregation: (trip count per OD pair)
origin_h3,count
Success: One row per unique OD cell pair with trip count -- ready for flow visualization.
使用按(origin_h3, destination_h3)配对统计出行次数:
native.groupby- 分组依据:
origin_h3, destination_h3 - 聚合方式:(每对OD的出行次数)
origin_h3,count
成功标志:每个唯一OD网格配对对应一行数据,包含出行次数——可用于流量可视化。
Step D4: Save
步骤D4:保存
Use .
native.saveastable使用保存结果。
native.saveastableGotchas
注意事项
- Provider casing & SQL dialect. This skill uses lowercase column names (,
origin_id,destination_id,duration_s,distance_m, etc.) — BigQuery / Databricks / Postgres / Redshift convention. On Snowflake, reference these UPPERCASE (origin_h3,ORIGIN_ID, ...). SeeDURATION_Sfor casing rules and SQL dialect equivalents.carto-create-workflow/references/providers/<provider>.md - Isolines and routing components consume LDS (Location Data Services) quota. Check available quota with before bulk operations. Buffers (
LDS_QUOTA_INFO) do not consume LDS quota and are a free alternative for simple circular catchments.native.buffer - OD matrices grow quadratically: N origins x M destinations = N*M rows. Filter or sample inputs to keep the matrix manageable. For 1000 origins x 1000 destinations, you get 1 million rows.
- Walking mode has a much shorter practical range than driving. Walking isolines beyond 20-30 minutes or OD matrices beyond a few kilometers produce unreliable or empty results.
- Route geometries can be large. For pure analytics (time/distance only), prefer the OD matrix (Pattern B) over full routes (Pattern C) to reduce data volume.
- Time-of-day affects driving results due to congestion. Specify if the component supports it; otherwise results reflect typical/average conditions.
departure_time - Isoline polygons may overlap for nearby locations. If enriching afterwards, polyfill to a spatial index and deduplicate cells to avoid double-counting.
- For OD flow visualization (Pattern D), use H3 cell center points rather than raw coordinates for cleaner aggregation and visualization. A coarser resolution (e.g. H3 res 7-8) produces more meaningful flow patterns than fine resolutions.
- The LDS routing components require a connection with LDS API access enabled. Validation may fail if the connection lacks this permission.
- 提供商大小写与SQL方言:本技能使用小写列名(、
origin_id、destination_id、duration_s、distance_m等)——符合BigQuery / Databricks / Postgres / Redshift的约定。在Snowflake上,需引用大写列名(origin_h3、ORIGIN_ID等)。查看DURATION_S获取大小写规则和SQL方言对应关系。carto-create-workflow/references/providers/<provider>.md - 等值线和路径规划组件会消耗LDS(位置数据服务)配额。批量操作前请通过检查可用配额。缓冲区(
LDS_QUOTA_INFO)不消耗LDS配额,是简单圆形服务区的免费替代方案。native.buffer - OD矩阵的规模呈二次增长:N个起点 × M个终点 = N*M行数据。请过滤或采样输入数据以控制矩阵规模。例如1000个起点 × 1000个终点会生成100万行数据。
- 步行模式的实际有效范围远小于驾车模式。步行等值线超过20-30分钟,或OD矩阵超过几公里范围时,结果可能不可靠或为空。
- 路线几何图形数据量较大。若仅需分析时间/距离,优先选择OD矩阵(模式B)而非完整路线(模式C)以减少数据量。
- 时段会影响驾车结果,因为存在交通拥堵。若组件支持,请指定;否则结果反映典型/平均路况。
departure_time - 邻近位置的等值线多边形可能重叠。若后续要进行数据丰富,需将多边形转换为空间索引并去重网格单元,避免重复统计。
- 对于OD流量可视化(模式D),使用H3网格中心点而非原始坐标进行聚合和可视化效果更佳。较粗的分辨率(例如H3第7-8级)比精细分辨率能生成更有意义的流量模式。
- LDS路径规划组件需要启用LDS API访问权限的连接。若连接缺少该权限,验证可能失败。
Reference Templates
参考模板
| Resource | Description |
|---|---|
| Scalable Routing Tutorial | Step-by-step scalable routing in Workflows |
| OD Patterns Tutorial | Analyzing origin-destination patterns (NYC taxi example) |
| Routing Module (BQ) | Using the routing module with Analytics Toolbox for BigQuery |
| Isoline Generation Template | Generating isochrones via Workflow templates |
| Trade Area Isolines (BQ) | Drive/walk-time isoline trade areas for BigQuery |
| Trade Area Isolines (SF) | Drive/walk-time isoline trade areas for Snowflake |
| 资源 | 描述 |
|---|---|
| Scalable Routing Tutorial | 工作流中可扩展路径规划分析的分步教程 |
| OD Patterns Tutorial | 起讫点模式分析教程(纽约出租车示例) |
| Routing Module (BQ) | 结合BigQuery分析工具箱使用路径规划模块 |
| Isoline Generation Template | 通过工作流模板生成等时线 |
| Trade Area Isolines (BQ) | BigQuery中基于驾车/步行时间等值线的商圈生成 |
| Trade Area Isolines (SF) | Snowflake中基于驾车/步行时间等值线的商圈生成 |
Common Variations
常见变体
| Variant | How |
|---|---|
| Service area coverage | Isolines (car, multiple ranges e.g. 5/10/15 min) -> union -> measure total population covered |
| Nearest facility | OD matrix -> group by origin -> min(duration_s) -> join back to get nearest destination ID |
| Accessibility scoring | OD matrix -> filter by threshold -> count destinations per origin -> score by reachable count |
| Fleet route planning | Routes between depot and delivery points -> aggregate total distance/time per route |
| Commute flow analysis | Trip data -> H3 origin + H3 destination -> group by OD pair -> count -> visualize top flows |
| Multi-modal comparison | Run isolines twice (car + walk) -> compare coverage polygons -> identify transit-dependent areas |
| 变体 | 实现方式 |
|---|---|
| 服务区域覆盖 | 生成等值线(驾车模式,多范围例如5/10/15分钟)-> 合并 -> 统计覆盖的总人口 |
| 最近设施查找 | OD矩阵 -> 按起点分组 -> 取最小(duration_s) -> 关联获取最近终点ID |
| 可达性评分 | OD矩阵 -> 按阈值过滤 -> 统计每个起点可达的终点数量 -> 按可达数量评分 |
| 车队路线规划 | 生成仓库与配送点之间的路线 -> 聚合每条路线的总距离/时间 |
| 通勤流量分析 | 出行数据 -> H3起点 + H3终点 -> 按OD配对分组 -> 统计数量 -> 可视化Top流量 |
| 多模式对比 | 生成两次等值线(驾车+步行)-> 对比覆盖多边形 -> 识别依赖公共交通的区域 |