Calculate the distance between two LWGEOMs, using the coordinates are longitude and latitude.
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
Return immediately when the calulated distance drops below the tolerance (useful for dwithin calculations). Return a negative distance for incalculable cases.
2195 LWDEBUGF(4,
"entered function, tolerance %.8g", tolerance);
2204 type1 = lwgeom1->
type;
2205 type2 = lwgeom2->
type;
2208 if ( lwgeom1->
bbox )
2209 gbox1 = *(lwgeom1->
bbox);
2214 if ( lwgeom2->
bbox )
2215 gbox2 = *(lwgeom2->
bbox);
2230 pa1 = ((
LWPOINT*)lwgeom1)->point;
2232 pa1 = ((
LWLINE*)lwgeom1)->points;
2235 pa2 = ((
LWPOINT*)lwgeom2)->point;
2237 pa2 = ((
LWLINE*)lwgeom2)->points;
2255 lwpoly = (
LWPOLY*)lwgeom2;
2260 lwpoly = (
LWPOLY*)lwgeom1;
2271 for ( i = 0; i < lwpoly->
nrings; i++ )
2274 if ( ring_distance < distance )
2275 distance = ring_distance;
2276 if ( distance < tolerance )
2289 double distance = FLT_MAX;
2294 lwline = (
LWLINE*)lwgeom1;
2295 lwpoly = (
LWPOLY*)lwgeom2;
2299 lwline = (
LWLINE*)lwgeom2;
2300 lwpoly = (
LWPOLY*)lwgeom1;
2304 LWDEBUG(4,
"checking if a point of line is in polygon");
2310 LWDEBUG(4,
"checking ring distances");
2313 for ( i = 0; i < lwpoly->
nrings; i++ )
2316 LWDEBUGF(4,
"ring[%d] ring_distance = %.8g", i, ring_distance);
2317 if ( ring_distance < distance )
2318 distance = ring_distance;
2319 if ( distance < tolerance )
2322 LWDEBUGF(4,
"all rings checked, returning distance = %.8g", distance);
2334 double distance = FLT_MAX;
2348 for ( i = 0; i < lwpoly1->
nrings; i++ )
2350 for ( j = 0; j < lwpoly2->
nrings; j++ )
2353 if ( ring_distance < distance )
2354 distance = ring_distance;
2355 if ( distance < tolerance )
2366 double distance = FLT_MAX;
2369 for ( i = 0; i < col->
ngeoms; i++ )
2372 if ( geom_distance < distance )
2373 distance = geom_distance;
2374 if ( distance < tolerance )
2384 double distance = FLT_MAX;
2387 for ( i = 0; i < col->
ngeoms; i++ )
2390 if ( geom_distance < distance )
2391 distance = geom_distance;
2392 if ( distance < tolerance )
static double ptarray_distance_spheroid(const POINTARRAY *pa1, const POINTARRAY *pa2, const SPHEROID *s, double tolerance, int check_intersection)
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the distance between two LWGEOMs, using the coordinates are longitude and latitude...
#define LWDEBUG(level, msg)
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
#define LW_TRUE
Return types for functions with status returns.
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
Datum distance(PG_FUNCTION_ARGS)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
int lwpoly_covers_point2d(const LWPOLY *poly, const POINT2D *pt_to_test)
Given a polygon (lon/lat decimal degrees) and point (lon/lat decimal degrees) and a guaranteed outsid...
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.