PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ST_DistanceRectTreeCached()

Datum ST_DistanceRectTreeCached ( PG_FUNCTION_ARGS  )

Definition at line 149 of file lwgeom_rectree.c.

150 {
151  RectTreeGeomCache *tree_cache = NULL;
152  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
153  GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
154  LWGEOM *lwg1, *lwg2;
155 
156  /* Return NULL on empty arguments. */
158  {
159  PG_FREE_IF_COPY(g1, 0);
160  PG_FREE_IF_COPY(g2, 1);
161  PG_RETURN_NULL();
162  }
163 
164  lwg1 = lwgeom_from_gserialized(g1);
165  lwg2 = lwgeom_from_gserialized(g2);
166 
167  /* Two points? Get outa here... */
168  if (lwg1->type == POINTTYPE && lwg2->type == POINTTYPE)
169  PG_RETURN_FLOAT8(lwgeom_mindistance2d(lwg1, lwg2));
170 
171  /* Fetch/build our cache, if appropriate, etc... */
172  tree_cache = GetRectTreeGeomCache(fcinfo, g1, g2);
173 
174  if (tree_cache && tree_cache->gcache.argnum)
175  {
176  RECT_NODE *n;
177  RECT_NODE *n_cached = tree_cache->index;;
178  if (tree_cache->gcache.argnum == 1)
179  {
180  n = rect_tree_from_lwgeom(lwg2);
181  }
182  else if (tree_cache->gcache.argnum == 2)
183  {
184  n = rect_tree_from_lwgeom(lwg1);
185  }
186  else
187  {
188  elog(ERROR, "reached unreachable block in %s", __func__);
189  }
190  PG_RETURN_FLOAT8(rect_tree_distance_tree(n, n_cached, 0.0));
191  }
192  else
193  {
194  PG_RETURN_FLOAT8(lwgeom_mindistance2d(lwg1, lwg2));
195  }
196 
197  PG_RETURN_NULL();
198 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing min distance calculation.
Definition: measures.c:202
static RectTreeGeomCache * GetRectTreeGeomCache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2)
RECT_NODE * rect_tree_from_lwgeom(const LWGEOM *lwgeom)
Create a tree index on top an LWGEOM.
Definition: lwtree.c:861
double rect_tree_distance_tree(RECT_NODE *n1, RECT_NODE *n2, double threshold)
Return the distance between two RECT_NODE trees.
Definition: lwtree.c:1354
uint8_t type
Definition: liblwgeom.h:399
RECT_NODE * index

References RectTreeGeomCache::gcache, GetRectTreeGeomCache(), gserialized_is_empty(), RectTreeGeomCache::index, lwgeom_from_gserialized(), lwgeom_mindistance2d(), POINTTYPE, rect_tree_distance_tree(), rect_tree_from_lwgeom(), and LWGEOM::type.

Here is the call graph for this function: