在PostgreSQL / Postgis

时间:2018-04-25 09:01:06

标签: postgis postgresql-9.6

我正在尝试将一系列线串几何与匹配属性(road_name_search和road_id)合并,然后将合并的线串连接回来自以下示例数据的road_id属性

http://sqlfiddle.com/#!15/f52d21(请注意 - 如果将其复制到数据库,则需要将形状列的类型更改为几何(MultiLineString,2193))...是否有一个PostGIS版本的SQL小提琴?)

我尝试过使用下面的代码,它可以很好地结合道路名称:

SELECT 
MAX (road_id),
road_name_search
FROM a_road_test 
GROUP BY road_name_search

这似乎按预期工作,结果如下:

max         road_name_search
3033986     Kennedy Road (Onekawa)
3033986     Kennedy Road (Greenmeadows)
3033986     Kennedy Road (Marewa)
1808281     Kennedy Road (Pyes Pa)
3033986     Kennedy Road (Pirimai)

接下来,我尝试包含几何字符串,所以我最终得到了我需要的一切......当我扩展查询以包含像这样的几何字符串的聚类时

SELECT 
MAX (road_id),
road_name_search,
unnest(ST_ClusterIntersecting(shape))
FROM a_road_test 
GROUP BY road_name_search

然后我最终得到重复的road_name_search_fields,即每次出现多次,例如

1808281 Kennedy Road (Pyes Pa)      geoma
3033986 Kennedy Road (Pirimai)      geomb
3033986 Kennedy Road (Pirimai)      geomc
3033986 Kennedy Road (Onekawa)      geomd
3033986 Kennedy Road (Greenmeadows) geome
3033986 Kennedy Road (Greenmeadows) geomf
3033986 Kennedy Road (Marewa)       geomg
3033986 Kennedy Road (Marewa)       geomh

接下来的方法,排除不需要的功能......     选择     MAX(road_id),     road_name_search,     ST_ClusterIntersecting(形状)     来自a_road_test     GROUP BY road_name_search

现在我最终......

1808281 Kennedy Road (Pyes Pa)  [geoma]
3033986 Kennedy Road (Pirimai)  [geomb, geomc]
3033986 Kennedy Road (Onekawa)  [geomd]
3033986 Kennedy Road (Greenmeadows) [geome, geomf]
3033986 Kennedy Road (Marewa)   [geomg, geomh]

只是不能弄清楚如何......

1808281 Kennedy Road (Pyes Pa)      geoma
3033986 Kennedy Road (Pirimai)      geombc
3033986 Kennedy Road (Onekawa)      geomd
3033986 Kennedy Road (Greenmeadows) geomef
3033986 Kennedy Road (Marewa)       geomgh

感谢您寻找:)

1 个答案:

答案 0 :(得分:0)

@ewcz

确定的一个非常简单的答案
Cannot GET /(routename)