Split polygons into triangles and use centroid of the triangle with the triangle area as weight to calculate the centroid of a (multi)polygon.
319 uint32_t i, ir, ip, j = 0;
321 POINT4D* reference_point = NULL;
324 for (ip = 0; ip < mpoly->
ngeoms; ip++) {
325 for (ir = 0; ir < mpoly->
geoms[ip]->
nrings; ir++) {
330 points = palloc(size*
sizeof(
POINT3DM));
336 for (ip = 0; ip < mpoly->
ngeoms; ip++) {
339 for (ir = 0; ir < poly->
nrings; ir++) {
343 for (i = 0; i < ring->
npoints - 1; i++) {
374 triangle[0].
x = p1->
x;
375 triangle[0].
y = p1->
y;
378 triangle[1].
x = p2->
x;
379 triangle[1].
y = p2->
y;
382 triangle[2].
x = reference_point->
x;
383 triangle[2].
y = reference_point->
y;
391 points[j].
m = weight;
LWPOINT * geography_centroid_from_wpoints(const int32_t srid, const POINT3DM *points, const uint32_t size)
Convert lat-lon-points to x-y-z-coordinates, calculate a weighted average point and return lat-lon-co...
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
void lwpoint_free(LWPOINT *pt)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
double lwpoint_get_x(const LWPOINT *point)
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where)
Insert a point into an existing POINTARRAY.
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
#define LW_TRUE
Return types for functions with status returns.
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
double lwpoint_get_y(const LWPOINT *point)
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.