PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwmpoly_to_points()

LWMPOINT* lwmpoly_to_points ( const LWMPOLY lwmpoly,
uint32_t  npoints 
)

Definition at line 1664 of file liblwgeom/lwgeom_geos.c.

1665 {
1666  const LWGEOM* lwgeom = (LWGEOM*)lwmpoly;
1667  double area;
1668  uint32_t i;
1669  LWMPOINT* mpt = NULL;
1670 
1671  if (lwgeom_get_type(lwgeom) != MULTIPOLYGONTYPE)
1672  {
1673  lwerror("%s: only multipolygons supported", __func__);
1674  return NULL;
1675  }
1676  if (npoints == 0 || lwgeom_is_empty(lwgeom)) return NULL;
1677 
1678  area = lwgeom_area(lwgeom);
1679 
1680  for (i = 0; i < lwmpoly->ngeoms; i++)
1681  {
1682  double sub_area = lwpoly_area(lwmpoly->geoms[i]);
1683  int sub_npoints = lround(npoints * sub_area / area);
1684  if (sub_npoints > 0)
1685  {
1686  LWMPOINT* sub_mpt = lwpoly_to_points(lwmpoly->geoms[i], sub_npoints);
1687  if (!mpt)
1688  mpt = sub_mpt;
1689  else
1690  {
1691  uint32_t j;
1692  for (j = 0; j < sub_mpt->ngeoms; j++)
1693  mpt = lwmpoint_add_lwpoint(mpt, sub_mpt->geoms[j]);
1694  /* Just free the shell, leave the underlying lwpoints alone, as they are now owned by
1695  * the returning multipoint */
1696  lwfree(sub_mpt->geoms);
1697  lwgeom_release((LWGEOM*)sub_mpt);
1698  }
1699  }
1700  }
1701  return mpt;
1702 }
LWMPOINT * lwpoly_to_points(const LWPOLY *lwpoly, uint32_t npoints)
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:923
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1872
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
void lwfree(void *mem)
Definition: lwutil.c:244
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:459
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
Definition: lwpoly.c:441
Datum area(PG_FUNCTION_ARGS)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint32_t ngeoms
Definition: liblwgeom.h:471
LWPOINT ** geoms
Definition: liblwgeom.h:473
uint32_t ngeoms
Definition: liblwgeom.h:497
LWPOLY ** geoms
Definition: liblwgeom.h:499
unsigned int uint32_t
Definition: uthash.h:78

References area(), LWMPOINT::geoms, LWMPOLY::geoms, lwerror(), lwfree(), lwgeom_area(), lwgeom_get_type(), lwgeom_is_empty(), lwgeom_release(), lwmpoint_add_lwpoint(), lwpoly_area(), lwpoly_to_points(), MULTIPOLYGONTYPE, LWMPOINT::ngeoms, and LWMPOLY::ngeoms.

Referenced by lwgeom_to_points().

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