PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ geography_centroid_from_wpoints()

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

Definition at line 180 of file geography_centroid.c.

181{
182 double_t x_sum = 0;
183 double_t y_sum = 0;
184 double_t z_sum = 0;
185 double_t weight_sum = 0;
186
187 double_t weight = 1;
188 POINT3D* point;
189
190 uint32_t i;
191 for (i = 0; i < size; i++ )
192 {
193 point = lonlat_to_cart(points[i].x, points[i].y);
194 weight = points[i].m;
195
196 x_sum += point->x * weight;
197 y_sum += point->y * weight;
198 z_sum += point->z * weight;
199
200 weight_sum += weight;
201
202 lwfree(point);
203 }
204
205 return cart_to_lwpoint(x_sum, y_sum, z_sum, weight_sum, srid);
206}
POINT3D * lonlat_to_cart(const double_t raw_lon, const double_t raw_lat)
LWPOINT * cart_to_lwpoint(const double_t x_sum, const double_t y_sum, const double_t z_sum, const double_t weight_sum, const int32_t srid)
void lwfree(void *mem)
Definition lwutil.c:248
double m
Definition liblwgeom.h:408
double z
Definition liblwgeom.h:402
double x
Definition liblwgeom.h:402
double y
Definition liblwgeom.h:402

References cart_to_lwpoint(), lonlat_to_cart(), lwfree(), POINT3DM::m, POINT3D::x, POINT3D::y, and POINT3D::z.

Referenced by geography_centroid(), geography_centroid_from_mline(), and geography_centroid_from_mpoly().

Here is the call graph for this function:
Here is the caller graph for this function: