PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ gserialized2_peek_gbox_p()

int gserialized2_peek_gbox_p ( const GSERIALIZED g,
GBOX gbox 
)

Definition at line 361 of file gserialized2.c.

362 {
363  uint32_t type = gserialized2_get_type(g);
364  uint8_t *geometry_start = gserialized2_get_geometry_p(g);
365  double *dptr = (double *)(geometry_start);
366  int32_t *iptr = (int32_t *)(geometry_start);
367 
368  /* Peeking doesn't help if you already have a box or are geodetic */
370  {
371  return LW_FAILURE;
372  }
373 
374  /* Boxes of points are easy peasy */
375  if (type == POINTTYPE)
376  {
377  int i = 1; /* Start past <pointtype><padding> */
378 
379  /* Read the npoints flag */
380  int isempty = (iptr[1] == 0);
381 
382  /* EMPTY point has no box */
383  if (isempty) return LW_FAILURE;
384 
385  gbox->xmin = gbox->xmax = dptr[i++];
386  gbox->ymin = gbox->ymax = dptr[i++];
387  gbox->flags = gserialized2_get_lwflags(g);
388  if (G2FLAGS_GET_Z(g->gflags))
389  {
390  gbox->zmin = gbox->zmax = dptr[i++];
391  }
392  if (G2FLAGS_GET_M(g->gflags))
393  {
394  gbox->mmin = gbox->mmax = dptr[i++];
395  }
396  gbox_float_round(gbox);
397  return LW_SUCCESS;
398  }
399  /* We can calculate the box of a two-point cartesian line trivially */
400  else if (type == LINETYPE)
401  {
402  int ndims = G2FLAGS_NDIMS(g->gflags);
403  int i = 0; /* Start at <linetype><npoints> */
404  int npoints = iptr[1]; /* Read the npoints */
405 
406  /* This only works with 2-point lines */
407  if (npoints != 2)
408  return LW_FAILURE;
409 
410  /* Advance to X */
411  /* Past <linetype><npoints> */
412  i++;
413  gbox->xmin = FP_MIN(dptr[i], dptr[i+ndims]);
414  gbox->xmax = FP_MAX(dptr[i], dptr[i+ndims]);
415 
416  /* Advance to Y */
417  i++;
418  gbox->ymin = FP_MIN(dptr[i], dptr[i+ndims]);
419  gbox->ymax = FP_MAX(dptr[i], dptr[i+ndims]);
420 
421  gbox->flags = gserialized2_get_lwflags(g);
422  if (G2FLAGS_GET_Z(g->gflags))
423  {
424  /* Advance to Z */
425  i++;
426  gbox->zmin = FP_MIN(dptr[i], dptr[i+ndims]);
427  gbox->zmax = FP_MAX(dptr[i], dptr[i+ndims]);
428  }
429  if (G2FLAGS_GET_M(g->gflags))
430  {
431  /* Advance to M */
432  i++;
433  gbox->mmin = FP_MIN(dptr[i], dptr[i+ndims]);
434  gbox->mmax = FP_MAX(dptr[i], dptr[i+ndims]);
435  }
436  gbox_float_round(gbox);
437  return LW_SUCCESS;
438  }
439  /* We can also do single-entry multi-points */
440  else if (type == MULTIPOINTTYPE)
441  {
442  int i = 0; /* Start at <multipointtype><ngeoms> */
443  int ngeoms = iptr[1]; /* Read the ngeoms */
444  int npoints;
445 
446  /* This only works with single-entry multipoints */
447  if (ngeoms != 1)
448  return LW_FAILURE;
449 
450  /* Npoints is at <multipointtype><ngeoms><pointtype><npoints> */
451  npoints = iptr[3];
452 
453  /* The check below is necessary because we can have a MULTIPOINT
454  * that contains a single, empty POINT (ngeoms = 1, npoints = 0) */
455  if (npoints != 1)
456  return LW_FAILURE;
457 
458  /* Move forward two doubles (four ints) */
459  /* Past <multipointtype><ngeoms> */
460  /* Past <pointtype><npoints> */
461  i += 2;
462 
463  /* Read the doubles from the one point */
464  gbox->xmin = gbox->xmax = dptr[i++];
465  gbox->ymin = gbox->ymax = dptr[i++];
466  gbox->flags = gserialized2_get_lwflags(g);
467  if (G2FLAGS_GET_Z(g->gflags))
468  {
469  gbox->zmin = gbox->zmax = dptr[i++];
470  }
471  if (G2FLAGS_GET_M(g->gflags))
472  {
473  gbox->mmin = gbox->mmax = dptr[i++];
474  }
475  gbox_float_round(gbox);
476  return LW_SUCCESS;
477  }
478  /* And we can do single-entry multi-lines with two vertices (!!!) */
479  else if (type == MULTILINETYPE)
480  {
481  int ndims = G2FLAGS_NDIMS(g->gflags);
482  int i = 0; /* Start at <multilinetype><ngeoms> */
483  int ngeoms = iptr[1]; /* Read the ngeoms */
484  int npoints;
485 
486  /* This only works with 1-line multilines */
487  if (ngeoms != 1)
488  return LW_FAILURE;
489 
490  /* Npoints is at <multilinetype><ngeoms><linetype><npoints> */
491  npoints = iptr[3];
492 
493  if (npoints != 2)
494  return LW_FAILURE;
495 
496  /* Advance to X */
497  /* Move forward two doubles (four ints) */
498  /* Past <multilinetype><ngeoms> */
499  /* Past <linetype><npoints> */
500  i += 2;
501  gbox->xmin = FP_MIN(dptr[i], dptr[i+ndims]);
502  gbox->xmax = FP_MAX(dptr[i], dptr[i+ndims]);
503 
504  /* Advance to Y */
505  i++;
506  gbox->ymin = FP_MIN(dptr[i], dptr[i+ndims]);
507  gbox->ymax = FP_MAX(dptr[i], dptr[i+ndims]);
508 
509  gbox->flags = gserialized2_get_lwflags(g);
510  if (G2FLAGS_GET_Z(g->gflags))
511  {
512  /* Advance to Z */
513  i++;
514  gbox->zmin = FP_MIN(dptr[i], dptr[i+ndims]);
515  gbox->zmax = FP_MAX(dptr[i], dptr[i+ndims]);
516  }
517  if (G2FLAGS_GET_M(g->gflags))
518  {
519  /* Advance to M */
520  i++;
521  gbox->mmin = FP_MIN(dptr[i], dptr[i+ndims]);
522  gbox->mmax = FP_MAX(dptr[i], dptr[i+ndims]);
523  }
524  gbox_float_round(gbox);
525  return LW_SUCCESS;
526  }
527 
528  return LW_FAILURE;
529 }
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: gbox.c:774
uint32_t gserialized2_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized2.c:185
static uint8_t * gserialized2_get_geometry_p(const GSERIALIZED *g)
Definition: gserialized2.c:106
lwflags_t gserialized2_get_lwflags(const GSERIALIZED *g)
Read the flags from a GSERIALIZED and return a standard lwflag integer.
Definition: gserialized2.c:59
#define G2FLAGS_GET_BBOX(gflags)
Definition: gserialized2.h:24
#define G2FLAGS_GET_GEODETIC(gflags)
Definition: gserialized2.h:25
#define G2FLAGS_GET_Z(gflags)
Definition: gserialized2.h:22
#define G2FLAGS_GET_M(gflags)
Definition: gserialized2.h:23
#define G2FLAGS_NDIMS(gflags)
Definition: gserialized2.h:36
#define LW_FAILURE
Definition: liblwgeom.h:96
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define LINETYPE
Definition: liblwgeom.h:103
#define LW_SUCCESS
Definition: liblwgeom.h:97
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
#define FP_MAX(A, B)
#define FP_MIN(A, B)
type
Definition: ovdump.py:42
double ymax
Definition: liblwgeom.h:357
double zmax
Definition: liblwgeom.h:359
double xmax
Definition: liblwgeom.h:355
double zmin
Definition: liblwgeom.h:358
double mmax
Definition: liblwgeom.h:361
double ymin
Definition: liblwgeom.h:356
double xmin
Definition: liblwgeom.h:354
double mmin
Definition: liblwgeom.h:360
lwflags_t flags
Definition: liblwgeom.h:353
uint8_t gflags
Definition: liblwgeom.h:446

References GBOX::flags, FP_MAX, FP_MIN, G2FLAGS_GET_BBOX, G2FLAGS_GET_GEODETIC, G2FLAGS_GET_M, G2FLAGS_GET_Z, G2FLAGS_NDIMS, gbox_float_round(), GSERIALIZED::gflags, gserialized2_get_geometry_p(), gserialized2_get_lwflags(), gserialized2_get_type(), LINETYPE, LW_FAILURE, LW_SUCCESS, GBOX::mmax, GBOX::mmin, MULTILINETYPE, MULTIPOINTTYPE, POINTTYPE, ovdump::type, GBOX::xmax, GBOX::xmin, GBOX::ymax, GBOX::ymin, GBOX::zmax, and GBOX::zmin.

Referenced by gserialized2_fast_gbox_p(), gserialized2_get_gbox_p(), test_gserialized2_peek_gbox_p_fails_for_unsupported_cases(), test_gserialized2_peek_gbox_p_gets_correct_box(), and test_gserialized2_peek_gbox_p_no_box_when_empty().

Here is the call graph for this function:
Here is the caller graph for this function: