SesarDB

Home Tables Schemas Diagrams Foreign Keys Indexes
sesar_fixpoly(geometry) - Procedure
Name sesar_fixpoly(geometry)
Comment
Src
CREATE OR REPLACE FUNCTION sesar_fixpoly(geometry) 
  RETURNS character varying AS 
$$


SELECT CASE WHEN
	( st_xmax( $1::geometry ) - st_xmin( $1::geometry ) ) > ( st_xmax( st_shift_longitude( $1::geometry ) ) - st_xmin( st_shift_longitude( $1::geometry ) ) )
THEN
	st_astext(
	st_union(
	st_intersection(st_shift_longitude($1::geometry),'POLYGON((179.99999 -89.9999,179.99999 89.9999,0.00001 89.9999,0.00001 -89.9999,179.99999 -89.9999))'::geometry),
	st_translate(
		st_intersection(st_shift_longitude($1::geometry),'POLYGON((180.00001 -89.9999,180.00001 89.9999,359.99999 89.9999,359.99999 -89.9999,180.00001 -89.9999))'::geometry),
	-360,0
	))
	)
ELSE
	st_astext($1::geometry)
END;


$$
  LANGUAGE sql VOLATILE 
  COST 100;