pgr_dijkstra returns 空集
pgr_dijkstra returns an empty set
我正在尝试编写一个函数,该函数能够使用 pgr_dijkstra
函数找到两点之间的最短路线。我正在关注 this guide. With data provided in the guide everything works fine. But when I try to apply the same steps (build a topology using pgr_createTopology
and then test it with pgr_dijkstra
) to another data set、pgr_dijkstra
returns 一个空结果。我还注意到指南的数据集有一个 LineString
几何列,而我有一个 MultiLineString
几何列。可能是什么原因?
我的table的结构:
Table "public.roads"
Column | Type | Collation | Nullable | Default
--------+--------------------------------+-----------+----------+------------------------------------
id | integer | | not null | nextval('roads_gid_seq'::regclass)
geom | geometry(MultiLineString,4326) | | |
source | integer | | |
target | integer | | |
Indexes:
"roads_pkey" PRIMARY KEY, btree (id)
"roads_geom_idx" gist (geom)
"roads_source_idx" btree (source)
"roads_target_idx" btree (target)
拓扑创建查询:
SELECT pgr_createTopology('roads', 0.00001, 'geom', 'id');
最短路线测试:
SELECT seq, node, edge, cost as cost, agg_cost, geom
FROM pgr_dijkstra(
'SELECT id, source, target, st_length(geom, true) AS cost FROM roads',
-- Some random points
1, 200
) AS pt
JOIN roads rd ON pt.edge = rd.id;
问题实际上与几何数据类型有关。该函数不能与 MultiLineString
一起正常工作,尽管它不会产生任何错误。所以,我已经将 MultiLineString
转换为 LineString
,现在一切似乎都正常了。
我正在尝试编写一个函数,该函数能够使用 pgr_dijkstra
函数找到两点之间的最短路线。我正在关注 this guide. With data provided in the guide everything works fine. But when I try to apply the same steps (build a topology using pgr_createTopology
and then test it with pgr_dijkstra
) to another data set、pgr_dijkstra
returns 一个空结果。我还注意到指南的数据集有一个 LineString
几何列,而我有一个 MultiLineString
几何列。可能是什么原因?
我的table的结构:
Table "public.roads"
Column | Type | Collation | Nullable | Default
--------+--------------------------------+-----------+----------+------------------------------------
id | integer | | not null | nextval('roads_gid_seq'::regclass)
geom | geometry(MultiLineString,4326) | | |
source | integer | | |
target | integer | | |
Indexes:
"roads_pkey" PRIMARY KEY, btree (id)
"roads_geom_idx" gist (geom)
"roads_source_idx" btree (source)
"roads_target_idx" btree (target)
拓扑创建查询:
SELECT pgr_createTopology('roads', 0.00001, 'geom', 'id');
最短路线测试:
SELECT seq, node, edge, cost as cost, agg_cost, geom
FROM pgr_dijkstra(
'SELECT id, source, target, st_length(geom, true) AS cost FROM roads',
-- Some random points
1, 200
) AS pt
JOIN roads rd ON pt.edge = rd.id;
问题实际上与几何数据类型有关。该函数不能与 MultiLineString
一起正常工作,尽管它不会产生任何错误。所以,我已经将 MultiLineString
转换为 LineString
,现在一切似乎都正常了。