I am trying to create ellipses from fields in my posgres table. I found this custom Ellipse function and have been trying to tweak it to meet my needs.
Create Ellipse (x,y,rx,ry,rotation,#of segments in 1/4 of ellipse):
CREATE OR REPLACE FUNCTION Ellipse(double precision, double precision, double precision, double precision, double precision, integer)
RETURNS geometry AS
$$
SELECT ST_Translate( ST_Rotate( ST_Scale( ST_Buffer(ST_Point(0,0), 0.5, $6), $3, $4), $5), $1, $2)
$$
LANGUAGE 'sql';
My inputs into this are a lat and lon. Smajor/Sminor measurements in meters. I receive my rotation in degrees but have a written a function that has converted them to radians per the requirements as stated in some of the other forums I've seen with this similar problem. I have tweaked the above method to this:
CREATE OR REPLACE FUNCTION Ellipse2(double precision, double precision, double precision, double precision, double precision, integer)
RETURNS geometry AS
$$
SELECT ST_Translate( ST_SetSRID( ST_Rotate( ST_Scale( ST_Buffer( ST_SetSRID( ST_Point(0,0), 3395), 0.5, $6), $3, $4), $5), 4326), $1, $2)
$$
LANGUAGE 'sql';
I create the point (0,0) and then set it's SRID to 3395(world meters based system) in hopes that the follow on functions use meters when it extrapolates the smajor/sminor sides. I'm getting ellipses that are massive though (i.e. continent size not 600 meter size) I'm pretty sure my issue is with projection based units. Can someone point out to me what I am doing wrong?