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 calculated distance drops below the tolerance (useful for dwithin calculations). Return a negative distance for incalculable cases.
2067{
2068 uint8_t type1, type2;
2071
2074
2075 assert(lwgeom1);
2076 assert(lwgeom2);
2077
2078 LWDEBUGF(4,
"entered function, tolerance %.8g", tolerance);
2079
2080
2081
2083 {
2084 return -1.0;
2085 }
2086
2087 type1 = lwgeom1->
type;
2088 type2 = lwgeom2->
type;
2089
2090
2092 gbox1 = *(lwgeom1->
bbox);
2093 else
2095
2096
2098 gbox2 = *(lwgeom2->
bbox);
2099 else
2101
2102
2105
2106
2109 {
2111
2113 pa1 = ((
LWPOINT*)lwgeom1)->point;
2114 else
2115 pa1 = ((
LWLINE*)lwgeom1)->points;
2116
2118 pa2 = ((
LWPOINT*)lwgeom2)->point;
2119 else
2120 pa2 = ((
LWLINE*)lwgeom2)->points;
2121
2123 }
2124
2125
2128 {
2133 uint32_t i;
2134
2136 {
2138 lwpoly = (
LWPOLY*)lwgeom2;
2139 }
2140 else
2141 {
2143 lwpoly = (
LWPOLY*)lwgeom1;
2144 }
2146
2147
2149 {
2150 return 0.0;
2151 }
2152
2153
2154 for ( i = 0; i < lwpoly->
nrings; i++ )
2155 {
2161 }
2163 }
2164
2165
2168 {
2173 uint32_t i;
2174
2176 {
2177 lwline = (
LWLINE*)lwgeom1;
2178 lwpoly = (
LWPOLY*)lwgeom2;
2179 }
2180 else
2181 {
2182 lwline = (
LWLINE*)lwgeom2;
2183 lwpoly = (
LWPOLY*)lwgeom1;
2184 }
2186
2187 LWDEBUG(4,
"checking if a point of line is in polygon");
2188
2189
2191 return 0.0;
2192
2193 LWDEBUG(4,
"checking ring distances");
2194
2195
2196 for ( i = 0; i < lwpoly->
nrings; i++ )
2197 {
2199 LWDEBUGF(4,
"ring[%d] ring_distance = %.8g", i, ring_distance);
2204 }
2207
2208 }
2209
2210
2211
2213 {
2218 uint32_t i, j;
2219
2220
2223
2224
2227
2228
2229 for (i = 0; i < lwpoly1->
nrings; i++)
2230 {
2231 for (j = 0; j < lwpoly2->
nrings; j++)
2232 {
2233 double ring_distance =
2237 spheroid,
2238 tolerance,
2239 check_intersection);
2243 }
2244 }
2246 }
2247
2248
2250 {
2251 uint32_t i;
2254
2255 for ( i = 0; i < col->
ngeoms; i++ )
2256 {
2258 col->
geoms[i], lwgeom2, spheroid, tolerance);
2263 }
2265 }
2266
2267
2269 {
2270 uint32_t i;
2273
2274 for ( i = 0; i < col->
ngeoms; i++ )
2275 {
2281 }
2283 }
2284
2285
2287 return -1.0;
2288
2289}
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.
#define FLAGS_GET_GEODETIC(flags)
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 void lwerror(const char *fmt,...) __attribute__((format(printf
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)