<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">Hey,</div><div class="gmail_default" style="font-family:monospace,monospace">two things : </div><div class="gmail_default" style="font-family:monospace,monospace">recent version of QGIS are boringly strict about geometry type,</div><div class="gmail_default" style="font-family:monospace,monospace">so if you want to be able to add the corresponding postgis layer to qgis, you may have to explicitely cast the result.<br>QGIS also require a unique identifier per row,</div><div class="gmail_default" style="font-family:monospace,monospace">which you can fabricate with row_number() for instance</div><div class="gmail_default" style="font-family:monospace,monospace">​​</div><div class="gmail_default" style="font-family:monospace,monospace">----------------------------------------------------------------</div>CREATE TABLE my_table AS <br>SELECT row_number() over() AS qgis_unique_id,<br>    st_intersection(t.geom, d.geom)::geometry(linestring,4326) AS geom<br>    ,t.trails_id, <a href="http://d.id">d.id</a> <br>FROM public.temp_trails as t, public.polys as d; <div class="gmail_default" style="font-family:monospace,monospace">----------------------------------------------------------------</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Cheers,</div><div class="gmail_default" style="font-family:monospace,monospace">Rémi-C</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-03-17 8:15 GMT+01:00 François Hugues <span dir="ltr"><<a href="mailto:hugues.francois@irstea.fr" target="_blank">hugues.francois@irstea.fr</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="FR" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hello,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Dis you take a look at the query result ? </span><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I think you should first try to see what is the type of geometry returned using ST_GeometryType(). You may have some geometrycollections and I’m not sure QGis can handle  it. In this case you could extract lines using ST_CollectionExtract().<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">To achieve what you want to do, you’ll be able to compare your original lines table with the result of your query using ST_Difference().<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Regards,<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hugues.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">De :</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> postgis-users [mailto:<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>] <b>De la part de</b> Garret W<br><b>Envoyé :</b> jeudi 17 mars 2016 04:11<br><b>À :</b> <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br><b>Objet :</b> [postgis-users] split line at polygon edge<u></u><u></u></span></p><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><p>Hi Ive been looking for a way to take several hundred lines and split them where they intersect a polygon while also giving them the ID of the polygon they fall in. Ive seen many posts on splitting polygons. But its been difficult for me to adapt those examples.<u></u><u></u></p><p>Ive been able to get an output from this:<u></u><u></u></p><p>select st_intersection(t.geom, d.geom),t.trails_id, <a href="http://d.id" target="_blank">d.id</a> from public.temp_trails as t, public.polys as d; <u></u><u></u></p><p>Its giving me the line and IDs that I wanted but the geom is unreadable for some reason by QGIS.<u></u><u></u></p><p>99.9% of the lines fall within a polygon. Id like to still hang on to those few lines that arent contained in a polygon. They should just be split with no ID added<u></u><u></u></p><p>Im using; postgis 2.2, postgresql 9.5<u></u><u></u></p><p>Thank you<br>Garret<u></u><u></u></p></div></div></div></div><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/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman/listinfo/postgis-users</a><br></blockquote></div><br></div>