[postgis-devel] Is there a reason those GArray functions aren't documented?

Obe, Regina robe.dnd at cityofboston.gov
Tue Jul 1 03:48:46 PDT 2008


I was assuming it is because we consider them internal like functions
since they are used to form the aggregate functions and may be something
that changes in the future.  

I finally found a use for them somewhat directly and felt a little dirty
using them.

Case in point.  Someone asked me how to formulate a polygon if he has a
known finite set of points he pulled out of a hat (well a hat that forms
points forming a closed ring - not coming from an aggregate rollup)

After looking thru the docs and the closest thing I could come up with
using documented
functions was

ST_MakePolygon(ST_LineFromMultiPoint(multipoint))

which would require me to get my points into a multipoint (using yet
another undocumented GArray function or using a messy union all).


I then found all these undocumented garray functions used to form the
aggregates which allowed me to write a function using ST_MakeLineGArray.

CREATE OR REPLACE FUNCTION upgis_makepolygonfrompoints(points
geometry[])
  RETURNS geometry AS
$BODY$
	SELECT ST_MakePolygon(ST_MakeLine_GArray($1))

$BODY$
  LANGUAGE 'sql' IMMUTABLE;

COMMENT ON FUNCTION upgis_makepolygonfrompoints(geometry[]) IS 'Takes an
array of points and returns a polygon formed from those points.  
	USAGE: SELECT
upgis_makepolygonfrompoints(ARRAY[ST_MakePoint(1,1), ST_MakePoint(2,1),
ST_MakePoint(2,0), ST_MakePoint(1,0), ST_MakePoint(1,1)]) ';


Which allows me to do something perverse like this

SELECT upgis_makepolygonfrompoints(ARRAY[ST_MakePoint(1,1),
ST_MakePoint(2,1), ST_MakePoint(2,0), ST_MakePoint(1,0),
ST_MakePoint(1,1)]);


Thanks,
Regina

-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.




More information about the postgis-devel mailing list