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

Stephen V. Mather svm at clevelandmetroparks.com
Thu Feb 9 12:57:52 PST 2012


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?

 

 

 

 

 

http://www.clemetparks.com/images/esig/cmp-ms-90x122.pngStephen Mather
Geographic Information Systems (GIS) Manager
(216) 635-3243

svm at clevelandmetroparks.com
 <http://www.clemetparks.com/> clevelandmetroparks.com

 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120209/13be7896/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/13be7896/attachment.png>


More information about the postgis-users mailing list