PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwmpoly_to_points()

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

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

1627{
1628 const LWGEOM* lwgeom = (LWGEOM*)lwmpoly;
1629 double area;
1630 uint32_t i;
1631 LWMPOINT* mpt = NULL;
1632
1633 if (lwgeom_get_type(lwgeom) != MULTIPOLYGONTYPE)
1634 {
1635 lwerror("%s: only multipolygons supported", __func__);
1636 return NULL;
1637 }
1638 if (npoints == 0 || lwgeom_is_empty(lwgeom)) return NULL;
1639
1640 area = lwgeom_area(lwgeom);
1641
1642 for (i = 0; i < lwmpoly->ngeoms; i++)
1643 {
1644 double sub_area = lwpoly_area(lwmpoly->geoms[i]);
1645 int sub_npoints = lround(npoints * sub_area / area);
1646 if (sub_npoints > 0)
1647 {
1648 LWMPOINT* sub_mpt = lwpoly_to_points(lwmpoly->geoms[i], sub_npoints, seed);
1649 if (!mpt)
1650 mpt = sub_mpt;
1651 else
1652 {
1653 uint32_t j;
1654 for (j = 0; j < sub_mpt->ngeoms; j++)
1655 mpt = lwmpoint_add_lwpoint(mpt, sub_mpt->geoms[j]);
1656 /* Just free the shell, leave the underlying lwpoints alone, as they are now owned by
1657 * the returning multipoint */
1658 lwfree(sub_mpt->geoms);
1659 lwgeom_release((LWGEOM*)sub_mpt);
1660 }
1661 }
1662 }
1663 return mpt;
1664}
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:1999
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:107
void lwfree(void *mem)
Definition lwutil.c:248
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition lwgeom.c:496
double lwpoly_area(const LWPOLY *poly)
Find the area of the outer ring - sum (area of inner rings).
Definition lwpoly.c:433
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition lwinline.h:141
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:199
uint32_t ngeoms
Definition liblwgeom.h:538
LWPOINT ** geoms
Definition liblwgeom.h:533

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: