我的PostgreSQL数据库(版本9.3)中有一个包含列geom的表,其中包含一个多面。然后我有一个线对象,它构建了一个边界。我正在尝试使用边界对象内的所有geom对象构建视图。
我尝试了ST_Within函数(不能处理多重多边形)和ST_Intersects ......
这是我的SQL命令:
CREATE VIEW buildings_intersect_boundary AS
SELECT ROW_NUMBER() OVER (ORDER BY "buildings".gid ASC) AS ROW_NUMBER,
"buildings".name,"buildings".type,
"buildings".geom
FROM "buildings" INNER JOIN "boundary" ON
ST_Intersects("buildings".geom,"boundary".geom)
目前我使用边界框解决问题:
CREATE VIEW osm_buildings_intersect_project_boundary AS
SELECT ROW_NUMBER() OVER (ORDER BY "buildings_fromOSMShape".gid ASC) AS ROW_NUMBER,
"buildings_fromOSMShape".name,"buildings_fromOSMShape".type,
"buildings_fromOSMShape".geom
FROM "buildings_fromOSMShape" INNER JOIN "boundary_project_area" ON
"buildings_fromOSMShape".geom @ "boundary_project_area".geom
但是这会返回太多的对象......
操作系统:Ubuntu 14.04
答案 0 :(得分:1)
您是在寻找ST_Contains,它类似于ST_Intersects,但排除了未完全包含的几何 - 您说您想要其他内容的对象。 ST_Within为您提供距其他人不远的几何图形。
CREATE VIEW osm_buildings_intersect_project_boundary AS
SELECT ROW_NUMBER() OVER (ORDER BY buildings.gid ASC) AS ROW_NUMBER,
buildings.name, buildings.type, buildings.geom
FROM "buildings_fromOSMShape" buildings, "boundary_project_area" boundaries
WHERE ST_Contains(boundaries.geom, buildings.geom)
就个人而言,我更喜欢以这种方式编写ST_Contains和ST_Intersects查询,因为我认为当连接键实际上是空间条件而不是相等约束时使用内连接比使用内连接更清楚,尽管查询将执行相同的操作。为了便于阅读/简洁起见,我还将您的表名别名。请注意,对于ST_Contains,几何的顺序很重要,与ST_Intersects不同,它没有。