3

Im trying to build a function to create an Ellipse without passing by classic programming language. I have these parameters stored in a custom GeoJSON. smallSide and bigSide has to be expressed in meters. Resulting geometry has to be created with EPSG 4326:

My parameters are:

 "geography" : {"type":"Ellipse",
                    "smallSide":100,
                    "bigSide" : 110,
                    "rotation" : 0,
                    "coordinates":[8.54736328125,46.37156925087649]}

Searching on web I found this solution that is very close to resolve my problem:

ST_AsEWKT(ST_Translate( ST_Rotate( ST_Scale( ST_Buffer(ST_Point(8.54736328125,46.37156925087649)::geography, 3000)::geometry, 0.3,0.5)::geometry, 0), 8.54736328125,46.37156925087649))

This function creates an Ellipse near Norway. Try with: http://geojson.io/#map=11/69.5354/11.1216

The original center is in Switzerland.

This function has 2 big problem: 1. The Ellipse is not centered in the coords; 2. I don't know how to convert xFactor/yFactor of Scale to match meters parameters;

PS. This is the WKT of above function:

SRID=4326;POLYGON((11.123273576134 69.5574277440815,11.1230606869505 69.5547928070317,11.1224064250309 69.55225640052,11.1213360407351 69.5499159578464,11.1198907409861 69.547861360983,11.1181260946945 69.5461714955871,11.1161098932273 69.5449112303195,11.1139195487472 69.544128934906,11.1116391298573 69.5438546306632,11.1093561468668 69.5440988431489,11.1071582077927 69.5448522000687,11.1051296707337 69.5460857895281,11.1033484183676 69.5477522651534,11.1018828760511 69.5497876565102,11.100789386429 69.5521138166206,11.1001100408036 69.554641414163,11.099871051113 69.5572733570283,11.1000817266595 69.5599085170987,11.1007340973332 69.5624456140896,11.1018032006992 69.5647871095818,11.1032480248444 69.5668429613212,11.105013073265 69.5685340926073,11.107030493374 69.5697954420587,11.1092226874817 69.5705784748924,11.1115053053956 69.5708530575261,11.1137905020249 69.5706086220194,11.1159903323456 69.5698545746198,11.1180201503338 69.568619932341,11.1198018783021 69.5669522018393,11.1212670184877 69.5649155445927,11.1223592894673 69.5625883002992,11.1230367854657 69.5600599653373,11.123273576134 69.5574277440815))
Jim Jones
  • 18,404
  • 3
  • 35
  • 44
EviSvil
  • 510
  • 3
  • 21
  • related: https://gis.stackexchange.com/questions/248260/making-ellipse-geometry-from-some-known-parameters-using-postgis – JGH Jun 11 '18 at 13:03
  • @JGH: The solution you linked is based on two points but I only have center and not the opposite points. – EviSvil Jun 11 '18 at 13:10

2 Answers2

0

Welcome to Stack Overflow! I'm not sure I quite understood the parameters bigSide and smallSide, but if you're only trying to create a buffer around a point using meters as parameter, you can use something like this:

SELECT 
  ST_AsText(
    ST_Rotate(
      ST_Buffer(
         ST_GeomFromText('SRID=4326;POINT(8.54736328125 46.37156925087649)')::GEOGRAPHY,3000, 'quad_segs=16')::GEOMETRY,0));

Which will draw a buffer around the given point (south of Switzerland):

enter image description here

Note: Calculations using GEOMETRY and GEOGRAPHY are made differently, and so are their results. GEOGRAPHY calculates the coordinates over an spherical surface (which can be much slower than GEOMETRY) and uses meters as unit of measurement, while GEOGRAPHY uses a planar projection and uses the SRS unit. (Text from this answer)

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
  • Hi! Thank you for your answerd. An ellipse is a Shrinked circle so bigSide is the original diameter but smallSide is the small "diameter" that is smaller than original. – EviSvil Jun 11 '18 at 13:08
0

The first problem is that you use the original coordinates of the center to translate the geometry. (I mean deltax and deltay in st_translate())

As far as i understand delta should be the difference beetween coordinates you need and actually have. So the solution is to calculate preliminary (shifted) polygon:

prePoly := ST_Rotate( ST_Scale(       ST_Buffer(ST_Point(8.54736328125,46.37156925087649)::geography,

3000)::geometry, 0.3,0.5)::geometry, 0);

and then translate it calculating deltas:

st_translate(prePoly, 8.54736328125 - st_x(ST_Centroid(prePoly)),46.37156925087649 - st_y(ST_Centroid(prePoly)))

I'm not sure that i got the second problem right, but if you originally have big and small sides in meters, you can take one (for example, big one) as a radius of buffer and than calculate

xFactor = smallSide/bigSide, and yFactor = 1

In this case your ellipse will be ellongated along the Y axis.

Hogstrom
  • 3,581
  • 2
  • 9
  • 25