Sep
19
2016
by eidam

some postgresql snippets

making polygon from array of points:

ST_MakePolygon(ST_MakeLine(sha));

 

if line is not closed:

ST_MakePolygon(ST_AddPoint(ST_MakeLine(sha), ST_StartPoint(ST_MakeLine(sha))));

 

turning geom_dump setof into array:

gs1 = array(SELECT geom FROM ST_DumpPoints(ge1));

 

create empty array / truncate array:

empty_array¬†:= ‘{}’;

 

append to array:

bs = array_append(bs, e[1]);

 

order array:

array(SELECT unnest(szs) AS x ORDER BY x)

 

average of array:

average = (SELECT avg(x) FROM unnest(szs) AS x)

 

uniq elements in array:

SELECT array_agg(DISTINCT c1) FROM unnest(ARRAY[1234,5343,6353,1234,1234]) t(c1)

 

multiline comment

/*

b = ST_Split(ST_Buffer(d, buf, ‘endcap=flat join=round’), d);

*/