PostGIS  2.5.0dev-r@@SVN_REVISION@@
LWPOINT * geography_centroid_from_mline ( const LWMLINE mline,
SPHEROID s 
)

Split lines into segments and calculate with middle of segment as weighted point.

Definition at line 250 of file geography_centroid.c.

References geography_centroid_from_wpoints(), LWMLINE::geoms, getPoint2d_cp(), LW_TRUE, lwgeom_distance_spheroid(), lwgeom_free(), lwgeom_set_geodetic(), lwpoint_as_lwgeom(), lwpoint_make2d(), POINT3DM::m, LWMLINE::ngeoms, POINTARRAY::npoints, LWLINE::points, LWMLINE::srid, POINT2D::x, POINT3DM::x, POINT2D::y, and POINT3DM::y.

Referenced by geography_centroid().

251 {
252  double_t tolerance = 0.0;
253  uint32_t size = 0;
254  uint32_t i, k;
255 
256  /* get total number of points */
257  for (i = 0; i < mline->ngeoms; i++) {
258  size += (mline->geoms[i]->points->npoints - 1) * 2;
259  }
260 
261  POINT3DM points[size];
262  uint32_t j = 0;
263 
264  for (i = 0; i < mline->ngeoms; i++) {
265  LWLINE* line = mline->geoms[i];
266 
267  /* add both points of line segment as weighted point */
268  for (k = 0; k < line->points->npoints - 1; k++) {
269  const POINT2D* p1 = getPoint2d_cp(line->points, k);
270  const POINT2D* p2 = getPoint2d_cp(line->points, k+1);
271 
272  /* use line-segment length as weight */
273  LWPOINT* lwp1 = lwpoint_make2d(mline->srid, p1->x, p1->y);
274  LWPOINT* lwp2 = lwpoint_make2d(mline->srid, p2->x, p2->y);
275  LWGEOM* lwgeom1 = lwpoint_as_lwgeom(lwp1);
276  LWGEOM* lwgeom2 = lwpoint_as_lwgeom(lwp2);
277  lwgeom_set_geodetic(lwgeom1, LW_TRUE);
278  lwgeom_set_geodetic(lwgeom2, LW_TRUE);
279 
280  /* use point distance as weight */
281  double_t weight = lwgeom_distance_spheroid(lwgeom1, lwgeom2, s, tolerance);
282 
283  points[j].x = p1->x;
284  points[j].y = p1->y;
285  points[j].m = weight;
286  j++;
287 
288  points[j].x = p2->x;
289  points[j].y = p2->y;
290  points[j].m = weight;
291  j++;
292 
293  lwgeom_free(lwgeom1);
294  lwgeom_free(lwgeom2);
295  }
296  }
297 
298  return geography_centroid_from_wpoints(mline->srid, points, size);
299 }
double x
Definition: liblwgeom.h:345
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:327
double m
Definition: liblwgeom.h:345
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
double y
Definition: liblwgeom.h:327
double y
Definition: liblwgeom.h:345
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:945
uint32_t ngeoms
Definition: liblwgeom.h:480
LWLINE ** geoms
Definition: liblwgeom.h:482
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:334
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
Definition: lwgeodetic.c:2096
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...
int32_t srid
Definition: liblwgeom.h:479
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
POINTARRAY * points
Definition: liblwgeom.h:421
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function:

Here is the caller graph for this function: