carto-routing-od-analysis

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Routing 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
carto-create-workflow
for the development process, JSON structure, and validation commands.

构建可计算路线、出行时间/距离矩阵以及等值线服务区的CARTO工作流。支持驾车和步行模式,还涵盖基于空间索引的OD流量模式分析。
前提条件:加载
carto-create-workflow
以获取开发流程、JSON结构和验证命令。

Instructions

操作说明

Three main workflow patterns exist. Choose based on the use case:
PatternComponentUse when
Isoline/Isochrone
native.isolines
You need catchment polygons around locations (e.g. "everywhere reachable within 10 min")
OD Matrix
native.routesodmatrix
You need travel time/distance between every origin-destination pair (analytics, no geometry)
Route Creation
native.routes
You need actual route line geometries between OD pairs (visualization, detailed path)

存在三种主要工作流模式,请根据使用场景选择:
模式组件使用场景
等值线/等时线
native.isolines
需要生成位置周边的服务区多边形(例如:“10分钟内可达的所有区域”)
OD矩阵
native.routesodmatrix
需要计算每一对起讫点之间的出行时间/距离(仅分析,无需几何图形)
路线生成
native.routes
需要起讫点对之间的实际路线几何图形(用于可视化、详细路径展示)

Pattern A: Isoline/Isochrone Generation

模式A:等值线/等时线生成

Pipeline:
Source Points -> (Filter) -> Isolines -> (Polyfill / Enrich) -> Save
流程:
源点数据 -> (过滤) -> 等值线生成 -> (Polyfill / 数据丰富) -> 保存

Step A1: Load Source Points

步骤A1:加载源点数据

Use
native.gettablebyname
to load locations (stores, stations, facilities).
Success: Table with a geometry column and a unique location identifier.
使用
native.gettablebyname
加载位置数据(门店、站点、设施等)。
成功标志:包含几何列和唯一位置标识符的表格。

Step A2: Generate Isolines

步骤A2:生成等值线

Use
native.isolines
with:
InputDescriptionExample
mode
Travel mode
car
or
walk
range_type
What the range measures
time
or
distance
range
Threshold valueSeconds for time (e.g.
600
= 10 min), meters for distance (e.g.
5000
= 5 km)
Success: Each input point has an associated polygon geometry representing the reachable area.
使用
native.isolines
,配置参数如下:
输入项描述示例
mode
出行模式
car
walk
range_type
范围度量类型
time
distance
range
阈值时间单位为秒(例如
600
=10分钟),距离单位为米(例如
5000
=5公里)
成功标志:每个输入点都对应一个代表可达区域的多边形几何图形。

Step A3: Post-Processing (optional)

步骤A3:后处理(可选)

Common follow-ups after isoline generation:
  • Polyfill + Enrich: Convert isoline polygons to H3 with
    native.h3polyfill
    , then enrich with demographics or POI data (see trade-area-analysis skill).
  • Overlap analysis: Use
    native.spatialjoin
    to find which isolines overlap, identifying areas served by multiple locations.
  • Coverage union: Use
    native.dissolve
    to merge all isoline polygons into a single coverage footprint.
等值线生成后的常见后续操作:
  • Polyfill + 数据丰富:使用
    native.h3polyfill
    将等值线多边形转换为H3网格,然后结合人口统计或POI数据进行丰富(参考商圈分析技能)。
  • 重叠分析:使用
    native.spatialjoin
    查找重叠的等值线,识别被多个位置覆盖的区域。
  • 覆盖范围合并:使用
    native.dissolve
    将所有等值线多边形合并为单个覆盖范围。

Step A4: Save

步骤A4:保存

Use
native.saveastable
to persist isoline polygons or enriched results.
Success: Validated workflow uploadable via
carto workflows create
.

使用
native.saveastable
保存等值线多边形或丰富后的结果。
成功标志:验证通过的工作流可通过
carto workflows create
上传。

Pattern 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
native.gettablebyname
nodes -- one for origins, one for destinations. Both need geometry columns.
Success: Two tables, each with point geometries and unique identifiers.
使用两个
native.gettablebyname
节点——一个加载起点数据,一个加载终点数据。两者都需要包含几何列。
成功标志:两个包含点几何图形和唯一标识符的表格。

