-
Notifications
You must be signed in to change notification settings - Fork 941
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
centroid vs mean centre #334
Comments
Just checking this myself and was about to ask the same question, the doc says " calculates the centroid using the arithmetic mean of all vertices" which is what the function is doing, qgis I believe is calculating the weighted mean. Have you tried postgis but apparently it would give the same answer as turf for centroid. I think adding the weighted option as a switch/parameter would be nice instead of having to add the module https://github.com/Turfjs/turf-weighted-centroid maybe check with that module see if its similar to Qgis |
The turf-weighted-centroid module implements an algorithm that weights the centroid of a collection of features by some external heuristic (ie: population, median income, etc.).
There are many different centroid algorithms that are used in different analysis contexts. I would be open to a module that implements the desired behavior here, provided a generic, concrete algorithm to follow (the same goes for other types of centroid algorithms). I'm going to close this ticket, but feel free to open another one with a reference to a specific algorithm that is needed. |
Same issue here - can't figure out how to achieve QGIS-like centroids with Turf. Have you found the solution @jamaps? UPD: |
@kachkaev I would give @mourner's new Polylabel module a spin. Polylabel implements a fast centroid algorithm (modified pole of inaccessibility) aimed at visual rendering (unlike any of the turf centroid algorithms, which have different design goals). |
Greetings turf people,
I think turf's centroid method doesn't actually calculate the true centroid of a polygon. It seems to calculate the mean of all the vertices of a polygon rather than the mean of all the points that fall within the polygon. Thus, if there are lots of vertices on one side of the shape, it pulls the centroid point towards that edge.
Centroid calculated by turf:
Centroid calculated in QGIS (using "polygon centroids" under geometry tools)
I think what turf is calculating is actually the mean centre, which can be quite useful for cluster analysis, but it's not the same as the centroid of a polygon. (https://www.wikiwand.com/en/Centroid)
Maybe this is just semantics, but I found the output of turf's centroid function confusing as I expected one result and received another.
All the best,
The text was updated successfully, but these errors were encountered: