Polygon area calculation doesn't match other tools like google earth engine or geojson.io
See original GitHub issuePolygon area calculation doesn’t seem to match up with other similar tools such as Geojson.io or Google Earth Engine. For example:
coords = [(-97.59238135821987, 43.47456565304017),
(-97.59244690469288, 43.47962399877412),
(-97.59191951546768, 43.47962728271748),
(-97.59185396090983, 43.47456565304017),
(-97.59238135821987, 43.47456565304017)]
projection = partial(pyproj.transform, pyproj.Proj(init='epsg:4326'), pyproj.Proj(init='epsg:3857'))
shapely.ops.transform(projection, shapely.geometry.Polygon(sample_coords)).area
yields an area of 45573.993884405005
m^2 while Google Earth Engine and Geojson.io report 23944.14737277293
and 23997.77
, respectively.
The area in shapely is calculated here quoting a method whose link is broken, while the Geojson.io is calculated here via a method described on starting on page 3 of this document.
I’ve converted this briefly to python with the argument expecting the same coordinate scheme as above (list of coordinates):
def ringArea(coords):
#var p1, p2, p3, lowerIndex, middleIndex, upperIndex, i,
area = 0
wgs84_radius = 6378137 # earth's equitorial radius in wgs84 = espg 4326
coordsLength = len(coords)
if coordsLength > 2:
for i in range(coordsLength):
if i == coordsLength - 2:
lowerIndex = coordsLength - 2
middleIndex = coordsLength - 1
upperIndex = 0
elif i == coordsLength - 1:
lowerIndex = coordsLength - 1
middleIndex = 0
upperIndex = 1
else:
lowerIndex = i
middleIndex = i + 1
upperIndex = i + 2
p1 = coords[lowerIndex]
p2 = coords[middleIndex]
p3 = coords[upperIndex]
area += (np.deg2rad(p3[0]) - np.deg2rad(p1[0]) ) * np.sin(np.deg2rad(p2[1]))
area = area * wgs84_radius * wgs84_radius / 2
return area
This method returns an area of 23997.769250450423
m^2.
My main question is: Is the current method preferred for some reason? If so, can the link to the cited be fixed (i’m not sure where it’s supposed to go). If not, is it possible to conform (or add the option) to the method described int he JPL doc?
I’d be happy to contribute to this if the option for this other method would like to be added but I didn’t see any contributing guidelines.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
As far as I understand, shapely assumes all points are cartesian, and calculates area in whatever coordinates it is given; in the example above wgs coordinates are converted to web mercator
epsg3857
to calculate area, but web mercator is not an equal area projection.If we substitute conversion to an equal area coordinate system such as world mollweide (https://spatialreference.org/ref/esri/54009/) , the area calculation is performed as expected:
Which gives
23997.775332830173
.We use this over in https://github.com/mapbox/fio-area. Hope this helps!
In case anyone else comes across the above issue w.r.t. re-projecting to ESRI:54009, here is a solution https://github.com/pyproj4/pyproj/issues/341