PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ geography_distance_cache_tolerance()

static int geography_distance_cache_tolerance ( FunctionCallInfo  fcinfo,
const GSERIALIZED g1,
const GSERIALIZED g2,
const SPHEROID s,
double  tolerance,
double *  distance 
)
static

Definition at line 157 of file geography_measurement_trees.c.

163 {
164  CircTreeGeomCache* tree_cache = NULL;
165 
166  int type1 = gserialized_get_type(g1);
167  int type2 = gserialized_get_type(g2);
168 
169  Assert(distance);
170 
171  /* Two points? Get outa here... */
172  if ( type1 == POINTTYPE && type2 == POINTTYPE )
173  return LW_FAILURE;
174 
175  /* Fetch/build our cache, if appropriate, etc... */
176  tree_cache = GetCircTreeGeomCache(fcinfo, g1, g2);
177 
178  /* OK, we have an index at the ready! Use it for the one tree argument and */
179  /* fill in the other tree argument */
180  if ( tree_cache && tree_cache->gcache.argnum && tree_cache->index )
181  {
182  CIRC_NODE* circtree_cached = tree_cache->index;
183  CIRC_NODE* circtree = NULL;
184  const GSERIALIZED* g_cached;
185  const GSERIALIZED* g;
186  LWGEOM* lwgeom = NULL;
187  int geomtype_cached;
188  int geomtype;
189  POINT4D p4d;
190 
191  /* We need to dynamically build a tree for the uncached side of the function call */
192  if ( tree_cache->gcache.argnum == 1 )
193  {
194  g_cached = g1;
195  g = g2;
196  geomtype_cached = type1;
197  geomtype = type2;
198  }
199  else if ( tree_cache->gcache.argnum == 2 )
200  {
201  g_cached = g2;
202  g = g1;
203  geomtype_cached = type2;
204  geomtype = type1;
205  }
206  else
207  {
208  lwpgerror("geography_distance_cache this cannot happen!");
209  return LW_FAILURE;
210  }
211 
212  lwgeom = lwgeom_from_gserialized(g);
213  if ( geomtype_cached == POLYGONTYPE || geomtype_cached == MULTIPOLYGONTYPE )
214  {
215  lwgeom_startpoint(lwgeom, &p4d);
216  if ( CircTreePIP(circtree_cached, g_cached, &p4d) )
217  {
218  *distance = 0.0;
219  lwgeom_free(lwgeom);
220  return LW_SUCCESS;
221  }
222  }
223 
224  circtree = lwgeom_calculate_circ_tree(lwgeom);
225  if ( geomtype == POLYGONTYPE || geomtype == MULTIPOLYGONTYPE )
226  {
227  POINT2D p2d;
228  circ_tree_get_point(circtree_cached, &p2d);
229  p4d.x = p2d.x;
230  p4d.y = p2d.y;
231  if ( CircTreePIP(circtree, g, &p4d) )
232  {
233  *distance = 0.0;
234  circ_tree_free(circtree);
235  lwgeom_free(lwgeom);
236  return LW_SUCCESS;
237  }
238  }
239 
240  *distance = circ_tree_distance_tree(circtree_cached, circtree, s, tolerance);
241  circ_tree_free(circtree);
242  lwgeom_free(lwgeom);
243  return LW_SUCCESS;
244  }
245  else
246  {
247  return LW_FAILURE;
248  }
249 }
char * s
Definition: cu_in_wkt.c:23
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
static CircTreeGeomCache * GetCircTreeGeomCache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2)
static int CircTreePIP(const CIRC_NODE *tree1, const GSERIALIZED *g1, const POINT4D *in_point)
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
Definition: lwgeom.c:2122
#define LW_FAILURE
Definition: liblwgeom.h:79
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POLYGONTYPE
Definition: liblwgeom.h:87
double circ_tree_distance_tree(const CIRC_NODE *n1, const CIRC_NODE *n2, const SPHEROID *spheroid, double threshold)
int circ_tree_get_point(const CIRC_NODE *node, POINT2D *pt)
Returns a POINT2D that is a vertex of the input shape.
void circ_tree_free(CIRC_NODE *node)
Recurse from top of node tree and free all children.
CIRC_NODE * lwgeom_calculate_circ_tree(const LWGEOM *lwgeom)
Datum distance(PG_FUNCTION_ARGS)
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.

References circ_tree_distance_tree(), circ_tree_free(), circ_tree_get_point(), CircTreePIP(), distance(), CircTreeGeomCache::gcache, GetCircTreeGeomCache(), gserialized_get_type(), CircTreeGeomCache::index, LW_FAILURE, LW_SUCCESS, lwgeom_calculate_circ_tree(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_startpoint(), MULTIPOLYGONTYPE, POINTTYPE, POLYGONTYPE, s, POINT2D::x, POINT4D::x, POINT2D::y, and POINT4D::y.

Referenced by geography_distance_cache(), and geography_dwithin_cache().

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