Step B2: Compute OD Matrix

步骤B2:计算OD矩阵

Use
native.routesodmatrix
with:
InputDescription
mode
car
or
walk
Origins inputConnected from the origins table node
Destinations inputConnected from the destinations table node
Output columns:
origin_id
,
destination_id
,
duration_s
,
distance_m
.
Success: One row per origin-destination pair with travel time and distance.
使用
native.routesodmatrix
,配置参数如下:
输入项描述
mode
car
walk
起点输入连接到起点表节点
终点输入连接到终点表节点
输出列
origin_id
destination_id
duration_s
distance_m
成功标志:每一对起讫点对应一行数据,包含出行时间和距离。

Step B3: Filter or Aggregate (optional)

步骤B3:过滤或聚合(可选)

Common post-processing:
  • Nearest destination: Use
    native.groupby
    to find the minimum
    duration_s
    per origin, then join back to get the nearest destination.
  • Threshold filter: Use
    native.where
    to keep only pairs within a time/distance limit (e.g.
    duration_s < 1800
    for 30-min threshold).
  • Accessibility score: Count destinations reachable within a threshold per origin using
    native.groupby
    .
常见后处理操作:
  • 最近终点:使用
    native.groupby
    找到每个起点对应的最小
    duration_s
    ,然后关联回数据获取最近的终点。
  • 阈值过滤:使用
    native.where
    保留时间/距离在阈值内的配对(例如
    duration_s < 1800
    即30分钟阈值)。
  • 可达性评分:使用
    native.groupby
    统计每个起点在阈值内可达的终点数量。

Step B4: Save

步骤B4:保存

Use
native.saveastable
.
Success: Validated workflow uploadable via
carto workflows create
.

使用
native.saveastable
保存结果。
成功标志:验证通过的工作流可通过
carto workflows create
上传。

Pattern C: Route Geometries

模式C:路线几何图形

Pipeline:
Origins Table -> ┐
                 ├-> Routes -> Save
Destinations Table -> ┘
流程:
起点表 -> ┐
          ├-> 路线生成 -> 保存
终点表 -> ┘

Step C1: Load Origins and Destinations

步骤C1:加载起点和终点数据

Same as Pattern B -- two
native.gettablebyname
nodes with point geometries.
与模式B相同——两个
native.gettablebyname
节点,包含点几何图形。

Step C2: Compute Routes

步骤C2:计算路线

Use
native.routes
with:
InputDescription
mode
car
or
walk
Origins inputConnected from the origins table node
Destinations inputConnected from the destinations table node
Output: Route line geometries with
duration_s
and
distance_m
attributes.
Success: One route geometry per OD pair, visualizable on a map.
使用
native.routes
,配置参数如下:
输入项描述
mode
car
walk
起点输入连接到起点表节点
终点输入连接到终点表节点
输出:包含
duration_s
distance_m
属性的路线几何图形。
成功标志:每一对起讫点对应一条路线几何图形,可在地图上可视化展示。

Step C3: Save

步骤C3:保存

Use
native.saveastable
.
Success: Validated workflow uploadable via
carto workflows create
.

使用
native.saveastable
保存结果。
成功标志:验证通过的工作流可通过
carto workflows create
上传。

Pattern 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
native.gettablebyname
. The table should have both origin and destination coordinates (e.g. pickup_lon/lat, dropoff_lon/lat).
使用
native.gettablebyname
加载数据。表格需包含起点和终点坐标(例如上车经纬度、下车经纬度)。

Step D2: Index Origins and Destinations to H3

步骤D2:将起点和终点索引到H3网格

Use
native.selectexpression
to compute H3 cells for both origin and destination points:
  • Origin H3: derive from pickup coordinates
  • Destination H3: derive from dropoff coordinates
Alternatively, if the data has separate geometry columns, use
native.h3frompoint
for each.
使用
native.selectexpression
为起点和终点计算H3网格单元:
  • 起点H3:由上车坐标推导
  • 终点H3:由下车坐标推导
