PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ geom2d_brin_inclusion_add_value()

Datum geom2d_brin_inclusion_add_value ( PG_FUNCTION_ARGS  )

Definition at line 16 of file brin_2d.c.

17 {
18  BrinValues *column = (BrinValues *) PG_GETARG_POINTER(1);
19  Datum newval = PG_GETARG_DATUM(2);
20  bool isnull = PG_GETARG_BOOL(3);
21  BOX2DF box_geom, *box_key;
22 
23  /*
24  * If the new value is null, we record that we saw it if it's the first
25  * one; otherwise, there's nothing to do.
26  */
27  if (isnull)
28  {
29  if (column->bv_hasnulls)
30  PG_RETURN_BOOL(false);
31 
32  column->bv_hasnulls = true;
33  PG_RETURN_BOOL(true);
34  }
35 
36  /*
37  * check other cases where it is not possible to retrieve a box
38  */
39  if (gserialized_datum_get_box2df_p(newval, &box_geom) == LW_FAILURE)
40  {
41  /*
42  * Empty entries have to be supported in the opclass: test the passed
43  * new value for emptiness; if it returns true, we need to set the
44  * "contains empty" flag in the element (unless already set).
45  */
46  if (is_gserialized_from_datum_empty(newval)) {
47  if (!DatumGetBool(column->bv_values[INCLUSION_CONTAINS_EMPTY]))
48  {
49  column->bv_values[INCLUSION_CONTAINS_EMPTY] = BoolGetDatum(true);
50  PG_RETURN_BOOL(true);
51  }
52 
53  PG_RETURN_BOOL(false);
54  } else
55  {
56  /*
57  * in case the entry is not empty and it is not possible to
58  * retrieve a box, raise an error
59  */
60  elog(ERROR, "Error while extracting the box2df from the geom");
61  }
62  }
63 
64  /* if the recorded value is null, we just need to store the box2df */
65  if (column->bv_allnulls)
66  {
67  column->bv_values[INCLUSION_UNION] = datumCopy((Datum) &box_geom, false,
68  sizeof(BOX2DF));
69  column->bv_values[INCLUSION_UNMERGEABLE] = BoolGetDatum(false);
70  column->bv_values[INCLUSION_CONTAINS_EMPTY] = BoolGetDatum(false);
71  column->bv_allnulls = false;
72  PG_RETURN_BOOL(true);
73  }
74 
75  box_key = (BOX2DF *) column->bv_values[INCLUSION_UNION];
76 
77  /* Check if the stored bounding box already contains the geometry's one */
78  if (box2df_contains(box_key, &box_geom))
79  PG_RETURN_BOOL(false);
80 
81  /*
82  * Otherwise, we need to enlarge the stored box2df to make it contains the
83  * current geometry
84  */
85  box_key->xmin = Min(box_key->xmin, box_geom.xmin);
86  box_key->xmax = Max(box_key->xmax, box_geom.xmax);
87  box_key->ymin = Min(box_key->ymin, box_geom.ymin);
88  box_key->ymax = Max(box_key->ymax, box_geom.ymax);
89 
90  PG_RETURN_BOOL(true);
91 }
bool is_gserialized_from_datum_empty(Datum the_datum)
Definition: brin_common.c:4
bool box2df_contains(const BOX2DF *a, const BOX2DF *b)
int gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df)
Peak into a GSERIALIZED datum to find the bounding box.
#define LW_FAILURE
Definition: liblwgeom.h:79
if(!(yy_init))
#define INCLUSION_UNMERGEABLE
Definition: postgis_brin.h:20
#define INCLUSION_UNION
Definition: postgis_brin.h:19
#define INCLUSION_CONTAINS_EMPTY
Definition: postgis_brin.h:21

References box2df_contains(), gserialized_datum_get_box2df_p(), if(), INCLUSION_CONTAINS_EMPTY, INCLUSION_UNION, INCLUSION_UNMERGEABLE, is_gserialized_from_datum_empty(), and LW_FAILURE.

Here is the call graph for this function: