Split polygons into triangles and use centroid of the triangle with the triangle area as weight to calculate the centroid of a (multi)polygon.
313 for (ip = 0; ip < mpoly->
ngeoms; ip++) {
314 for (ir = 0; ir < mpoly->
geoms[ip]->
nrings; ir++) {
325 for (ip = 0; ip < mpoly->
ngeoms; ip++) {
328 for (ir = 0; ir < poly->
nrings; ir++) {
332 for (i = 0; i < ring->
npoints - 1; i++) {
363 triangle[0].
x = p1->
x;
364 triangle[0].
y = p1->
y;
367 triangle[1].
x = p2->
x;
368 triangle[1].
y = p2->
y;
371 triangle[2].
x = reference_point->
x;
372 triangle[2].
y = reference_point->
y;
380 points[j].
m = weight;
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void lwpoint_free(LWPOINT *pt)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
double lwpoint_get_x(const LWPOINT *point)
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
#define LW_TRUE
Return types for functions with status returns.
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, int where)
Insert a point into an existing POINTARRAY.
double lwgeom_area_sphere(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the sphere.
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
double lwpoint_get_y(const LWPOINT *point)
double lwgeom_area_spheroid(const LWGEOM *lwgeom, const SPHEROID *spheroid)
Calculate the geodetic area of a lwgeom on the spheroid.
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
LWPOINT * geography_centroid_from_wpoints(const uint32_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...