PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lwmpoly_to_points()

LWMPOINT* lwmpoly_to_points ( const LWMPOLY lwmpoly,
uint32_t  npoints,
int32_t  seed 
)

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

1853 {
1854  const LWGEOM* lwgeom = (LWGEOM*)lwmpoly;
1855  double area;
1856  uint32_t i;
1857  LWMPOINT* mpt = NULL;
1858 
1859  if (lwgeom_get_type(lwgeom) != MULTIPOLYGONTYPE)
1860  {
1861  lwerror("%s: only multipolygons supported", __func__);
1862  return NULL;
1863  }
1864  if (npoints == 0 || lwgeom_is_empty(lwgeom)) return NULL;
1865 
1866  area = lwgeom_area(lwgeom);
1867 
1868  for (i = 0; i < lwmpoly->ngeoms; i++)
1869  {
1870  double sub_area = lwpoly_area(lwmpoly->geoms[i]);
1871  int sub_npoints = lround(npoints * sub_area / area);
1872  if (sub_npoints > 0)
1873  {
1874  LWMPOINT* sub_mpt = lwpoly_to_points(lwmpoly->geoms[i], sub_npoints, seed);
1875  if (!mpt)
1876  mpt = sub_mpt;
1877  else
1878  {
1879  uint32_t j;
1880  for (j = 0; j < sub_mpt->ngeoms; j++)
1881  mpt = lwmpoint_add_lwpoint(mpt, sub_mpt->geoms[j]);
1882  /* Just free the shell, leave the underlying lwpoints alone, as they are now owned by
1883  * the returning multipoint */
1884  lwfree(sub_mpt->geoms);
1885  lwgeom_release((LWGEOM*)sub_mpt);
1886  }
1887  }
1888  }
1889  return mpt;
1890 }
LWMPOINT * lwpoly_to_points(const LWPOLY *lwpoly, uint32_t npoints, int32_t seed)
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1908
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:122
void lwfree(void *mem)
Definition: lwutil.c:242
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:468
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
Definition: lwpoly.c:434
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwinline.h:145
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
uint32_t ngeoms
Definition: liblwgeom.h:553
LWPOINT ** geoms
Definition: liblwgeom.h:548
uint32_t ngeoms
Definition: liblwgeom.h:581
LWPOLY ** geoms
Definition: liblwgeom.h:576

References 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: