[postgis-users] X() function working for POINTs and MULTIPOINTs

Bernhard Reimar Hoefle Bernhard.Hoefle at uibk.ac.at
Sat Mar 25 01:27:06 PST 2006


> Hi, Bernhard,
>
> Bernhard Reimar Hoefle wrote:
>
> > The PostGIS x() function does not support MULTIPOINTs and the geometryN()
> does
> > not support POINTs.
> >
> > select x('MULTIPOINT(1 1 1,2 2 2)'::GEOMETRY);
> > ERROR:  Argument to X() must be a point
> > ERROR:  Argument to X() must be a point
>
> You might want to write your own set returning plpgsql function. This
> way, it is even possible that select your_x('MULTIPOINT(...)') returns
> two rows, 1 and 2.
>
> HTH,
> Schabi

Hi Markus!
I was thinking of plpgsql functions. How would such a function look like? I
don't know how to write a plpgsql function which works like the dump()
function. I just know to write a function like SELECT * from
your_x('MULTIPOINT(...)')

But my problem is performance and the C functions are quite faster than the
procedural scripts.

Indeed, I do need a function like

SELECT id, your_x('MULTIPOINT(1 1 1, 2 2 2)') from table1;

returning

id|x
-----
1|1
1|2

I was thinking of adapting the C code of the dump() function for my purpose.
What do the PostGIS insiders think is the fastest solution for my problem?
The easiest solution is a combined usage of geometryn() and x(), or writing a
plpgsql script which checks how many geometries are in the MULTIPOINT object
and  loops over the geometries with returning the individual values.

Bernhard H.



More information about the postgis-users mailing list