PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ lwmpoly_to_points()

LWMPOINT* lwmpoly_to_points ( const LWMPOLY lwmpoly,
int  npoints 
)

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

References area(), LWMPOINT::geoms, LWMPOLY::geoms, lwerror(), 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().

1842 {
1843  const LWGEOM *lwgeom = (LWGEOM*)lwmpoly;
1844  double area;
1845  int i;
1846  LWMPOINT *mpt = NULL;
1847 
1848  if (lwgeom_get_type(lwgeom) != MULTIPOLYGONTYPE)
1849  {
1850  lwerror("%s: only multipolygons supported", __func__);
1851  return NULL;
1852  }
1853  if (npoints == 0 || lwgeom_is_empty(lwgeom))
1854  {
1855  return NULL;
1856  }
1857 
1858  area = lwgeom_area(lwgeom);
1859 
1860  for (i = 0; i < lwmpoly->ngeoms; i++)
1861  {
1862  double sub_area = lwpoly_area(lwmpoly->geoms[i]);
1863  int sub_npoints = lround(npoints * sub_area / area);
1864  if(sub_npoints > 0)
1865  {
1866  LWMPOINT *sub_mpt = lwpoly_to_points(lwmpoly->geoms[i], sub_npoints);
1867  if (!mpt)
1868  {
1869  mpt = sub_mpt;
1870  }
1871  else
1872  {
1873  int j;
1874  for (j = 0; j < sub_mpt->ngeoms; j++)
1875  {
1876  mpt = lwmpoint_add_lwpoint(mpt, sub_mpt->geoms[j]);
1877  }
1878  /* Just free the shell, leave the underlying lwpoints alone, as they
1879  are now owed by the returning multipoint */
1880  lwgeom_release((LWGEOM*)sub_mpt);
1881  }
1882  }
1883  }
1884 
1885  return mpt;
1886 }
LWMPOINT * lwpoly_to_points(const LWPOLY *lwpoly, int npoints)
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:842
Datum area(PG_FUNCTION_ARGS)
LWPOLY ** geoms
Definition: liblwgeom.h:495
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:484
int ngeoms
Definition: liblwgeom.h:493
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1592
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:385
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:1310
int ngeoms
Definition: liblwgeom.h:467
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: