简体   繁体   中英

POSTGIS multiple polygons ST_Intersects check

I have set of polygons (not in database) in an array. I want to check those polygons intersects with another one polygon.

Example:

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

ST_intersects support only two polygons at a time. IS there any way to check all at a time ? if not I have to loop through all the input polygons and check one by one.

Thanks.

You can combine ST_DUMP and ST_INTERSECTS functions for Array Geometries (MULTIGEOMETRY TYPE)

St_astext(parcel.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)))

Here is a example at my database - that checked in ;

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

If you want to know if at least one of your input polygons intersect the target polygon you can represent the input as MultiPolygon data type. This is basically the array that you have. Then ST_Intersects takes a Multipolygon cell. However, there is no option to return an array of boolean values (true or false).

You can see a WKT representation of MultiPolygon in WKT wiki page , construct it and convert to PostGIS binary using ST_GeomFromText

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM