402 double tolerance = 0.0;
404 bool use_spheroid =
true;
408 g1 = PG_GETARG_GSERIALIZED_P(0);
409 g2 = PG_GETARG_GSERIALIZED_P(1);
412 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
413 tolerance = PG_GETARG_FLOAT8(2);
416 if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
417 use_spheroid = PG_GETARG_BOOL(3);
425 if ( ! use_spheroid )
426 s.a =
s.b =
s.radius;
434 PG_RETURN_BOOL(
false);
442 PG_FREE_IF_COPY(g1, 0);
443 PG_FREE_IF_COPY(g2, 1);
448 elog(ERROR,
"lwgeom_distance_spheroid returned negative!");
449 PG_RETURN_BOOL(
false);
452 PG_RETURN_BOOL(
distance <= tolerance);
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)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
void error_if_srid_mismatch(int srid1, int srid2)
Datum distance(PG_FUNCTION_ARGS)