ST_Intersection

简介

geometry ST_Intersection (geometry geomA,geometry geomB) ;

 

geography ST_Intersection (geography geogA,geography geogB) ;

描述

返回几何几何,代表该点的交集。

换句话说 - 的那部分的几何形状和几何乙两个几何之间共享。

如果几何不共享任何空间(不相交),那么一个空的几何集合返回。

在结合ST_Intersects ST_Intersection裁剪的几何形状,如边界框,缓冲器,区域查询,只想返回该部分的几何形状,坐落在一个国家或地区的利益是非常有用的。

[注意]  

地理:地理周围的几何实现,这的确是一个薄的包装。 它首先确定最佳的SRID,适合2地理对象的边框(如果geography对象是在一个半区的UTM,但不相同的UTM会挑其中的一个)(有利于UTM或兰勃特方位等面积(LAEA)/南北极,并回落墨卡托在最坏的情况下),然后在最合适的平面空间参考和WGS84地理retransforms。

[重要]  

不要把GEOMETRYCOLLECTION作为一个参数用

由GEOS模块执行

状况:1.5支持地理数据类型进行了介绍。

 此方法实现OpenGIS的简单功能实现SQL 1.1规范。 s2.1.1.3

 此方法实现SQL / MM的规范。 SQL-MM:5.1.18

示例


SELECT ST_AsText(ST_Intersection('POINT(0 0)'::geometry, 'LINESTRING ( 2 0, 0 2 )'::geometry));
 st_astext
---------------
GEOMETRYCOLLECTION EMPTY
(1 row)
SELECT ST_AsText(ST_Intersection('POINT(0 0)'::geometry, 'LINESTRING ( 0 0, 0 2 )'::geometry));
 st_astext
---------------
POINT(0 0)
(1 row)

---Clip all lines (trails) by country (here we assume country geom are POLYGON or MULTIPOLYGONS)
-- NOTE: we are only keeping intersections that result in a LINESTRING or MULTILINESTRING because we don't
-- care about trails that just share a point
-- the dump is needed to expand a geometry collection into individual single MULT* parts
-- the below is fairly generic and will work for polys, etc. by just changing the where clause
SELECT clipped.gid, clipped.f_name, clipped_geom
FROM (SELECT trails.gid, trails.f_name, (ST_Dump(ST_Intersection(country.the_geom, trails.the_geom))).geom As clipped_geom
FROM country
	INNER JOIN trails
	ON ST_Intersects(country.the_geom, trails.the_geom))  As clipped
	WHERE ST_Dimension(clipped.clipped_geom) = 1 ;

--For polys e.g. polygon landmarks, you can also use the sometimes faster hack that buffering anything by 0.0
-- except a polygon results in an empty geometry collection
--(so a geometry collection containing polys, lines and points)
-- buffered by 0.0 would only leave the polygons and dissolve the collection shell
SELECT poly.gid,  ST_Multi(ST_Buffer(
				ST_Intersection(country.the_geom, poly.the_geom),
				0.0)
				) As clipped_geom
FROM country
	INNER JOIN poly
	ON ST_Intersects(country.the_geom, poly.the_geom)
	WHERE Not ST_IsEmpty(ST_Buffer(ST_Intersection(country.the_geom, poly.the_geom),0.0));
		

你可能感兴趣的:(ST_Intersection)