Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
A spheroid with major axis == minor axis will be treated as a sphere. Pass in a tolerance in spheroid units.
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
Return immediately when the calculated distance drops below the tolerance (useful for dwithin calculations). Return a negative distance for incalculable cases.
2188{
2189 uint8_t type1, type2;
2192
2195
2196 assert(lwgeom1);
2197 assert(lwgeom2);
2198
2199 LWDEBUGF(4,
"entered function, tolerance %.8g", tolerance);
2200
2201
2202
2204 {
2205 return -1.0;
2206 }
2207
2208 type1 = lwgeom1->
type;
2209 type2 = lwgeom2->
type;
2210
2211
2212 if ( lwgeom1->
bbox )
2213 gbox1 = *(lwgeom1->
bbox);
2214 else
2216
2217
2218 if ( lwgeom2->
bbox )
2219 gbox2 = *(lwgeom2->
bbox);
2220 else
2222
2223
2226
2227
2230 {
2232
2234 pa1 = ((
LWPOINT*)lwgeom1)->point;
2235 else
2236 pa1 = ((
LWLINE*)lwgeom1)->points;
2237
2239 pa2 = ((
LWPOINT*)lwgeom2)->point;
2240 else
2241 pa2 = ((
LWLINE*)lwgeom2)->points;
2242
2244 }
2245
2246
2249 {
2254 uint32_t i;
2255
2257 {
2259 lwpoly = (
LWPOLY*)lwgeom2;
2260 }
2261 else
2262 {
2264 lwpoly = (
LWPOLY*)lwgeom1;
2265 }
2267
2268
2270 {
2271 return 0.0;
2272 }
2273
2274
2275 for ( i = 0; i < lwpoly->
nrings; i++ )
2276 {
2282 }
2284 }
2285
2286
2289 {
2294 uint32_t i;
2295
2297 {
2298 lwline = (
LWLINE*)lwgeom1;
2299 lwpoly = (
LWPOLY*)lwgeom2;
2300 }
2301 else
2302 {
2303 lwline = (
LWLINE*)lwgeom2;
2304 lwpoly = (
LWPOLY*)lwgeom1;
2305 }
2307
2308 LWDEBUG(4,
"checking if a point of line is in polygon");
2309
2310
2312 return 0.0;
2313
2314 LWDEBUG(4,
"checking ring distances");
2315
2316
2317 for ( i = 0; i < lwpoly->
nrings; i++ )
2318 {
2320 LWDEBUGF(4,
"ring[%d] ring_distance = %.8g", i, ring_distance);
2325 }
2328
2329 }
2330
2331
2332
2334 {
2339 uint32_t i, j;
2340
2341
2344
2345
2348
2349
2350 for (i = 0; i < lwpoly1->
nrings; i++)
2351 {
2352 for (j = 0; j < lwpoly2->
nrings; j++)
2353 {
2354 double ring_distance =
2358 spheroid,
2359 tolerance,
2360 check_intersection);
2364 }
2365 }
2367 }
2368
2369
2371 {
2372 uint32_t i;
2375
2376 for ( i = 0; i < col->
ngeoms; i++ )
2377 {
2379 col->
geoms[i], lwgeom2, spheroid, tolerance);
2384 }
2386 }
2387
2388
2390 {
2391 uint32_t i;
2394
2395 for ( i = 0; i < col->
ngeoms; i++ )
2396 {
2402 }
2404 }
2405
2406
2408 return -1.0;
2409
2410}
int gbox_overlaps(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps, LW_FALSE otherwise.
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define LW_TRUE
Return types for functions with status returns.
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...
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.
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
static double ptarray_distance_spheroid(const POINTARRAY *pa1, const POINTARRAY *pa2, const SPHEROID *s, double tolerance, int check_intersection)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
static double distance(double x1, double y1, double x2, double y2)