4

I have a line in a PostGIS table test_line. I want to extract it's nodes into a multipoint geometry.

I tried the following:

SELECT ST_Collect((ST_DumpPoints(the_geom)).geom) FROM test_line;

But it gives me the error ERROR: set-valued function called in context that cannot accept a set.

What do I have to change in order to get it to work?

  • I'm curious to know whether and how you want to scale up your test case. – raphael Dec 27 '14 at 3:09
3

I had a similar problem and this mailing list post helped me:

http://lists.osgeo.org/pipermail/postgis-users/2010-June/026887.html

The solution they came up with is as follows:

SELECT gid, ST_AsText(replace(ST_AsEWKT(geom), 'LINESTRING',
'MULTIPOINT')::geometry)
FROM
 (SELECT 1 as gid, 'LINESTRING (0 0, 0 3, 3 4)'::geometry AS geom
  UNION ALL
  SELECT 2 as gid, 'LINESTRING (1 1, 2 6, 7 7)'::geometry AS geom) AS g;
1

ST_Dump is returning multiple values for one row, which cannot be nested within the ST_Collect() function, so you must separate things out using a sub-query.

 SELECT ST_Collect(the_geom2) 
 FROM (
       SELECT (ST_DumpPoints(the_geom)).geom AS the_geom2 
       FROM test_line) foo;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.