[postgis-devel] constructor for CIRCULARLINE(pt1,pt2,pt3)

Rémi Cura remi.cura at gmail.com
Wed Oct 16 05:35:59 PDT 2013


Hey,

I'm working with curves,
and I can't find a constructor except passing by WKT then GeomFromText.


I did a simple plpgsql function to try to reduce the hassle, but it is a
binary hack : changing the binary value indicating linestring to binary
value indicating circularline, according to WKB definition. It still makes
many casts.

*This is very dirty*, does anybody have better suggestion?

Rémi-C

The function and test code :


DROP FUNCTION IF EXISTS public.rc_MakeArc(p1 geometry, p2 geometry, p3
geometry);

CREATE FUNCTION public.rc_MakeArc(p1 geometry, p2 geometry, p3 geometry)

RETURNS geometry AS

$BODY$

--this function create a curve geometry based on input 3 points. Points are
supposed to be in the natural order along the curve

DECLARE

result geometry := NULL;

t text;

query text;

BEGIN

--the trick is  to create first a linestring, then to change the WKB
reprensentation, going from 2 to 8 to change from line string to
circularstring

RETURN geometry(

set_byte(

ST_AsBinary(

ST_MakeLine(ARRAY[p1,p2,p3])

)::bytea

,1,8)

);

END ;

$BODY$

LANGUAGE plpgsql IMMUTABLE;

----

SELECT ST_AsText(public.rc_MakeArc(

'point(1 1)'::geometry,--p1 geometry

'point(0 0)'::geometry,-- p2 geometry

'point(1 -1)'::geometry -- p3 geometry

))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20131016/3a207508/attachment.html>


More information about the postgis-devel mailing list