269 SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
270 SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
271 const GSERIALIZED *g1 = shared_gserialized_get(shared_geom1);
272 const GSERIALIZED *g2 = shared_gserialized_get(shared_geom2);
275 bool use_spheroid =
true;
282 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
283 tolerance = PG_GETARG_FLOAT8(2);
286 if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
287 use_spheroid = PG_GETARG_BOOL(3);
293 if ( ! use_spheroid )
294 s.a =
s.b =
s.radius;
298 PG_RETURN_BOOL(
false);
308 elog(ERROR,
"lwgeom_distance_spheroid returned negative!");
314 PG_RETURN_BOOL(dwithin);
int geography_dwithin_cache(FunctionCallInfo fcinfo, SHARED_GSERIALIZED *g1, SHARED_GSERIALIZED *g2, const SPHEROID *s, double tolerance, int *dwithin)
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
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.
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
void lwgeom_free(LWGEOM *geom)
#define FP_TOLERANCE
Floating point comparators.
static double distance(double x1, double y1, double x2, double y2)