I am trying to create an ellipse to be stored in my django project. I'm provided a lat, lon, major/minor in Nautical Miles, and an orientation in degrees. Between this post and the docs I've been able to piece together the below code, however, when I compare the final outputs from an export of my django to what I have generated from the arcgis "Table to Ellipse tool" they don't match. I've tried to account for Arc's different methodology of using azimuth and clockwise rotation in my code but the orientation and scale don't match. I think the issue stems from starting in cartesian space as meters, converting to WGS-84, and then translating origin position. Here is my code with random test data.

from functools import partial
from shapely.ops import transform
from shapely.affinity import translate
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.geos import MultiPolygon
import pyproj

lat = -78.150511
lon = 39.190978
major = 13.114 #Nmi
minor = 8.58 #Nmi
metersconversion = 1852
smajormeters = (major * metersconversion) / 2
sminormeters = (minor * metersconversion) / 2
orient = 61.9 #Degrees Rotation
#Ellipse parameters
ellipse = ((0, 0), (smajormeters, sminormeters), orient)
#create circle with radius of 1
circ = shapely.geometry.Point(ellipse[0]).buffer(1)
#create ellipse along x and y
ell = shapely.affinity.scale(circ, int(ellipse[1][0]), int(ellipse[1][1]))
#Rotate ellipse
elrv = shapely.affinity.rotate(ell, 90 + (ellipse[2] * -1))
project = partial(pyproj.transform, pyproj.Proj(init='epsg:3857'), 
geom4326 = transform(project, elrv)
transgeom = shapely.affinity.translate(geom4326, lon, lat)
ellpoly = GEOSGeometry(transgeom.wkt)
#Define the srid/epsg as 4326 for ingest into django postgresql
ellpoly.srid = 4326    

What has gone wrong?

  • Swap lat and lon for one unless the data's in Antarctica.
    – mkennedy
    Aug 31, 2017 at 23:57
  • @mkennedy Are you saying instead of (0,0) set one of them to 1 i.e. (0,1) or are you saying something like (lat,0)? Nothing I'm working on will ever be in a polar region so that sounds like a reasonable plan. Sep 1, 2017 at 0:17
  • You currently have lat set to -78. That is more likely to be the lon value. Likewise, paired with 39, which should be the latitude value. I haven't looked at the rest of the code.
    – mkennedy
    Sep 1, 2017 at 1:26
  • One question is whether the api can build geodetic ellipses (lat,lon center, radii in linear units. If so build it directly. If not you may need to build it in a projected crs.
    – mkennedy
    Sep 1, 2017 at 1:29


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.