[postgis-users] Keeping vertices from lines in order... .

Nicolas Ribot nicolas.ribot at gmail.com
Thu Feb 9 13:40:06 PST 2012


Hi,

The new st_dumppoints() function may be useful in your case. It returns an
array of (path, point) that represents the line vertices:

select st_dumppoints('LINESTRING(0 0, 1 1, 2 2)'::geometry);

                  st_dumppoints
--------------------------------------------------
 ({1},010100000000000000000000000000000000000000)
 ({2},0101000000000000000000F03F000000000000F03F)
 ({3},010100000000000000000000400000000000000040)
(3 rows)

Nicolas

On 9 February 2012 21:57, Stephen V. Mather <svm at clevelandmetroparks.com>wrote:

>  Hi All,****
>
>                 If I’m converting from a line to its vertices, I use
> something like this (ala the postgis docs):****
>
> ** **
>
> SELECT ****
>
>    ST_PointN(****
>
>                   the_geom,****
>
>                   generate_series(1, ST_NPoints(the_geom))****
>
>    )****
>
> FROM ms_trails_test AS foo;****
>
> ** **
>
> Now, if I want to make sure I keep all those vertices in order for later,
> I better give them an id, so here’s my original cludge:****
>
> ** **
>
> SELECT ****
>
>    ST_PointN(****
>
>                   the_geom,****
>
>                   generate_series(1, ST_NPoints(the_geom))****
>
>    ),****
>
>                 generate_series(1, ST_NPoints(the_geom)) + foo.gid * 100000
> ****
>
> FROM ms_trails_test AS foo;****
>
> ** **
>
> Which is fine for most cases, but not really a general solution… .****
>
> Better yet, I’ll just keep my original gid as the feature id and have a
> separate vertex id:****
>
> ** **
>
> SELECT ****
>
>    ST_PointN(****
>
>                   the_geom,****
>
>                   generate_series(1, ST_NPoints(the_geom))****
>
>    ),****
>
>                 gid as feature_id,****
>
>                 generate_series(1, ST_NPoints(the_geom)) as vertex_id****
>
> FROM ms_trails_test AS foo;****
>
> ** **
>
> Thus, I can play with the points and reassemble them back into lines
> later.  But, it seems inefficient to run generate_series twice.  Is this
> the best way?****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> **[image: http://www.clemetparks.com/images/esig/cmp-ms-90x122.png]**Stephen
> Mather
> Geographic Information Systems (GIS) Manager
> (216) 635-3243****
>
> svm at clevelandmetroparks.com
> clevelandmetroparks.com <http://www.clemetparks.com/>****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120209/48a6329b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 3772 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120209/48a6329b/attachment.png>


More information about the postgis-users mailing list