<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:st1="urn:schemas-microsoft-com:office:smarttags" 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 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
 namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="place"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=blue>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Ellipses can be made directly using Affine
transformations.  The idea is to create a circle (buffer), distort along
the x & y axis (scale), rotate to the correct angle and then transform to
the final location.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>To mimic your parameters an ellipse is<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>translate(rotate(scale(buffer(makepoint(‘0’,’0’),1,slices/4),a,b),alpha),cx,cy)<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Note the buffer function has an optional
parameter that defines the number of line segments for a quarter circle (thus
the slices/4 – the default is 8)<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>You can also rotate the ellipse thru an
angle alpha (radians).<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>The above should be much faster.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Bruce Rindahl<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=3 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
postgis-users-bounces@postgis.refractions.net [mailto:postgis-users-bounces@postgis.refractions.net]
<b><span style='font-weight:bold'>On Behalf Of </span></b>marco vieira<br>
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, March 08, 2007
5:54 AM<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">PostGIS
 Users Discussion</st1:PersonName><br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [postgis-users] How
to add circle to Postgis database?</span></font><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>I wrote this function to
draw ellipses (or circles) in PG.<br>
Feel free to make changes and send to the list.<br>
<br>
Parameters:<br>
cx,cy: Center of ellipse<br>
a: major semi-axis<br>
b: minor semi-axis<br>
slices: number of vertices of polygon that define the ellipse. As big as this
value smoothed is the curve. <br>
<br>
-- Function: make_ellipse(cx float8, cy float8, a float8, b float8, slices
float8)<br>
<br>
-- DROP FUNCTION make_ellipse(cx float8, cy float8, a float8, b float8, slices
float8);<br>
<br>
CREATE OR REPLACE FUNCTION make_ellipse(cx float8, cy float8, a float8, b
float8, slices float8) <br>
  RETURNS geometry AS<br>
$BODY$<br>
declare<br>
    cx alias for $1;<br>
    cy alias for $2;<br>
    a alias for $3;<br>
    b alias for $4;<br>
    slices alias for $5;<br>
    i float;<br>
    geom geometry;<br>
begin<br>
    i := 0.0;<br>
    execute 'create table tempo(ii float,the_geom geometry) with
oids;';<br>
    WHILE i < 2.0*pi() LOOP<br>
    execute 'insert into tempo select
'||i||'::float,makepoint('||cx+a*cos(i)||','||cy+b*sin(i)||');'; <br>
    i := i+2.0*pi()/slices;<br>
    END <st1:place w:st="on">LOOP</st1:place>;<br>
    execute 'select
setsrid(makepolygon(makeline(the_geom)),4170) from tempo;' into geom;<br>
    execute 'drop table tempo;';<br>
    return geom;<br>
end; <br>
$BODY$<br>
  LANGUAGE 'plpgsql' VOLATILE;<br>
ALTER FUNCTION make_ellipse(cx float8, cy float8, a float8, b float8, slices
float8) OWNER TO marco;<br>
GRANT EXECUTE ON FUNCTION make_ellipse(cx float8, cy float8, a float8, b
float8, slices float8) TO public; <br>
<br>
<br>
<o:p></o:p></span></font></p>

<div>

<p class=MsoNormal><span class=gmailquote><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>2007/3/7, Brent Wood <<a
href="mailto:pcreso@pcreso.com">pcreso@pcreso.com</a>>:</span></font></span><o:p></o:p></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
<br>
<br>
OK, I've trimmed all the other content, but my request is slightly off the main<br>
subject.<br>
<br>
Does anyone have any comments/advice on what I am doing in this subject area?<br>
The discusison so far suggests I could usefully learm something here :-) <br>
<br>
<br>
So far I've used a local custom equal area projection (Albers EA from memory) I<br>
created for my purposes.<br>
<br>
I was looking at the recorded start positions for fishing trawls along with the<br>
distance towed and gear width to derive an estimated swept area held as a <br>
circle centred on the start point. As I want the circles to represent a<br>
comparable area whether they at lat 20S or 60S, I used an equal area projection<br>
to create them.<br>
<br>
Mu limited understanding was that despite the circles being defined by a <br>
radius, an equal area was better than equidistant for this.<br>
<br>
I'm storing them as lat/long (EPSG:4326 projection with longs 0-360 as they<br>
cross the 180 meridian... sigh...). In this projection the circles display as <br>
ellipses, exactly as they should, but this does confuse some around here :-)<br>
<br>
<br>
Is there a better way to achieve this?<br>
<br>
Thanks,<br>
<br>
  Brent<br>
_______________________________________________<br>
postgis-users mailing list <br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users
</a><o:p></o:p></span></font></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
<br clear=all>
<br>
-- <br>
Marco Vieira<br>
+55 21 9499-6800<br>
e-mail: <a href="mailto:maovieira@gmail.com">maovieira@gmail.com</a> <o:p></o:p></span></font></p>

</div>

</body>

</html>