PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ LWGEOM_expand()

Datum LWGEOM_expand ( PG_FUNCTION_ARGS  )

Definition at line 1659 of file lwgeom_functions_basic.c.

1660 {
1661  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
1662  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
1663  int32_t srid = lwgeom_get_srid(lwgeom);
1664  LWPOLY *poly;
1666  GBOX gbox;
1667 
1668  POSTGIS_DEBUG(2, "LWGEOM_expand called.");
1669 
1670  /* Can't expand an empty */
1671  if (lwgeom_is_empty(lwgeom))
1672  {
1673  lwgeom_free(lwgeom);
1674  PG_RETURN_POINTER(geom);
1675  }
1676 
1677  /* Can't expand something with no gbox! */
1678  if (LW_FAILURE == lwgeom_calculate_gbox(lwgeom, &gbox))
1679  {
1680  lwgeom_free(lwgeom);
1681  PG_RETURN_POINTER(geom);
1682  }
1683 
1684  if (PG_NARGS() == 2)
1685  {
1686  /* Expand the box the same amount in all directions */
1687  double d = PG_GETARG_FLOAT8(1);
1688  gbox_expand(&gbox, d);
1689  }
1690  else
1691  {
1692  double dx = PG_GETARG_FLOAT8(1);
1693  double dy = PG_GETARG_FLOAT8(2);
1694  double dz = PG_GETARG_FLOAT8(3);
1695  double dm = PG_GETARG_FLOAT8(4);
1696 
1697  gbox_expand_xyzm(&gbox, dx, dy, dz, dm);
1698  }
1699 
1700  {
1701  POINT4D p1 = {gbox.xmin, gbox.ymin, gbox.zmin, gbox.mmin};
1702  POINT4D p2 = {gbox.xmin, gbox.ymax, gbox.zmin, gbox.mmin};
1703  POINT4D p3 = {gbox.xmax, gbox.ymax, gbox.zmax, gbox.mmax};
1704  POINT4D p4 = {gbox.xmax, gbox.ymin, gbox.zmax, gbox.mmax};
1705 
1706  poly = lwpoly_construct_rectangle(lwgeom_has_z(lwgeom), lwgeom_has_m(lwgeom), &p1, &p2, &p3, &p4);
1707  }
1708 
1710  lwgeom_set_srid(lwpoly_as_lwgeom(poly), srid);
1711 
1712  /* Construct GSERIALIZED */
1713  result = geometry_serialize(lwpoly_as_lwgeom(poly));
1714 
1716  lwgeom_free(lwgeom);
1717  PG_FREE_IF_COPY(geom, 0);
1718 
1719  PG_RETURN_POINTER(result);
1720 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: gbox.c:97
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: gbox.c:115
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:927
void lwgeom_set_srid(LWGEOM *geom, int32_t srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
Definition: lwgeom.c:1547
#define LW_FAILURE
Definition: liblwgeom.h:111
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:329
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:934
LWPOLY * lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4)
Definition: lwpoly.c:80
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:755
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:941
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:695
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:203
double ymax
Definition: liblwgeom.h:372
double zmax
Definition: liblwgeom.h:374
double xmax
Definition: liblwgeom.h:370
double zmin
Definition: liblwgeom.h:373
double mmax
Definition: liblwgeom.h:376
double ymin
Definition: liblwgeom.h:371
double xmin
Definition: liblwgeom.h:369
double mmin
Definition: liblwgeom.h:375

References gbox_expand(), gbox_expand_xyzm(), 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, result, GBOX::xmax, GBOX::xmin, GBOX::ymax, GBOX::ymin, GBOX::zmax, and GBOX::zmin.

Here is the call graph for this function: