[postgis-users] How to add circle to Postgis database?
Bruce Rindahl
rindahl at lrcwe.com
Fri Mar 9 10:51:25 PST 2007
Thanks!
Should we add some more functions as part of the standard package? I was
thinking of ellipse like below and rotate around a point.
Bruce
_____
From: marco vieira [mailto:maovieira at gmail.com]
Sent: Friday, March 09, 2007 11:46 AM
To: rindahl at lrcwe.com; PostGIS Users Discussion
Subject: Re: [postgis-users] How to add circle to Postgis database?
Thank's Bruce!
It is much better. I wrote this function a long time ago but it is still
useful.
2007/3/8, Bruce Rindahl < rindahl at lrcwe.com <mailto:rindahl at lrcwe.com> >:
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.
To mimic your parameters an ellipse is
translate(rotate(scale(buffer(makepoint('0','0'),1,slices/4),a,b),alpha),cx,
cy)
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)
You can also rotate the ellipse thru an angle alpha (radians).
The above should be much faster.
Bruce Rindahl
_____
From: postgis-users-bounces at postgis.refractions.net [mailto:
postgis-users-bounces at postgis.refractions.net
<mailto:postgis-users-bounces at postgis.refractions.net> ] On Behalf Of marco
vieira
Sent: Thursday, March 08, 2007 5:54 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] How to add circle to Postgis database?
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
<http://postgis.refractions.net/mailman/listinfo/postgis-users>
--
Marco Vieira
+55 21 9499-6800
e-mail: maovieira at gmail.com
_______________________________________________
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/20070309/625e930a/attachment.html>
More information about the postgis-users
mailing list