[postgis-devel] function ST_Split(geom, multi geom)

Rémi Cura remi.cura at gmail.com
Fri Oct 11 08:30:16 PDT 2013


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



--creating a simple wrapper around ST_Split to allow splitting line by
multipoints
DROP FUNCTION IF EXISTS public.rc_Split_multi(input_geom geometry ,blade
geometry);
 CREATE FUNCTION public.rc_Split_multi(input_geom geometry ,blade geometry)
  RETURNS geometry AS
 $BODY$
--this function is a wrapper around the function ST_Split to allow
splitting mutli_lines with multi_points
 --
    DECLARE
result geometry;
 simple_blade geometry;
blade_geometry_type text := GeometryType(blade); geom_geometry_type text :=
GeometryType(input_geom);
 blade_coded_type SMALLINT; geom_coded_type SMALLINT;
    BEGIN

 --finding type of input : mixed type are not allowed
--if type is not multi, simply splitting and returning result

IF blade_geometry_type NOT ILIKE 'MULTI%' THEN
--RAISE NOTICE 'input geom is simple, doing regular split';
 RETURN ST_Split(input_geom,blade);
ELSIF blade_geometry_type ILIKE '%POINT' THEN
 blade_coded_type:= 1;
ELSIF blade_geometry_type ILIKE '%LINESTRING' THEN
 blade_coded_type:= 2;
ELSIF blade_geometry_type ILIKE '%POLYGON' THEN
 blade_coded_type:= 3;
ELSE
RAISE NOTICE 'mutliple input geometry types for the blade : should be
homogenous ';
 RETURN NULL;
END IF;

IF geom_geometry_type ILIKE '%POINT' THEN
 geom_coded_type:= 1;
ELSIF geom_geometry_type ILIKE '%LINESTRING' THEN
 geom_coded_type:= 2;
ELSIF geom_geometry_type ILIKE '%POLYGON' THEN
 geom_coded_type:= 3;
ELSE
RAISE NOTICE 'mutliple input geometry types for the geom: should be
homogenous ';
 RETURN NULL;
END IF;

result := input_geom;
 --Loop on all the geometry in the blade
FOR simple_blade IN SELECT (ST_Dump(ST_CollectionExtract(blade,
blade_coded_type))).geom
 LOOP
result:=
ST_CollectionExtract(ST_Split(result,simple_blade),geom_coded_type);
 END LOOP;
RETURN result;
    END;
 $BODY$
LANGUAGE plpgsql IMMUTABLE;
----
 --Testing the function
SELECT ST_AsText(rc_Split_multi(geom, blade))
 FROM (
SELECT ST_GeomFromText('Multilinestring((-3 0, 3 0),(-1 0,1 0))') AS geom,
 ST_GeomFromText('MULTIPOINT((-0.5 0),(0.5 0))') AS blade
--ST_GeomFromText('POINT(-0.5 0)') AS blade
 --ST_GeomFromText('MULTILINESTRING((0 1, 0 -1),(0 2,0 -2))') AS blade
--ST_GeomFromText('MULTIPOLYGON(((0 1,0 -1 ,1 -1,0 1)),((0 2,0 -2,1 -2,0
2)))') AS blade
 ) AS toto





2013/10/10 Sandro Santilli <strk at keybit.net>

> On Thu, Oct 10, 2013 at 06:20:57PM +0200, Rémi Cura wrote:
> > Hey,
> > I wrote a (simple) wrapper around ST_Split to enable splitting of mutli
> > geometry with multi geometry.
> > Any reason why ST_Split forbids splitting line with multipoints?
>
> No reason, just haven't been implemented.
> If you want to contribute your wrapper it could be a first implementation.
> Ideally it would be in C but we can always have a script version in 2.2
> and improve over time in that branch...
>
> --strk;
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20131011/847deca7/attachment.html>


More information about the postgis-devel mailing list