PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwmpoly_to_points()

LWMPOINT* lwmpoly_to_points ( const LWMPOLY mpoly,
uint32_t  npoints 
)

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

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().

1868 {
1869  const LWGEOM *lwgeom = (LWGEOM*)lwmpoly;
1870  double area;
1871  uint32_t i;
1872  LWMPOINT *mpt = NULL;
1873 
1874  if (lwgeom_get_type(lwgeom) != MULTIPOLYGONTYPE)
1875  {
1876  lwerror("%s: only multipolygons supported", __func__);
1877  return NULL;
1878  }
1879  if (npoints == 0 || lwgeom_is_empty(lwgeom))
1880  {
1881  return NULL;
1882  }
1883 
1884  area = lwgeom_area(lwgeom);
1885 
1886  for (i = 0; i < lwmpoly->ngeoms; i++)
1887  {
1888  double sub_area = lwpoly_area(lwmpoly->geoms[i]);
1889  int sub_npoints = lround(npoints * sub_area / area);
1890  if(sub_npoints > 0)
1891  {
1892  LWMPOINT *sub_mpt = lwpoly_to_points(lwmpoly->geoms[i], sub_npoints);
1893  if (!mpt)
1894  {
1895  mpt = sub_mpt;
1896  }
1897  else
1898  {
1899  uint32_t j;
1900  for (j = 0; j < sub_mpt->ngeoms; j++)
1901  {
1902  mpt = lwmpoint_add_lwpoint(mpt, sub_mpt->geoms[j]);
1903  }
1904  /* Just free the shell, leave the underlying lwpoints alone, as they
1905  are now owed by the returning multipoint */
1906  lwfree(sub_mpt->geoms);
1907  lwgeom_release((LWGEOM*)sub_mpt);
1908  }
1909  }
1910  }
1911 
1912  return mpt;
1913 }
uint32_t ngeoms
Definition: liblwgeom.h:467
void lwfree(void *mem)
Definition: lwutil.c:244
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:916
Datum area(PG_FUNCTION_ARGS)
unsigned int uint32_t
Definition: uthash.h:78
LWMPOINT * lwpoly_to_points(const LWPOLY *lwpoly, uint32_t npoints)
LWPOINT ** geoms
Definition: liblwgeom.h:469
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
Definition: lwpoly.c:441
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1850
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:452
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:1386
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: