<div dir="ltr">OK , here is the straightforward code, even if it is not integrated it could be used.<br>Please tell me what is wrong/bad practice, I'm not a plpgsql guru<div>Cheers,</div><div>Rémi-C</div><div><br></div>

<div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><br></div><div><div>--creating a simple wrapper around ST_Split to allow splitting line by multipoints</div></div><div><div><span style="white-space:pre-wrap">            </span>DROP FUNCTION IF EXISTS public.rc_Split_multi(input_geom geometry ,blade geometry);</div>

</div><div><div><span style="white-space:pre-wrap">           </span>CREATE FUNCTION public.rc_Split_multi(input_geom geometry ,blade geometry)</div></div><div><div><span style="white-space:pre-wrap">                </span>  RETURNS geometry AS</div>

</div><div><div><span style="white-space:pre-wrap">           </span>$BODY$</div></div><div><div><span style="white-space:pre-wrap">            </span>--this function is a wrapper around the function ST_Split to allow splitting mutli_lines with multi_points</div>

</div><div><div><span style="white-space:pre-wrap">           </span>--</div></div><div><div><span style="white-space:pre-wrap">                </span>    DECLARE</div></div><div><div><span style="white-space:pre-wrap">                     </span>result geometry;</div>

</div><div><div><span style="white-space:pre-wrap">                   </span>simple_blade geometry;</div></div><div><div><span style="white-space:pre-wrap">                    </span>blade_geometry_type text := GeometryType(blade); geom_geometry_type text := GeometryType(input_geom);</div>

</div><div><div><span style="white-space:pre-wrap">                   </span>blade_coded_type SMALLINT; geom_coded_type SMALLINT;</div></div><div><div><span style="white-space:pre-wrap">              </span>    BEGIN</div></div><div><div><br>
</div></div><div><div><span style="white-space:pre-wrap">                       </span>--finding type of input : mixed type are not allowed</div></div><div><div><span style="white-space:pre-wrap">                      </span>--if type is not multi, simply splitting and returning result</div>

</div><div><div><br></div></div><div><div><span style="white-space:pre-wrap">                           </span>IF blade_geometry_type NOT ILIKE 'MULTI%' THEN</div></div><div><div><span style="white-space:pre-wrap">                                    </span>--RAISE NOTICE 'input geom is simple, doing regular split';</div>

</div><div><div><span style="white-space:pre-wrap">                                   </span>RETURN ST_Split(input_geom,blade);</div></div><div><div><span style="white-space:pre-wrap">                                </span>ELSIF blade_geometry_type ILIKE '%POINT' THEN</div>

</div><div><div><span style="white-space:pre-wrap">                                   </span>blade_coded_type:= 1;</div></div><div><div><span style="white-space:pre-wrap">                             </span>ELSIF blade_geometry_type ILIKE '%LINESTRING' THEN</div>
</div><div><div><span style="white-space:pre-wrap">                                   </span>blade_coded_type:= 2;</div></div><div><div><span style="white-space:pre-wrap">                             </span>ELSIF blade_geometry_type ILIKE '%POLYGON' THEN</div>
</div><div><div><span style="white-space:pre-wrap">                                   </span>blade_coded_type:= 3;</div></div><div><div><span style="white-space:pre-wrap">                             </span>ELSE</div></div><div><div><span style="white-space:pre-wrap">                                      </span>RAISE NOTICE 'mutliple input geometry types for the blade : should be homogenous ';</div>

</div><div><div><span style="white-space:pre-wrap">                                   </span>RETURN NULL;</div></div><div><div><span style="white-space:pre-wrap">                              </span>END IF;</div></div><div><div><br></div></div><div><div><span style="white-space:pre-wrap">                           </span>IF geom_geometry_type ILIKE '%POINT' THEN</div>

