280 double tolerance = 0.0;
282 bool use_spheroid =
true;
287 g1 = PG_GETARG_GSERIALIZED_P(0);
288 g2 = PG_GETARG_GSERIALIZED_P(1);
291 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
292 tolerance = PG_GETARG_FLOAT8(2);
295 if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
296 use_spheroid = PG_GETARG_BOOL(3);
304 if ( ! use_spheroid )
310 PG_FREE_IF_COPY(g1, 0);
311 PG_FREE_IF_COPY(g2, 1);
312 PG_RETURN_BOOL(
FALSE);
322 if ( distance < 0.0 )
323 elog(ERROR,
"lwgeom_distance_spheroid returned negative!");
324 dwithin = (distance <= tolerance);
330 PG_FREE_IF_COPY(g1, 0);
331 PG_FREE_IF_COPY(g2, 1);
333 PG_RETURN_BOOL(dwithin);
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
void error_if_srid_mismatch(int srid1, int srid2)
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Datum distance(PG_FUNCTION_ARGS)
int geography_dwithin_cache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, int *dwithin)
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.
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)...