<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=WordSection1>
<p class=MsoNormal><span style='color:#1F497D'>Here is a sample function to help
illustrate the issue (you can perform a simple test by calling ‘Select
wedgefunc(1,1,1) as test;’):<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>CREATE OR REPLACE FUNCTION
wedgefunc(outerradius float, startangle float, openingangle float)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> RETURNS text AS<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>$BODY$<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> DECLARE<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> startchord geometry;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> midchord geometry;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> endchord geometry;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> revstartchord geometry;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> outerarc text;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> outerarcline geometry;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> polyborder geometry;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> poly geometry;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> BEGIN<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> -- Rotate a horizontal line to
form chords - the 'mid' chord is to help form the CIRCULARLINESTRING<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> startchord :=
st_rotate(st_makeline(st_point(0,0),st_point(outerradius,0)),startangle);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> midchord :=
st_rotate(st_makeline(st_point(0,0),st_point(outerradius,0)),startangle + (.5 *
openingangle));<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> endchord :=
st_rotate(st_makeline(st_point(0,0),st_point(outerradius,0)),startangle +
openingangle);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --Make a reversal of the start
chord - just in case the points need to be in order when putting together the
poly<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> revstartchord :=
st_reverse(startchord); <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --Create an arc line by
passing the endpoints of the endchord, midchord, and startchord<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> outerarc :=
'CIRCULARSTRING('||st_x(st_endpoint(endchord))||'
'||st_y(st_endpoint(endchord))||','||st_x(st_endpoint(midchord))||'
'||st_y(st_endpoint(midchord))||','||st_x(st_endpoint(startchord))||'
'||st_y(st_endpoint(startchord))||')';<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> outerarcline :=
st_curvetoline(outerarc);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --Create the single LINESTRING
representing the border by combining the individual LINESTRINGS<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> polyborder :=
st_union(st_union(revstartchord,endchord),outerarcline);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --polyborder :=
st_collect(st_collect(revstartchord,endchord),outerarcline);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --Debugging<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --return
st_astext(startchord);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --return
st_astext(midchord);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --return
st_astext(endchord);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --return
st_astext(revstartchord);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --return
st_astext(outerarcline);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --return
st_astext(polyborder);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> --Create the POLYGON geometry
and return it <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> poly :=
st_polygon(polyborder,-1);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> return
st_astext(poly);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> END;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> $BODY$<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> LANGUAGE 'plpgsql' IMMUTABLE;<o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>