-
Notifications
You must be signed in to change notification settings - Fork 943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate area with higher accuracy #2643
Comments
Thanks @vTechGIS. I think this type of request has come up in different forms in the past. I think that Turf does not try to perfectly match QGIS, or its underlying GEOS library, or any other 3rd party, as the source of truth. I think Turf methods were chosen for speed and accuracy, and possibly even simplicity. And any differences between libraries may be within the bounds of error of the approximations they are making. I think this could be documented better. That said, the questions that come to mind for me is:
I did a little digging on the turf side:
Related issues that provide some insight: |
@twelch Why don't you use the common WGS84/GRS80 standard for earth radius (6378137.0 m)? I have a large area calculation going on for agricultural plots. For the calculation on the server is done using postgis. The calculations are very different from what I get when calculating the area while editing the contour. The server calculates 139.29 ha (same values I got on QGIS), with turf I get an area of 138.8 ha, which is a very big difference for hectares. |
@Armer7 It looks like 6371008.8 is the mean radius
And 6378137.0 is the equatorial radius.
It looks like mean radius was chosen by Turf, because it is seen as a better approximation of radius for the haversine distance formula, which is what turf.distance uses.
I can't tell you if the "better approximation" suggestion holds true for the geodesic area algorithm turf uses, but it's worth noting that OpenLayers also uses the mean radius value for all of the distance, area, length, etc. calculation. In addition, they support passing your own radius value. This would allow someone to match their library of choice if the same algorithm otherwise is used. There is in fact an open Turf ticked to support this. #1176 seems like a reasonable way forward here. I think more convincing would be needed that switching to equatorial radius by default in turf, at least for turf.area, is the right choice. I think Turf needs to better document the algorithms it uses for distance/area, the nature of them (geodesic), and the earth radius assumed. So that people can make a more informed decision. |
Here's the original paper for the area algorithm, took me a while to track it down - https://dataverse.jpl.nasa.gov/dataset.xhtml?persistentId=hdl:2014/41271. It doesn't specify a radius value to use 2007_ChamberlainDuquette_SomeAlgorithmsForPolygonsOnASphere.pdf |
I use the latest version of Turf to calculate the area of a geojson polygon.
The area result from Turf is: 22.13 m2 and Geographic Lib (https://geographiclib.sourceforge.io/) 22.06 m2. I also checked on QGIS the area result is 22.03 m2
So Geographic Lib has higher accuracy than Turf Lib. Can you improve this issue?
Thank you so much.
Geojson data source:
{"type":"Polygon","coordinates":[[[106.66416522963165,14.579907369919486],[106.6641609900968,14.579919026608949],[106.66415731659645,14.579932022843553],[106.66414116820758,14.579927094033418],[106.66413907381092,14.579900138182057],[106.66411935271576,14.579868331778414],[106.66412579474931,14.5798490375216],[106.66414456560182,14.579868433595195],[106.66415768266069,14.579875838613062],[106.66416266097694,14.579878985318168],[106.66416175432456,14.579893036877686],[106.66416522963165,14.579907369919486]]]}
The text was updated successfully, but these errors were encountered: