function ST_Split(geom, multi geom)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

function ST_Split(geom, multi geom)

Rémi Cura
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?

Cheers,

Rémi-C

_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: function ST_Split(geom, multi geom)

Sandro Santilli-2
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
[hidden email]
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: function ST_Split(geom, multi geom)

Rémi Cura
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 <[hidden email]>
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
[hidden email]
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel


_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel