<div dir="ltr">Hey,<div><br></div><div>I'm working with curves,</div><div>and I can't find a constructor except passing by WKT then GeomFromText.</div><div><br></div><div><br></div><div>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.</div>
<div><br><b>This is very dirty</b>, does anybody have better suggestion?</div><div><br></div><div>Rémi-C</div><div><br></div><div>The function and test code :</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><br></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div>DROP FUNCTION IF EXISTS public.rc_MakeArc(p1 geometry, p2 geometry, p3 geometry);</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>CREATE FUNCTION public.rc_MakeArc(p1 geometry, p2 geometry, p3 geometry)</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>RETURNS geometry AS</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><div><span class="" style="white-space:pre"> </span>$BODY$</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>--this function create a curve geometry based on input 3 points. Points are supposed to be in the natural order along the curve</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>DECLARE </div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><div><span class="" style="white-space:pre"> </span>result geometry := NULL;</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>t text;</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>query text;</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><div><span class="" style="white-space:pre"> </span>BEGIN</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>--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</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>RETURN geometry( </div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><div><span class="" style="white-space:pre"> </span>set_byte(</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>ST_AsBinary(</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>ST_MakeLine(ARRAY[p1,p2,p3])</div></div></div></blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>)::bytea</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><div><span class="" style="white-space:pre"> </span>,1,8)</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>);</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>END ;</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><div><span class="" style="white-space:pre"> </span>$BODY$</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>LANGUAGE plpgsql IMMUTABLE;</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>----</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><div><span class="" style="white-space:pre"> </span>SELECT ST_AsText(public.rc_MakeArc(</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>'point(1 1)'::geometry,--p1 geometry</div>
</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>'point(0 0)'::geometry,-- p2 geometry</div></div></div></blockquote>
<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><span class="" style="white-space:pre"> </span>'point(1 -1)'::geometry -- p3 geometry</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div><div><div><span class="" style="white-space:pre"> </span>))</div></div></div></blockquote></blockquote></div>