Quantcast

Keeping vertices from lines in order... .

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Keeping vertices from lines in order... .

Stephen V. Mather

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

[hidden email]
clevelandmetroparks.com

 

 

 

 


_______________________________________________
postgis-users mailing list
[hidden email]
http://postgis.refractions.net/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Keeping vertices from lines in order... .

Nicolas Ribot-2
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 <[hidden email]> 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?

 

 

 

 

 

http://www.clemetparks.com/images/esig/cmp-ms-90x122.pngStephen Mather
Geographic Information Systems (GIS) Manager
<a href="tel:%28216%29%20635-3243" value="+12166353243" target="_blank">(216) 635-3243

[hidden email]
clevelandmetroparks.com

 

 

 

 


_______________________________________________
postgis-users mailing list
[hidden email]
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
[hidden email]
http://postgis.refractions.net/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Keeping vertices from lines in order... .

Stephen V. Mather

Ah, and I see it’s a 1.5 feature.  Thank you.

 

Steve

 

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

[hidden email]
clevelandmetroparks.com

 

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Nicolas Ribot
Sent: Thursday, February 09, 2012 4:40 PM
To: [hidden email]; PostGIS Users Discussion
Subject: Re: [postgis-users] Keeping vertices from lines in order... .

 

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 <[hidden email]> 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?

 

 

 

 

 

http://www.clemetparks.com/images/esig/cmp-ms-90x122.pngStephen Mather
Geographic Information Systems (GIS) Manager
<a href="tel:%28216%29%20635-3243" target="_blank">(216) 635-3243

[hidden email]
clevelandmetroparks.com

 

 

 

 


_______________________________________________
postgis-users mailing list
[hidden email]
http://postgis.refractions.net/mailman/listinfo/postgis-users

 


_______________________________________________
postgis-users mailing list
[hidden email]
http://postgis.refractions.net/mailman/listinfo/postgis-users
Loading...