[postgis-users] How to add circle to Postgis database?

marco vieira maovieira at gmail.com
Thu Mar 8 04:53:46 PST 2007


I wrote this function to draw ellipses (or circles) in PG.
Feel free to make changes and send to the list.

Parameters:
cx,cy: Center of ellipse
a: major semi-axis
b: minor semi-axis
slices: number of vertices of polygon that define the ellipse. As big as
this value smoothed is the curve.

-- Function: make_ellipse(cx float8, cy float8, a float8, b float8, slices
float8)

-- DROP FUNCTION make_ellipse(cx float8, cy float8, a float8, b float8,
slices float8);

CREATE OR REPLACE FUNCTION make_ellipse(cx float8, cy float8, a float8, b
float8, slices float8)
  RETURNS geometry AS
$BODY$
declare
    cx alias for $1;
    cy alias for $2;
    a alias for $3;
    b alias for $4;
    slices alias for $5;
    i float;
    geom geometry;
begin
    i := 0.0;
    execute 'create table tempo(ii float,the_geom geometry) with oids;';
    WHILE i < 2.0*pi() LOOP
    execute 'insert into tempo select
'||i||'::float,makepoint('||cx+a*cos(i)||','||cy+b*sin(i)||');';
    i := i+2.0*pi()/slices;
    END LOOP;
    execute 'select setsrid(makepolygon(makeline(the_geom)),4170) from
tempo;' into geom;
    execute 'drop table tempo;';
    return geom;
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION make_ellipse(cx float8, cy float8, a float8, b float8, slices
float8) OWNER TO marco;
GRANT EXECUTE ON FUNCTION make_ellipse(cx float8, cy float8, a float8, b
float8, slices float8) TO public;



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



-- 
Marco Vieira
+55 21 9499-6800
e-mail: maovieira at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070308/de45935e/attachment.html>


More information about the postgis-users mailing list