PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum geography_distance_tree ( PG_FUNCTION_ARGS  )

Definition at line 246 of file geography_measurement.c.

References SPHEROID::a, SPHEROID::b, distance(), geography_tree_distance(), gserialized_get_srid(), gserialized_is_empty(), LW_FAILURE, SPHEROID::radius, and s.

247 {
248  GSERIALIZED *g1 = NULL;
249  GSERIALIZED *g2 = NULL;
250  double tolerance;
251  double distance;
252  bool use_spheroid;
253  SPHEROID s;
254 
255  /* Get our geometry objects loaded into memory. */
256  g1 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
257  g2 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
258 
259  /* Return FALSE on empty arguments. */
261  {
262  PG_FREE_IF_COPY(g1, 0);
263  PG_FREE_IF_COPY(g2, 1);
264  PG_RETURN_FLOAT8(0.0);
265  }
266 
267  /* Read our tolerance value. */
268  tolerance = PG_GETARG_FLOAT8(2);
269 
270  /* Read our calculation type. */
271  use_spheroid = PG_GETARG_BOOL(3);
272 
273  /* Initialize spheroid */
274  spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
275 
276  /* Set to sphere if requested */
277  if ( ! use_spheroid )
278  s.a = s.b = s.radius;
279 
280  if ( geography_tree_distance(g1, g2, &s, tolerance, &distance) == LW_FAILURE )
281  {
282  elog(ERROR, "geography_distance_tree failed!");
283  PG_RETURN_NULL();
284  }
285 
286  PG_RETURN_FLOAT8(distance);
287 }
double b
Definition: liblwgeom.h:270
double radius
Definition: liblwgeom.h:274
int geography_tree_distance(const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, double *distance)
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
#define LW_FAILURE
Definition: liblwgeom.h:54
char * s
Definition: cu_in_wkt.c:24
Datum distance(PG_FUNCTION_ARGS)
double a
Definition: liblwgeom.h:269
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:70

Here is the call graph for this function: