2017-06-21 249 views
0

我有一組數組中的多邊形(不在數據庫中)。我想檢查那些多邊形與另一個多邊形相交。POSTGIS多邊形ST_Intersects檢查

實施例:

input: [[], [], [], [], []] - set of polygons 
want to checks those with another one polygon. 
Return an array of true or false 

ST_intersects支持一次僅兩個多邊形。 有沒有辦法一次檢查所有的東西?如果沒有,我必須遍歷所有的輸入多邊形並逐一檢查。

謝謝。

+0

AFAIK沒有辦法做到這一點。您必須循環 –

回答

0

如果您想知道至少有一個輸入多邊形是否與目標多邊形相交,則可以將輸入表示爲MultiPolygon數據類型。這基本上就是你擁有的數組。然後ST_Intersects需要一個Multipolygon單元。但是,沒有選項可以返回一組布爾值(true或false)。

你可以看到的MultiPolygon的WKT表示在WKT wiki page,構建並使用ST_GeomFromText

+0

我需要檢查所有多邊形是否與另一個多邊形相交,或者是否有多邊形與另一個多邊形不相交返回false。 ? –

0

轉換爲PostGIS的二進制您可以結合ST_DUMPST_INTERSECTS功能陣列幾何(MULTIGEOMETRY TYPE)

St_astext(包裹。的geom);

MULTIPOLYGON(((398140.945672642 4542263.06495453,398140.410405475 4542262.72839343,398140.513367039 4542263.18287079,398140.945672642 4542263.06495453)), 
((398147.309882976 4542261.32904395,398146.58758329 4542258.33481488,398144.165643562 4542262.18667092,398147.309882976 4542261.32904395)), 
((398141.915568335 4542238.96883738,398135.522133265 4542241.15138888,398138.811826236 4542255.67218681,398140.343422935 4542253.23633343,398146.254207604 4542256.95287011,398141.915568335 4542238.96883738))) 

這是我的數據庫的一個例子 - 簽入;

select a.objectid,b.fid ,st_intersects (a.poly,b.geom) 
from region a, 
(
select objectid::text||((st_dump(poly)).path[1]::text) as fid, (st_dump(poly)).geom as geom 
    from parcel where geometrytype(poly)='MULTIPOLYGON') 
    as b 

http://www.postgis.org/docs/ST_Dump.html

http://postgis.org/docs/ST_Intersects.html