若数据已包含单独的几何列,可分别使用
native.h3frompoint
计算。

Step D3: Aggregate Flows

步骤D3:聚合流量

Use
native.groupby
to count trips per (origin_h3, destination_h3) pair:
  • Group by:
    origin_h3, destination_h3
  • Aggregation:
    origin_h3,count
    (trip count per OD pair)
Success: One row per unique OD cell pair with trip count -- ready for flow visualization.
使用
native.groupby
按(origin_h3, destination_h3)配对统计出行次数:
  • 分组依据
    origin_h3, destination_h3
  • 聚合方式
    origin_h3,count
    (每对OD的出行次数)
成功标志:每个唯一OD网格配对对应一行数据,包含出行次数——可用于流量可视化。

Step D4: Save

步骤D4:保存

Use
native.saveastable
.

使用
native.saveastable
保存结果。

Gotchas

注意事项

  • Provider casing & SQL dialect. This skill uses lowercase column names (
    origin_id
    ,
    destination_id
    ,
    duration_s
    ,
    distance_m
    ,
    origin_h3
    , etc.) — BigQuery / Databricks / Postgres / Redshift convention. On Snowflake, reference these UPPERCASE (
    ORIGIN_ID
    ,
    DURATION_S
    , ...). See
    carto-create-workflow/references/providers/<provider>.md
    for casing rules and SQL dialect equivalents.
  • Isolines and routing components consume LDS (Location Data Services) quota. Check available quota with
    LDS_QUOTA_INFO
    before bulk operations. Buffers (
    native.buffer
    ) do not consume LDS quota and are a free alternative for simple circular catchments.
  • 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
    departure_time
    if the component supports it; otherwise results reflect typical/average conditions.
  • 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
    origin_h3
    等)——符合BigQuery / Databricks / Postgres / Redshift的约定。在Snowflake上,需引用大写列名(
    ORIGIN_ID
    DURATION_S
    等)。查看
    carto-create-workflow/references/providers/<provider>.md
    获取大小写规则和SQL方言对应关系。
  • 等值线和路径规划组件会消耗LDS(位置数据服务)配额。批量操作前请通过
    LDS_QUOTA_INFO
    检查可用配额。缓冲区(
    native.buffer
    )不消耗LDS配额,是简单圆形服务区的免费替代方案。
  • 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

参考模板

ResourceDescription
Scalable Routing TutorialStep-by-step scalable routing in Workflows
OD Patterns TutorialAnalyzing origin-destination patterns (NYC taxi example)
Routing Module (BQ)Using the routing module with Analytics Toolbox for BigQuery
Isoline Generation TemplateGenerating 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

常见变体

VariantHow
Service area coverageIsolines (car, multiple ranges e.g. 5/10/15 min) -> union -> measure total population covered
Nearest facilityOD matrix -> group by origin -> min(duration_s) -> join back to get nearest destination ID
Accessibility scoringOD matrix -> filter by threshold -> count destinations per origin -> score by reachable count
Fleet route planningRoutes between depot and delivery points -> aggregate total distance/time per route
Commute flow analysisTrip data -> H3 origin + H3 destination -> group by OD pair -> count -> visualize top flows
Multi-modal comparisonRun isolines twice (car + walk) -> compare coverage polygons -> identify transit-dependent areas
变体实现方式
服务区域覆盖生成等值线(驾车模式,多范围例如5/10/15分钟)-> 合并 -> 统计覆盖的总人口
最近设施查找OD矩阵 -> 按起点分组 -> 取最小(duration_s) -> 关联获取最近终点ID
可达性评分OD矩阵 -> 按阈值过滤 -> 统计每个起点可达的终点数量 -> 按可达数量评分
车队路线规划生成仓库与配送点之间的路线 -> 聚合每条路线的总距离/时间
通勤流量分析出行数据 -> H3起点 + H3终点 -> 按OD配对分组 -> 统计数量 -> 可视化Top流量
多模式对比生成两次等值线(驾车+步行)-> 对比覆盖多边形 -> 识别依赖公共交通的区域