PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ LWGEOM_expand()

Datum LWGEOM_expand ( PG_FUNCTION_ARGS  )

Definition at line 1548 of file lwgeom_functions_basic.c.

References gbox_expand(), dumpnode::geom, geometry_serialize(), LW_FAILURE, LW_TRUE, lwalloc(), lwgeom_add_bbox(), lwgeom_calculate_gbox(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_is_empty(), LWGEOM_to_BOX(), lwpoly_as_lwgeom(), lwpoly_construct(), POINT4D::m, GBOX::mmax, GBOX::mmin, PG_FUNCTION_INFO_V1(), ptarray_append_point(), ptarray_construct_empty(), LWGEOM::srid, POINT4D::x, GBOX::xmax, GBOX::xmin, POINT4D::y, GBOX::ymax, GBOX::ymin, POINT4D::z, GBOX::zmax, and GBOX::zmin.

Referenced by LWGEOM_makepoly().

1549 {
1550  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
1551  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
1552  double d = PG_GETARG_FLOAT8(1);
1553  POINT4D pt;
1554  POINTARRAY *pa;
1555  POINTARRAY **ppa;
1556  LWPOLY *poly;
1557  GSERIALIZED *result;
1558  GBOX gbox;
1559 
1560  POSTGIS_DEBUG(2, "LWGEOM_expand called.");
1561 
1562  /* Can't expand an empty */
1563  if ( lwgeom_is_empty(lwgeom) )
1564  {
1565  lwgeom_free(lwgeom);
1566  PG_RETURN_POINTER(geom);
1567  }
1568 
1569  /* Can't expand something with no gbox! */
1570  if ( LW_FAILURE == lwgeom_calculate_gbox(lwgeom, &gbox) )
1571  {
1572  lwgeom_free(lwgeom);
1573  PG_RETURN_POINTER(geom);
1574  }
1575 
1576  gbox_expand(&gbox, d);
1577 
1578  pa = ptarray_construct_empty(lwgeom_has_z(lwgeom), lwgeom_has_m(lwgeom), 5);
1579 
1580  /* Assign coordinates to POINT2D array */
1581  pt.x = gbox.xmin;
1582  pt.y = gbox.ymin;
1583  pt.z = gbox.zmin;
1584  pt.m = gbox.mmin;
1585  ptarray_append_point(pa, &pt, LW_TRUE);
1586  pt.x = gbox.xmin;
1587  pt.y = gbox.ymax;
1588  pt.z = gbox.zmin;
1589  pt.m = gbox.mmin;
1590  ptarray_append_point(pa, &pt, LW_TRUE);
1591  pt.x = gbox.xmax;
1592  pt.y = gbox.ymax;
1593  pt.z = gbox.zmax;
1594  pt.m = gbox.mmax;
1595  ptarray_append_point(pa, &pt, LW_TRUE);
1596  pt.x = gbox.xmax;
1597  pt.y = gbox.ymin;
1598  pt.z = gbox.zmax;
1599  pt.m = gbox.mmax;
1600  ptarray_append_point(pa, &pt, LW_TRUE);
1601  pt.x = gbox.xmin;
1602  pt.y = gbox.ymin;
1603  pt.z = gbox.zmin;
1604  pt.m = gbox.mmin;
1605  ptarray_append_point(pa, &pt, LW_TRUE);
1606 
1607  /* Construct point array */
1608  ppa = lwalloc(sizeof(POINTARRAY*));
1609  ppa[0] = pa;
1610 
1611  /* Construct polygon */
1612  poly = lwpoly_construct(lwgeom->srid, NULL, 1, ppa);
1614 
1615  /* Construct GSERIALIZED */
1616  result = geometry_serialize(lwpoly_as_lwgeom(poly));
1617 
1619  lwgeom_free(lwgeom);
1620  PG_FREE_IF_COPY(geom, 0);
1621 
1622  PG_RETURN_POINTER(result);
1623 }
double x
Definition: liblwgeom.h:336
double m
Definition: liblwgeom.h:336
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: g_box.c:93
double xmax
Definition: liblwgeom.h:277
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:836
int32_t srid
Definition: liblwgeom.h:383
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:239
#define LW_FAILURE
Definition: liblwgeom.h:64
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:652
double zmax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:278
LWGEOM * geom
double xmin
Definition: liblwgeom.h:276
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:156
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:29
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
double ymax
Definition: liblwgeom.h:279
double z
Definition: liblwgeom.h:336
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
double mmin
Definition: liblwgeom.h:282
double zmin
Definition: liblwgeom.h:280
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
double mmax
Definition: liblwgeom.h:283
void * lwalloc(size_t size)
Definition: lwutil.c:199
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:1297
double y
Definition: liblwgeom.h:336
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:843
Here is the call graph for this function:
Here is the caller graph for this function: