Opened 7 years ago
Closed 6 years ago
#3960 closed task (fixed)
Unify centroid functions
Reported by: | komzpa | Owned by: | komzpa |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 2.5.0 |
Component: | postgis | Version: | master |
Keywords: | Cc: |
Description
Code currently contains at least three centroid implementations:
ST_Centroid backing function, calls GEOS, has CIRCULAR* support, no weight support:
lwgeom_centroid, KMeans backing, calls GEOS, has no CIRCULAR* support visible:
median init_guess, only points, no GEOS, supports weights:
https://github.com/postgis/postgis/blob/svn-trunk/liblwgeom/lwgeom_median.c#L124
It looks like all three can be merged and pulled closer together, providing a weighted centroid for multipoints and support for CIRCULAR* in kmeans.
Are there any other places?
Change History (5)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Another centroid is in Geography.
Weighted by M, accepts multipoint (hey @dbaston there is such practice...): https://github.com/postgis/postgis/blob/64134491b6fad59a11da05d494b6046b715e00df/postgis/geography_centroid.c#L179 It looks like it doesn't accept Z and uses it only because of geog2cart transform.
The whole geography centroid file fully reimplements logic of geos centroid, if I'm correctly looking at its code here: https://github.com/OSGeo/geos/blob/master/src/algorithm/Centroid.cpp
Another small centroid in kmeans, 2D only, has logic of "check if it's current cluster" attached: https://github.com/postgis/postgis/blob/741b88eda71c80701366dffecd7fa665ee47060c/liblwgeom/lwkmeans.c#L45
GBOX centroid, uses fancy point iteration likely hardwired to memory layout: https://github.com/postgis/postgis/blob/b72778f0ff5564a6ec5b5e45620fc0e3b90c8433/liblwgeom/lwgeodetic.c#L258
comment:3 by , 7 years ago
Owner: | changed from | to
---|
#1 and #2 seem like good candidates to merge (add curve support to #2, and have #1 delegate to #2).
I'd keep #3 separate, as I don't think the use of M to signify "weight" is obvious or established throughout PostGIS.