Hi,<div><br></div><div>If the points are ordered in the CSV file, you could add a column with an autoincremented ID value before loading it into Postgis (with Excel or Awk). Then order the table by this ID and group by profile to create linestrings.</div>
<div>The order of points in the CSV file will be kept to generate linestrings:</div><div><br></div><div>insert into lines </div><div>with t as (select * from tmp order by profile, id) </div><div>select profile, st_makeline(the_geom))  from t group by profile;<br>
<br></div><div>Nicolas</div><div><br><div class="gmail_quote">On 2 October 2011 15:44, Gery . <span dir="ltr"><<a href="mailto:gamejihou@hotmail.com">gamejihou@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Hello Andy,<br>
<br>
Thanks for your answer, I updated my table, now it looks like:<br>
<br>
====<br>
 id  | profile  | longitude | latitude |                        geom                       <br>
-----+----------+-----------+----------+----------------------------------------------------<br>
   0 | HH00-23  |  -80.2835 | -8.05167 | 0101000020E6100000A01A2FDD241254C05F5E807D741A20C0<br>
   1 | HH00-23  |   -80.633 | -8.20033 | 0101000020E61000008D976E12832854C0BBD05CA7916620C0<br>
   2 | HH00-22  |  -80.6027 |  -8.2655 | 0101000020E6100000265305A3922654C00E2DB29DEF8720C0<br>
   3 | HH00-22  |  -80.2018 |   -8.094 | 0101000020E61000004D158C4AEA0C54C0E3A59BC4203020C0<br>
...<br>
...etc<br>
====<br>
<br>
I tried your code below but didn't work, but I think it is getting closer, how could I update it with this new ID field in order of getting what I want?<br>
<br>
 <br>
<br>
> Date: Sun, 2 Oct 2011 07:51:02 -0500<br>
> From: <a href="mailto:andy@squeakycode.net">andy@squeakycode.net</a><br>
> To: <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
> CC: <a href="mailto:gamejihou@hotmail.com">gamejihou@hotmail.com</a><br>
> Subject: Re: [postgis-users] csv table to points and then create line based on        same name<br>
<div><div></div><div class="h5">><br>
> On 10/02/2011 06:41 AM, Gery . wrote:<br>
> ><br>
> > Hello,<br>
> ><br>
> > I'm new around here and after working a while with postgis/postgresql, I'd like to get something that up to know is advanced for me. Please don't get mad at me if this is a stupid question =)<br>
> ><br>
> > I want to create a line table based on a point table, which it is composed of rows with equal names, this is an example of this csv table:<br>
> ><br>
> > ===<br>
> > PROFILE,LONGITUDE,LATITUDE<br>
> > HH00-23,-80.2835,-8.05167<br>
> > HH00-23,-80.633,-8.20033<br>
> > HH00-22,-80.6027,-8.2655<br>
> > HH00-22,-80.2018,-8.094<br>
> > ...<br>
> > ...<br>
> > ===<br>
> ><br>
> > I loaded this csv table into my database without problems, so this is how it looks like:<br>
> ><br>
> > ===<br>
> > profile | longitude | latitude | geom<br>
> > ----------+-----------+----------+----------------------------------------------------<br>
> > HH00-23 | -80.2835 | -8.05167 | 0101000020E6100000A01A2FDD241254C05F5E807D741A20C0<br>
> > HH00-23 | -80.633 | -8.20033 | 0101000020E61000008D976E12832854C0BBD05CA7916620C0<br>
> > HH00-22 | -80.6027 | -8.2655 | 0101000020E6100000265305A3922654C00E2DB29DEF8720C0<br>
> > HH00-22 | -80.2018 | -8.094 | 0101000020E61000004D158C4AEA0C54C0E3A59BC4203020C0<br>
> > ...<br>
> > ...<br>
> > ===<br>
> ><br>
> > now comes the part I don't know how to solve it, I want to get a table like this:<br>
> ><br>
> > ===<br>
> > profile | comments | geom<br>
> > -------------------------------------------------------------<br>
> > HH00-23 | some stuff | "HERE THE GEOMETRY SHOULD BE A LINE!"<br>
> > HH00-22 | some stuff | "HERE THE GEOMETRY SHOULD BE A LINE!"<br>
> > ...<br>
> > ...<br>
> > ===<br>
> ><br>
> > the case is that I have these points (from the csv table) in order, so, a straight line should be build after connecting the points. Here I showed just two pairs of points in each case, but I have also in that table 6 to 10 points with the same profile name. I did this in arcgis manually and it is painful, I think that postgis is definitively more practice.<br>

> ><br>
> > Any hint is very welcome,<br>
> ><br>
> > Gery<br>
><br>
> One little problem I can see is the order of the points will be undefined.  For example<br>
><br>
> HH00-23,-80,-8<br>
> HH00-23,-81,-8<br>
> HH00-23,-80,-7<br>
> HH00-23,-81.-7<br>
><br>
> after you dump theses into a table, then turn around and select them, if you dont put an order by on a select statement, then PG can return them in any order it wants.  And "order by profile" wont really help, again, those 4 points can be returned in any order.  Do you have any method of identifying the order of the points?<br>

><br>
> I assume you want to create a new table for the lines?<br>
><br>
> You can try something like this, not sure how well it'll work:<br>
><br>
> create table lines(uid serial primary key, profile text);<br>
> select AddGeometryColumn('lines', 'the_geom', -1, 'LINESTRING', 2);<br>
><br>
> insert into lines(profile, the_geom)<br>
>    select profile, ST_LineFromMultiPoint(ST_collect(the_geom))<br>
>    from point_table<br>
>    group by profile;<br>
><br>
><br>
> This is, of course, untested.<br>
><br>
> -Andy<br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br></div>