PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum LWGEOM_expand ( PG_FUNCTION_ARGS  )

Definition at line 1620 of file lwgeom_functions_basic.c.

References gbox_expand(), 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(), lwpoly_as_lwgeom(), lwpoly_construct(), POINT4D::m, GBOX::mmax, GBOX::mmin, ptarray_append_point(), ptarray_construct_empty(), result, LWGEOM::srid, POINT4D::x, GBOX::xmax, GBOX::xmin, POINT4D::y, GBOX::ymax, GBOX::ymin, POINT4D::z, GBOX::zmax, and GBOX::zmin.

1621 {
1622  GSERIALIZED *geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1623  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
1624  double d = PG_GETARG_FLOAT8(1);
1625  POINT4D pt;
1626  POINTARRAY *pa;
1627  POINTARRAY **ppa;
1628  LWPOLY *poly;
1630  GBOX gbox;
1631 
1632  POSTGIS_DEBUG(2, "LWGEOM_expand called.");
1633 
1634  /* Can't expand an empty */
1635  if ( lwgeom_is_empty(lwgeom) )
1636  {
1637  lwgeom_free(lwgeom);
1638  PG_RETURN_POINTER(geom);
1639  }
1640 
1641  /* Can't expand something with no gbox! */
1642  if ( LW_FAILURE == lwgeom_calculate_gbox(lwgeom, &gbox) )
1643  {
1644  lwgeom_free(lwgeom);
1645  PG_RETURN_POINTER(geom);
1646  }
1647 
1648  gbox_expand(&gbox, d);
1649 
1650  pa = ptarray_construct_empty(lwgeom_has_z(lwgeom), lwgeom_has_m(lwgeom), 5);
1651 
1652  /* Assign coordinates to POINT2D array */
1653  pt.x = gbox.xmin;
1654  pt.y = gbox.ymin;
1655  pt.z = gbox.zmin;
1656  pt.m = gbox.mmin;
1657  ptarray_append_point(pa, &pt, LW_TRUE);
1658  pt.x = gbox.xmin;
1659  pt.y = gbox.ymax;
1660  pt.z = gbox.zmin;
1661  pt.m = gbox.mmin;
1662  ptarray_append_point(pa, &pt, LW_TRUE);
1663  pt.x = gbox.xmax;
1664  pt.y = gbox.ymax;
1665  pt.z = gbox.zmax;
1666  pt.m = gbox.mmax;
1667  ptarray_append_point(pa, &pt, LW_TRUE);
1668  pt.x = gbox.xmax;
1669  pt.y = gbox.ymin;
1670  pt.z = gbox.zmax;
1671  pt.m = gbox.mmax;
1672  ptarray_append_point(pa, &pt, LW_TRUE);
1673  pt.x = gbox.xmin;
1674  pt.y = gbox.ymin;
1675  pt.z = gbox.zmin;
1676  pt.m = gbox.mmin;
1677  ptarray_append_point(pa, &pt, LW_TRUE);
1678 
1679  /* Construct point array */
1680  ppa = lwalloc(sizeof(POINTARRAY*));
1681  ppa[0] = pa;
1682 
1683  /* Construct polygon */
1684  poly = lwpoly_construct(lwgeom->srid, NULL, 1, ppa);
1686 
1687  /* Construct GSERIALIZED */
1688  result = geometry_serialize(lwpoly_as_lwgeom(poly));
1689 
1691  lwgeom_free(lwgeom);
1692  PG_FREE_IF_COPY(geom, 0);
1693 
1694  PG_RETURN_POINTER(result);
1695 }
double x
Definition: liblwgeom.h:308
double m
Definition: liblwgeom.h:308
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:91
double xmax
Definition: liblwgeom.h:249
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:792
char ** result
Definition: liblwgeom.h:218
int32_t srid
Definition: liblwgeom.h:355
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:239
#define LW_FAILURE
Definition: liblwgeom.h:54
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:608
double zmax
Definition: liblwgeom.h:253
double ymin
Definition: liblwgeom.h:250
LWGEOM * geom
double xmin
Definition: liblwgeom.h:248
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:141
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:51
double ymax
Definition: liblwgeom.h:251
double z
Definition: liblwgeom.h:308
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
double mmin
Definition: liblwgeom.h:254
double zmin
Definition: liblwgeom.h:252
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:555
double mmax
Definition: liblwgeom.h:255
void * lwalloc(size_t size)
Definition: lwutil.c:175
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:1229
double y
Definition: liblwgeom.h:308
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:799

Here is the call graph for this function: