返回Geometry對象相交的點(diǎn)集對應(yīng)的Geometry對象。
語法
geometry ST_Intersection(geometry geomA , geometry geomB);
geography ST_Intersection(geography geogA , geography geogB);
geometry ST_Intersection(geometry set gField);
參數(shù)
參數(shù)名稱 | 描述 |
---|---|
geomA/geomB | 兩個(gè)目標(biāo)Geometry對象。 |
geogA/geogB | 兩個(gè)目標(biāo)Geography對象。 |
gField | Geometry字段。 |
描述
- 如果輸入的兩個(gè)對象沒有任何公共的部分或者不相交,那么該函數(shù)返回一個(gè)空對象。
- 對于Geography類型對象,該函數(shù)只是對Geometry型函數(shù)的簡單封裝。該函數(shù)首先將其轉(zhuǎn)換成Geometry對象,然后在平面參考系中相交得到交集,然后轉(zhuǎn)換回WGS84參考系,變成Geography類型對象。
- 該函數(shù)不支持GeometryCollection類型對象作為輸入?yún)?shù)。
- 該函數(shù)會(huì)丟棄對象的M坐標(biāo)值。
- 聚合函數(shù)會(huì)將所有Geometry對象依次執(zhí)行intersection,返回所有對象的交集部分。
示例
- 默認(rèn)調(diào)用:
SELECT ST_AsText(ST_Intersection('POLYGON((0 0,0 2,2 2,2 0,0 0))'::geometry,'POLYGON((0 0,3 0,3 1,0 1,0 0))'::geometry)); st_astext -------------------------------- POLYGON((0 0,0 1,2 1,2 0,0 0)) (1 row)
- 聚合裁剪
create table agg_result(id integer, geom geometry); insert into agg_result values(0, ST_GeomFromText('POLYGON((0 0, 0 0.5, 0.5 0.5, 0.5 0, 0 0))')); insert into agg_result select i, st_buffer('POINT(0 0)', 0.8 + random()*0.1) from generate_series(1,100) as i; select st_astext(st_intersection(geom)) from agg_result; st_astext ---------------------------------------- POLYGON((0 0,0 0.5,0.5 0.5,0.5 0,0 0)) (1 row)