Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- Function: ershkus_fn_geompoly(geometry[])
-- DROP FUNCTION ershkus_fn_geompoly(geometry[]);
CREATE OR REPLACE FUNCTION ershkus_fn_geompoly(geometry[])
RETURNS geometry AS
$BODY$
BEGIN
-- RETURN (SELECT ST_Polygonize(c2) FROM (SELECT ST_GeomFromText(astext(ST_Collect(c1)),4326) as c2 FROM (SELECT unnest($1) as c1) as t1) as t2);
RETURN (SELECT ST_BuildArea(ST_GeomFromText(astext(ST_Collect(c1)),4326)) as c2 FROM (SELECT unnest($1) as c1) as t1);
EXCEPTION
WHEN SQLSTATE 'XX000' THEN
RETURN null;
WHEN SQLSTATE '21000' THEN
RETURN null;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION ershkus_fn_geompoly(geometry[])
OWNER TO ershkus;
GRANT EXECUTE ON FUNCTION ershkus_fn_geompoly(geometry[]) TO public;
GRANT EXECUTE ON FUNCTION ershkus_fn_geompoly(geometry[]) TO ershkus;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment