postgis函数geometry去重

postgis中多边形相交去重:

create or replace function difference(geom1 geometry , geom2 geometry ) returns geometry as
$$
declare

begin
	if st_intersects(geom1 , geom2) then
		return st_difference(geom1 , geom2);
	else
		return geom1 ;
	end if;


end;
$$
language plpgsql ;

该函数判断第二个参数和第一个参数是否有重合,有重合的话以第一个参数为模板去掉重合部分,没有重合则返回第一个参数。

 

postgis,根据两个经纬度返回矩形:

create or replace function points_to_polygon(lon1 numeric , lat1 numeric , lon2 numeric , lat2 numeric ) returns geometry as
$$

	select  st_geomfromtext('POLYGON((' || lon1  || ' ' || lat1
		|| ',' || lon2  || ' ' || lat1
		|| ',' || lon2  || ' ' || lat2
		|| ',' || lon1  || ' ' || lat2
		|| ',' || lon1  || ' ' || lat1  || '))' , 4326);

$$
language sql immutable ;

 

 

 

 

转载自:https://blog.csdn.net/jjxliu306/article/details/84903627

You may also like...

退出移动版