</div><div><div><span style="white-space:pre-wrap">                                   </span>geom_coded_type:= 1;</div></div><div><div><span style="white-space:pre-wrap">                              </span>ELSIF geom_geometry_type ILIKE '%LINESTRING' THEN</div>
</div><div><div><span style="white-space:pre-wrap">                                   </span>geom_coded_type:= 2;</div></div><div><div><span style="white-space:pre-wrap">                              </span>ELSIF geom_geometry_type ILIKE '%POLYGON' THEN</div></div>
<div><div><span style="white-space:pre-wrap">                                       </span>geom_coded_type:= 3;</div></div><div><div><span style="white-space:pre-wrap">                              </span>ELSE</div></div><div><div><span style="white-space:pre-wrap">                                      </span>RAISE NOTICE 'mutliple input geometry types for the geom: should be homogenous ';</div>

</div><div><div><span style="white-space:pre-wrap">                                   </span>RETURN NULL;</div></div><div><div><span style="white-space:pre-wrap">                              </span>END IF;</div></div><div><div><br></div></div><div><div><span style="white-space:pre-wrap">                   </span>result := input_geom;<span style="white-space:pre-wrap">                   </span></div>

</div><div><div><span style="white-space:pre-wrap">                   </span>--Loop on all the geometry in the blade</div></div><div><div><span style="white-space:pre-wrap">                   </span>FOR simple_blade IN SELECT (ST_Dump(ST_CollectionExtract(blade, blade_coded_type))).geom</div>

</div><div><div><span style="white-space:pre-wrap">                   </span>LOOP</div></div><div><div><span style="white-space:pre-wrap">                                      </span>result:= ST_CollectionExtract(ST_Split(result,simple_blade),geom_coded_type);</div>
</div><div><div><span style="white-space:pre-wrap">                   </span>END LOOP;</div></div><div><div><span style="white-space:pre-wrap">                 </span>RETURN result;</div></div><div><div><span style="white-space:pre-wrap">            </span>    END;</div>

</div><div><div><span style="white-space:pre-wrap">           </span>$BODY$</div></div><div><div><span style="white-space:pre-wrap">            </span>LANGUAGE plpgsql IMMUTABLE;</div></div><div><div><span style="white-space:pre-wrap">               </span>----</div>

</div><div><div><span style="white-space:pre-wrap">           </span>--Testing the function</div></div><div><div><span style="white-space:pre-wrap">            </span>SELECT ST_AsText(rc_Split_multi(geom, blade))</div></div><div><div>
<span style="white-space:pre-wrap">             </span>FROM (</div></div><div><div><span style="white-space:pre-wrap">                            </span>SELECT ST_GeomFromText('Multilinestring((-3 0, 3 0),(-1 0,1 0))') AS geom,</div></div><div>
<div><span style="white-space:pre-wrap">                          </span>ST_GeomFromText('MULTIPOINT((-0.5 0),(0.5 0))') AS blade</div></div><div><div><span style="white-space:pre-wrap">                          </span>--ST_GeomFromText('POINT(-0.5 0)') AS blade</div>

</div><div><div><span style="white-space:pre-wrap">                           </span>--ST_GeomFromText('MULTILINESTRING((0 1, 0 -1),(0 2,0 -2))') AS blade</div></div><div><div><span style="white-space:pre-wrap">                             </span>--ST_GeomFromText('MULTIPOLYGON(((0 1,0 -1 ,1 -1,0 1)),((0 2,0 -2,1 -2,0 2)))') AS blade</div>

</div><div><div><span style="white-space:pre-wrap">                   </span>) AS toto</div></div></blockquote></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/10/10 Sandro Santilli <span dir="ltr"><<a href="mailto:strk@keybit.net" target="_blank">strk@keybit.net</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, Oct 10, 2013 at 06:20:57PM +0200, Rémi Cura wrote:<br>
> Hey,<br>
> I wrote a (simple) wrapper around ST_Split to enable splitting of mutli<br>
> geometry with multi geometry.<br>
> Any reason why ST_Split forbids splitting line with multipoints?<br>
<br>
</div></div>No reason, just haven't been implemented.<br>
If you want to contribute your wrapper it could be a first implementation.<br>
Ideally it would be in C but we can always have a script version in 2.2<br>
and improve over time in that branch...<br>
<br>
--strk;<br>
_______________________________________________<br>
postgis-devel mailing list<br>
<a href="mailto:postgis-devel@lists.osgeo.org">postgis-devel@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel</a><br>
</blockquote></div><br></div>