【问题标题】:how to detect polygons within other (many) polygons in postgis如何在postgis中检测其他(许多)多边形中的多边形
【发布时间】:2015-06-15 03:38:13
【问题描述】:

我有两个数据集:1. ZipCodes 和 2. Neighborhoods(将它们视为县)。

我想加入邮政编码覆盖的每个社区。大多数社区只会在一个邮政编码之内,但在某些情况下,社区会跨越两个。比如:

邻域 1 位于 20001 内部
邻里 2 在 20002 里面
邻里3在20001,20002里面

这是我目前所拥有的:

SELECT name, zipcode  
FROM    
neighborhood_names nn, dc_zipcode_boundries dzb
WHERE ST_Intersects(nn.the_geom, dzb.the_geom);

注意:根据 cmets 更新到 within,现在可以得到每个邻域的答案,但仍然无法让 Array 函数按预期响应。

【问题讨论】:

  • 您并没有错过任何这样的东西,尽管您可能想要使用 ST_Intersects,它还将获取跨越边界的那些邮政编码。如果您想为每个邻域提供一行输出,则可以使用 array_agg 函数以及按名称进行的 GROUP,它将为您的第三个示例行返回类似 3, [20001, 20002] 的内容,而不是两行。跨度>
  • 所以我尝试了这个:
    select nn.the_geom_webmercator, name, string_Agg(zipcode, ',') as zipcodeArr from
    neighbor_names nn, dc_zipcode_boundries dzb where ST_Intersects(nn.the_geom,dzb .the_geom)
    并且通常会出错:列“nn.the_geom_webmercator”必须出现在 GROUP BY 子句中或用于聚合函数中我做错了什么?

标签: postgis cartodb


【解决方案1】:

我想通了。感谢约翰的帮助。我的声明需要一个 group by (这就是错误所说的,只是需要一些时间来消化它才能点击)。

下面的 sn-p 对任何关注的人都有效

SELECT name, array_to_string(array_agg(zipcode), ',') 
FROM    
neighborhood_names nn, dc_zipcode_boundries dzb
WHERE ST_Intersects(nn.the_geom, dzb.the_geom)
group by name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-09
    • 2015-07-24
    • 2018-11-12
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多