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

Definition at line 2865 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, 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.

2866 {
2867  GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
2868  GSERIALIZED *geom_out;
2869  bool fits = PG_GETARG_BOOL(1);
2870  LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
2871  LWGEOM *lwgeom_out;
2872  const GBOX *gbox;
2873  int hasz = FLAGS_GET_Z(lwgeom_in->flags);
2874  int hasm = FLAGS_GET_M(lwgeom_in->flags);
2875  int srid = lwgeom_in->srid;
2876  POINT4D pt;
2877  POINTARRAY *pa;
2878 
2879  if ( fits ) {
2880  /* unregister any cached bbox to ensure it's recomputed */
2881  lwgeom_in->bbox = NULL;
2882  }
2883 
2884  gbox = lwgeom_get_bbox(lwgeom_in);
2885 
2886  if ( ! gbox )
2887  {
2888  lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
2889  }
2890  else
2891  {
2892  pa = ptarray_construct_empty(hasz, hasm, 2);
2893  pt.x = gbox->xmin;
2894  pt.y = gbox->ymin;
2895  pt.z = gbox->zmin;
2896  pt.m = gbox->mmin;
2897  ptarray_append_point(pa, &pt, LW_TRUE);
2898  pt.x = gbox->xmax;
2899  pt.y = gbox->ymax;
2900  pt.z = gbox->zmax;
2901  pt.m = gbox->mmax;
2902  ptarray_append_point(pa, &pt, LW_TRUE);
2903  lwgeom_out = lwline_as_lwgeom( lwline_construct(srid, NULL, pa) );
2904  }
2905 
2906  lwgeom_free(lwgeom_in);
2907  PG_FREE_IF_COPY(geom_in, 0);
2908 
2909  geom_out = geometry_serialize(lwgeom_out);
2910  lwgeom_free(lwgeom_out);
2911 
2912  PG_RETURN_POINTER(geom_out);
2913 }
double x
Definition: liblwgeom.h:351
#define LINETYPE
Definition: liblwgeom.h:85
GBOX * bbox
Definition: liblwgeom.h:397
double m
Definition: liblwgeom.h:351
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint8_t flags
Definition: liblwgeom.h:396
double xmax
Definition: liblwgeom.h:292
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:1137
int32_t srid
Definition: liblwgeom.h:398
double zmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:293
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:329
double xmin
Definition: liblwgeom.h:291
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_FALSE, 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:75
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
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:727
double ymax
Definition: liblwgeom.h:294
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:2078
double z
Definition: liblwgeom.h:351
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
double mmin
Definition: liblwgeom.h:297
double zmin
Definition: liblwgeom.h:295
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
double mmax
Definition: liblwgeom.h:298
double y
Definition: liblwgeom.h:351

Here is the call graph for this function: