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

Definition at line 1599 of file lwgeom_functions_basic.c.

References gbox_expand(), gbox_expand_xyzm(), dumpnode::geom, geometry_serialize(), LW_FAILURE, lwgeom_add_bbox(), lwgeom_calculate_gbox(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_get_srid(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_is_empty(), lwgeom_set_srid(), lwpoly_as_lwgeom(), lwpoly_construct_rectangle(), GBOX::mmax, GBOX::mmin, GBOX::xmax, GBOX::xmin, GBOX::ymax, GBOX::ymin, GBOX::zmax, and GBOX::zmin.

1600 {
1601  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
1602  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
1603  int srid = lwgeom_get_srid(lwgeom);
1604  LWPOLY *poly;
1605  GSERIALIZED *result;
1606  GBOX gbox;
1607 
1608  POSTGIS_DEBUG(2, "LWGEOM_expand called.");
1609 
1610  /* Can't expand an empty */
1611  if ( lwgeom_is_empty(lwgeom) )
1612  {
1613  lwgeom_free(lwgeom);
1614  PG_RETURN_POINTER(geom);
1615  }
1616 
1617  /* Can't expand something with no gbox! */
1618  if ( LW_FAILURE == lwgeom_calculate_gbox(lwgeom, &gbox) )
1619  {
1620  lwgeom_free(lwgeom);
1621  PG_RETURN_POINTER(geom);
1622  }
1623 
1624  if (PG_NARGS() == 2)
1625  {
1626  /* Expand the box the same amount in all directions */
1627  double d = PG_GETARG_FLOAT8(1);
1628  gbox_expand(&gbox, d);
1629  }
1630  else
1631  {
1632  double dx = PG_GETARG_FLOAT8(1);
1633  double dy = PG_GETARG_FLOAT8(2);
1634  double dz = PG_GETARG_FLOAT8(3);
1635  double dm = PG_GETARG_FLOAT8(4);
1636 
1637  gbox_expand_xyzm(&gbox, dx, dy, dz, dm);
1638  }
1639 
1640  {
1641  POINT4D p1 = { gbox.xmin, gbox.ymin, gbox.zmin, gbox.mmin };
1642  POINT4D p2 = { gbox.xmin, gbox.ymax, gbox.zmin, gbox.mmin };
1643  POINT4D p3 = { gbox.xmax, gbox.ymax, gbox.zmax, gbox.mmax };
1644  POINT4D p4 = { gbox.xmax, gbox.ymin, gbox.zmax, gbox.mmax };
1645 
1646  poly = lwpoly_construct_rectangle(lwgeom_has_z(lwgeom), lwgeom_has_m(lwgeom), &p1, &p2, &p3, &p4);
1647  }
1648 
1650  lwgeom_set_srid(lwpoly_as_lwgeom(poly), srid);
1651 
1652  /* Construct GSERIALIZED */
1653  result = geometry_serialize(lwpoly_as_lwgeom(poly));
1654 
1656  lwgeom_free(lwgeom);
1657  PG_FREE_IF_COPY(geom, 0);
1658 
1659  PG_RETURN_POINTER(result);
1660 }
void gbox_expand_xyzm(GBOX *g, double dx, double dy, double dz, double dm)
Move the box minimums down and the maximums up by the distances provided.
Definition: g_box.c:126
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:108
double xmax
Definition: liblwgeom.h:292
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:909
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:923
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:319
#define LW_FAILURE
Definition: liblwgeom.h:78
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:739
double zmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:293
LWGEOM * geom
double xmin
Definition: liblwgeom.h:291
double ymax
Definition: liblwgeom.h:294
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
double mmin
Definition: liblwgeom.h:297
double zmin
Definition: liblwgeom.h:295
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:679
double mmax
Definition: liblwgeom.h:298
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
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
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:930
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80

Here is the call graph for this function: