<div dir="ltr">Hey, <div>here is the function, safe for geometry collection and multilinestring as well.</div><div>It mimics ST_DumpPoints. </div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>It doesn't work on polygon as we would first need a method STDumpLines.</div>
</blockquote><div><br></div><div>Origine of segments is preserved inside the path when multi.<br>Could it be added to core ?</div><div>Shall I add a ticket?</div><div><br></div><div>Cheers,</div><div>Rémi-C</div><div><br>
</div><div>/////////////////////////////////</div><div><br></div><div><div><span class="" style="white-space:pre">    </span>DROP FUNCTION IF EXISTS public.DumpSegments(line geometry ) ;</div><div><span class="" style="white-space:pre">              </span>CREATE OR REPLACE FUNCTION public.DumpSegments(_line geometry)</div>
<div><span class="" style="white-space:pre">            </span>RETURNS SETOF geometry_dump</div><div><span class="" style="white-space:pre">                </span>AS</div><div><span class="" style="white-space:pre">         </span>$BODY$</div><div><span class="" style="white-space:pre">                     </span>--this function breaks a line into minimal segments and return it</div>
<div><span class="" style="white-space:pre">                    </span></div><div><span class="" style="white-space:pre">                   </span>DECLARE</div><div><span class="" style="white-space:pre">                    </span>_r record;</div><div><span class="" style="white-space:pre">                 </span>BEGIN</div>
<div><br></div><div><span class="" style="white-space:pre">                   </span>FOR _r in SELECT ST_Dump(ST_CollectionExtract (_line,2)) AS dp</div><div><span class="" style="white-space:pre">                     </span>LOOP</div><div><span class="" style="white-space:pre">                               </span>RETURN QUERY WITH line AS( </div>
<div><span class="" style="white-space:pre">                                    </span>SELECT --ST_GeomFromText('LINESTRING(12 1, 13 1, 14 2, 15 4)') AS line</div><div><span class="" style="white-space:pre">                                             </span>(_r.dp).path AS gpath, (_r.dp).geom AS line</div>
<div><span class="" style="white-space:pre">                                    </span>),</div><div><span class="" style="white-space:pre">                         </span>dump AS(</div><div><span class="" style="white-space:pre">                                   </span>SELECT gpath[1] AS gpath, (ST_DumpPoints(line)) as dp</div>
<div><span class="" style="white-space:pre">                                    </span>FROM line</div><div><span class="" style="white-space:pre">                          </span>),</div><div><span class="" style="white-space:pre">                         </span>segments AS (</div><div><span class="" style="white-space:pre">                                      </span>SELECT CASE WHEN gpath IS NULL THEN ARRAY[(dp).path[1]-1] ELSE ARRAY[gpath, (dp).path[1]-1] END AS path,ST_MakeLine( lag((dp).geom , 1, NULL) OVER (ORDER BY  (dp).path),(dp).geom) AS geom</div>
<div><span class="" style="white-space:pre">                                    </span>FROM dump</div><div><span class="" style="white-space:pre">                          </span>)</div><div><span class="" style="white-space:pre">                          </span>SELECT path,geom</div><div><span class="" style="white-space:pre">                           </span>FROM segments </div>
<div><span class="" style="white-space:pre">                            </span>WHEre geom  IS NOT NULL;</div><div><span class="" style="white-space:pre">                  </span>END LOOP;--loop if multi linestring</div><div><span class="" style="white-space:pre">                        </span></div>
<div><span class="" style="white-space:pre">                    </span>RETURN;</div><div><span class="" style="white-space:pre">                    </span>END;</div><div><span class="" style="white-space:pre">               </span>$BODY$</div><div><span class="" style="white-space:pre">             </span>  LANGUAGE plpgsql  IMMUTABLE STRICT;</div>
<div><br></div><div><br></div><div><span class="" style="white-space:pre">          </span></div><div><span class="" style="white-space:pre">                   </span>SELECT public.DumpSegments(line2)</div><div><span class="" style="white-space:pre">                  </span>FROM ST_GeomFromText('MULTILINESTRING((12 1, 13 1, 14 2, 15 4),(1 1, 2 2,3 3))') AS line1,ST_GeomFromText( 'LINESTRING(12 1, 13 1, 14 2, 15 4)') AS line2</div>
<div><span class="" style="white-space:pre">            </span></div></div><div><br></div><div><br></div><div><br></div><div><br></div><div>//////////////////////////////////////</div><div><br></div><div><br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2013/10/30 Rémi Cura <span dir="ltr"><<a href="mailto:remi.cura@gmail.com" target="_blank">remi.cura@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Thanks,<div>wanted to do it the clean way (geos accelerated maybe?),</div><div><br></div><div>but not so much a big deal, I'll go you way.<br><br></div><div>Cheers,</div><div>Rémi-C</div></div><div class="">
<div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">2013/10/30 Nicolas Ribot <span dir="ltr"><<a href="mailto:nicolas.ribot@gmail.com" target="_blank">nicolas.ribot@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Hi,<br>
<br>
I don't think such a function exists in postgis.<br>
(To achieve that, I usually dump line points and create new<br>
linestrings with vertices n, n+1)<br>
<br>
Nicolas<br>
<div><div><br>
On 30 October 2013 10:59, Rémi Cura <<a href="mailto:remi.cura@gmail.com" target="_blank">remi.cura@gmail.com</a>> wrote:<br>
> Hey,<br>
> is somebodyers aware of a function breaking a linestring into a set of<br>
> segments (mathematical meaning),<br>
> without introducing new points?<br>
><br>
> Cheers,<br>
><br>
><br>
> Rémi-C<br>
><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/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
_______________________________________________<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/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>