<div dir="ltr">Thanks Remi-C and Hugues for your suggestions, they got me what I needed!<div><br></div><div>I first tried Remi-C's example, since I was curious about how it would turn out. It gave me an error mentioning that it could not convert GeometryCollection to LineString. This error brought me back to what Hugues mentioned. So I used ST_Summary() to verify the GeometryCollections, which appeared to be empty (0 elements), and mixed in I noticed the LineStrings, MultiLineStrings. Since the Collections seemed to be empty I opted to separate out the linestrings I using a function Hugues mentioned ST_GeometryType()</div><div><br></div><div>Specifically I used:</div><div><div>ST_GeometryType(geom) like '%Line%' </div></div><div><br></div><div>to get both linestring and multilinestrings.</div><div><br></div><div>In the end it took 2 statements, even though I knew someone much more proficient then myself could do it in one.</div><div><br></div><div>My final statements where:</div><div><div>#create table public.temp_trail_div1 as select st_intersection(t.geom, d.geom) as geom,t.trails_id, <a href="http://d.id">d.id</a> as trail_system from public.temp_trails as t, public.divisions as d;<span class=""> </span></div></div><div><br></div><div><div>#create table public.temp_trail_div_sep as select * from public.temp_trail_div1 where ST_GeometryType(geom) like '%Line%';</div></div><div><br></div><div>This seems to have done the trick, for now. Could someone enlighten me on how that might be done in one statement?</div><div><br></div><div>Thanks again,</div><div>Garret</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 17, 2016 at 5:45 AM, Rémi Cura <span dir="ltr"><<a href="mailto:remi.cura@gmail.com" target="_blank">remi.cura@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">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"><div><div class="h5">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></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><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><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></div></div>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">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>
<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>