2014-07-05 169 views
2

我在我的PostgreSQL數據庫(版本9.3)中有一個包含多邊形的列geom的表。然後我有一個線對象,它構建了一個邊界。我試圖用邊界對象內的所有geom對象來構建一個視圖。PostGIS:通過邊界過濾多邊形

我試過的功能ST_Within(不能處理multipolygons)和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

回答

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不同,幾何的順序很重要。

+0

嘿約翰,thx爲您的答案。我試過了,數據無法顯示。不幸的是,我認爲你的查詢不會幫助我。官方文檔說,幾何集合不支持(http://postgis.refractions.net/documentation/manual-1.4/ST_Contains.html [鏈接])...任何其他建議? – user3806723

+0

啊,你有幾何集合。是的,他們很難與之合作。你只有多邊形和多面體,還是你有線條和點? –

+0

我認爲只有多邊形,但不幸的是我不能排除,還有一些其他幾何... – user3806723