Opened 12 months ago

Closed 6 months ago

#3960 closed task (fixed)

Unify centroid functions

Reported by: komzpa Owned by: komzpa
Priority: medium Milestone: PostGIS 2.5.0
Component: postgis Version: trunk
Keywords: Cc:


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:

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 Changed 12 months ago by dbaston

#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.

comment:2 Changed 12 months ago by komzpa

Another centroid is in Geography.

Weighted by M, accepts multipoint (hey @dbaston there is such practice...): 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:

Another small centroid in kmeans, 2D only, has logic of "check if it's current cluster" attached:

GBOX centroid, uses fancy point iteration likely hardwired to memory layout:

comment:3 Changed 7 months ago by pramsey

Owner: changed from pramsey to komzpa

comment:4 Changed 7 months ago by pramsey

I'm reassigning this since it energizes me not at all.

comment:5 Changed 6 months ago by komzpa

Resolution: fixed
Status: newclosed

In 16608:

Unify geometry centroid functions

Make ST_Centroid call lwgeom_centroid.

Closes #3960

Note: See TracTickets for help on using tickets.