<div dir="ltr"><div><div><div>Sorry it didn't work :-( . Can you check that temp_id is not always 1?<br><br></div>It is more that this approach is flawed <br>_depending on the raster resolution and the small turn in your line (fixe = simplify line).<br>
</div><div>_anyway, you are constructing a new line from centroid, and not putting the height information on the old line (see end of the message)).<br></div><div><br></div>Can you try to spatially filter your line : with the same code, change just the beginning <br>
<br>WITH line AS<br>
-- From an arbitrary line<br>
(SELECT ST_Simplify(geom,2*your_raster_cell_size) from foot_cl where (sheet='AT24' AND sid=463)),<br>
cells AS ....<br><br><br></div><div>A safer way to do it would be for instance:<br></div><div>find the pixel under the line<br></div><div>transform those pixels into polygons along with height value (ST_PixelAsPolygons)<br>
</div><div>cut the line with those polygons (create new points at each enter/exit of pixels)<br></div><div>add the height information of each polygon into the line parts.<br></div><div>renode the line by assembling in the correct order the line parts.<br>
<br>A suggestion of code for it:<br><br>-----------------------------<br>WITH rast AS ( --getting a raster, and a diag line for this raster<br>        SELECT *  --, ST_Intersection(rast,line)--unnest(regexp_split_to_array(ST_Summary(rast),'\n'))<br>
        FROM test_raster.test_temp_raster,ST_SetSRID(ST_GeomFromText('Linestring(651050. 6860677,651055 6860682)') ,931008) AS line<br>        WHERE rid = 273143<br>        LIMIT 1<br>    )<br>    ,pix_under_line AS ( --get the pixels that are covered by the line, transform the pixels into square (pylgon), keep the value of the band 1 (heigth is supposed to be here)<br>
                        --this is suboptimal and could be replacer by using st_intersection<br>        SELECT pix.*, line <br>        FROM rast,ST_PixelAsPolygons(rast,1) AS pix<br>        WHERE  ST_Intersects(pix.geom,line)=TRUE<br>
            --AND pix.val!=0 --if raster from interpolation, no need to keep wrong parts<br>    )<br>    ,cutting_line_with_pix AS (--splitting the line with the pixels in order to obtain multiple parts of the line, each covering one pixel <br>
                            --(see <a href="https://github.com/Remi-C/PPPP_utilities/tree/master/postgis">https://github.com/Remi-C/PPPP_utilities/tree/master/postgis</a> for rc_split_multi)<br>        SELECT  ST_Dump(rc_Split_multi(min(line), ST_Union(ST_Boundary(geom)),0.01)) AS splitted_line<br>
        FROM pix_under_line<br>    )<br>    ,splitted_line AS ( --filtering the obtained parts of line to remove ghost created by precision error and point-line<br>        SELECT (splitted_line).path, (splitted_line).geom, ST_AsText( (splitted_line).geom)<br>
        FROM cutting_line_with_pix<br>        WHERE ST_Length((splitted_line).geom)>0.001<br>    )<br>    ,sl_and_pix AS ( --for each parts of line, get the pixel polygon that it covers, along with the value of the pixel. Add this value to the parts of line<br>
        SELECT DISTINCT ON (path) sl.*,  pul.*, ST_AddMeasure(sl.geom,pul.val,pul.val) AS l_heigth<br>        FROM splitted_line AS sl, pix_under_line AS pul<br>        WHERE  ST_Intersects(sl.geom,pul.geom)=TRUE<br>        ORDER BY path ASC, ST_Length(sl.geom) DESC<br>
    )--fusion the line parts to create a single line (don't use ST_Union, it drops the M value)<br>    SELECT ST_Astext(ST_MakeLine(l_heigth ORDER BY path ASC) )  <br>    FROM sl_and_pix<br>-----------------------------<br>
</div><div><br></div>Cheers,<br>Rémi-C<br><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-05-13 1:08 GMT+02:00 georgew <span dir="ltr"><<a href="mailto:gws293@hotmail.com" target="_blank">gws293@hotmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">thanks Remi, attached is the result after running your code, no change<br>
unfortunately.<br>
I had to make some slight changes to the code to make it work. The image has<br>
the code.<br>
However you also say that my approach is not as robust as it could be. Any<br>
suggestions on how to make it more robust?<br>
<br>
<br>
<br>
newline.png <<a href="http://postgis.17.x6.nabble.com/file/n5006277/newline.png" target="_blank">http://postgis.17.x6.nabble.com/file/n5006277/newline.png</a>><br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://postgis.17.x6.nabble.com/ST-MakeLine-woes-tp5006266p5006277.html" target="_blank">http://postgis.17.x6.nabble.com/ST-MakeLine-woes-tp5006266p5006277.html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the PostGIS - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br></div>