PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ ST_BoundingDiagonal()

Datum ST_BoundingDiagonal ( PG_FUNCTION_ARGS  )

Definition at line 2703 of file lwgeom_functions_basic.c.

References LWGEOM::bbox, LWGEOM::flags, FLAGS_GET_M, FLAGS_GET_Z, geometry_serialize(), LINETYPE, LW_TRUE, lwgeom_construct_empty(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_get_bbox(), lwline_as_lwgeom(), lwline_construct(), POINT4D::m, GBOX::mmax, GBOX::mmin, PG_FUNCTION_INFO_V1(), ptarray_append_point(), ptarray_construct_empty(), LWGEOM::srid, ST_Scale(), POINT4D::x, GBOX::xmax, GBOX::xmin, POINT4D::y, GBOX::ymax, GBOX::ymin, POINT4D::z, GBOX::zmax, and GBOX::zmin.

Referenced by ST_SwapOrdinates().

2704 {
2705  GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
2706  GSERIALIZED *geom_out;
2707  bool fits = PG_GETARG_BOOL(1);
2708  LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
2709  LWGEOM *lwgeom_out;
2710  const GBOX *gbox;
2711  int hasz = FLAGS_GET_Z(lwgeom_in->flags);
2712  int hasm = FLAGS_GET_M(lwgeom_in->flags);
2713  int srid = lwgeom_in->srid;
2714  POINT4D pt;
2715  POINTARRAY *pa;
2716 
2717  if ( fits ) {
2718  /* unregister any cached bbox to ensure it's recomputed */
2719  lwgeom_in->bbox = NULL;
2720  }
2721 
2722  gbox = lwgeom_get_bbox(lwgeom_in);
2723 
2724  if ( ! gbox )
2725  {
2726  lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
2727  }
2728  else
2729  {
2730  pa = ptarray_construct_empty(hasz, hasm, 2);
2731  pt.x = gbox->xmin;
2732  pt.y = gbox->ymin;
2733  pt.z = gbox->zmin;
2734  pt.m = gbox->mmin;
2735  ptarray_append_point(pa, &pt, LW_TRUE);
2736  pt.x = gbox->xmax;
2737  pt.y = gbox->ymax;
2738  pt.z = gbox->zmax;
2739  pt.m = gbox->mmax;
2740  ptarray_append_point(pa, &pt, LW_TRUE);
2741  lwgeom_out = lwline_as_lwgeom( lwline_construct(srid, NULL, pa) );
2742  }
2743 
2744  lwgeom_free(lwgeom_in);
2745  PG_FREE_IF_COPY(geom_in, 0);
2746 
2747  geom_out = geometry_serialize(lwgeom_out);
2748  lwgeom_free(lwgeom_out);
2749 
2750  PG_RETURN_POINTER(geom_out);
2751 }
double x
Definition: liblwgeom.h:336
#define LINETYPE
Definition: liblwgeom.h:71
GBOX * bbox
Definition: liblwgeom.h:382
double m
Definition: liblwgeom.h:336
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint8_t flags
Definition: liblwgeom.h:381
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
int32_t srid
Definition: liblwgeom.h:383
double zmax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:278
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:249
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
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition: lwgeom.c:640
double ymax
Definition: liblwgeom.h:279
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:1807
double z
Definition: liblwgeom.h:336
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
double mmin
Definition: liblwgeom.h:282
double zmin
Definition: liblwgeom.h:280
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
double mmax
Definition: liblwgeom.h:283
double y
Definition: liblwgeom.h:336
Here is the call graph for this function:
Here is the caller graph for this function: