[postgis-users] Converting a LineString to MultiPoint

Mike Toews mwtoews at gmail.com
Thu Jun 17 16:50:05 PDT 2010


Or, if you have version < 1.5, you could use a simple WKT hack to text
replace 'LINESTRING' with 'MULTIPOINT', since the rest is the same:

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;

Again, this is a complete hack, and assumes you have all LINESTRING
types. I use ST_AsEWKT in case you have more than 3 dimensions and/or
an SRID.

-Mike

On 17 June 2010 16:36, Mike Toews <mwtoews at gmail.com> wrote:
> If you have PostGIS 1.5, then you can use ST_DumpPoints:
> http://postgis.refractions.net/docs/ST_DumpPoints.html
>
> E.g.:
>
> SELECT gid, ST_AsText(ST_Collect(ST_AsText(geom)))
> FROM (
>  SELECT gid, (ST_DumpPoints(g.geom)).*
>  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
>  ) j
> GROUP BY gid;
>
> -Mike
>
> On 17 June 2010 14:57, Andrea Peri 2007 <aperi2007 at gmail.com> wrote:
>> Hi,
>>
>> I have a table of LineStrings, and need to create a table of MultiPoints,
>> where every multipoint is using the same vertex of a LineString.
>> There is a method to do this using only sql ?
>>
>> Thx,
>>
>> Andrea.
>>
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>



More information about the postgis-users mailing list