Split polygons into triangles and use centroid of the triangle with the triangle area as weight to calculate the centroid of a (multi)polygon.
316 POINT4D* reference_point = NULL;
319 for (ip = 0; ip < mpoly->
ngeoms; ip++) {
320 for (ir = 0; ir < mpoly->
geoms[ip]->
nrings; ir++) {
325 points = palloc(size*
sizeof(
POINT3DM));
331 for (ip = 0; ip < mpoly->
ngeoms; ip++) {
334 for (ir = 0; ir < poly->
nrings; ir++) {
338 for (i = 0; i < ring->
npoints - 1; i++) {
369 triangle[0].
x = p1->
x;
370 triangle[0].
y = p1->
y;
373 triangle[1].
x = p2->
x;
374 triangle[1].
y = p2->
y;
377 triangle[2].
x = reference_point->
x;
378 triangle[2].
y = reference_point->
y;
386 points[j].
m = weight;
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...
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(int 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.
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.