PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ geography_distance_uncached()

Datum geography_distance_uncached ( PG_FUNCTION_ARGS  )

Definition at line 134 of file geography_measurement.c.

135{
136 LWGEOM *lwgeom1 = NULL;
137 LWGEOM *lwgeom2 = NULL;
138 GSERIALIZED *g1 = NULL;
139 GSERIALIZED *g2 = NULL;
140 double distance;
141 double tolerance = FP_TOLERANCE;
142 bool use_spheroid = true;
143 SPHEROID s;
144
145 /* Get our geometry objects loaded into memory. */
146 g1 = PG_GETARG_GSERIALIZED_P(0);
147 g2 = PG_GETARG_GSERIALIZED_P(1);
148
149 /* Read our tolerance value. */
150 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
151 tolerance = PG_GETARG_FLOAT8(2);
152
153 /* Read our calculation type. */
154 if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
155 use_spheroid = PG_GETARG_BOOL(3);
156
157 gserialized_error_if_srid_mismatch(g1, g2, __func__);
158
159 /* Initialize spheroid */
160 spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
161
162 /* Set to sphere if requested */
163 if ( ! use_spheroid )
164 s.a = s.b = s.radius;
165
166 lwgeom1 = lwgeom_from_gserialized(g1);
167 lwgeom2 = lwgeom_from_gserialized(g2);
168
169 /* Return NULL on empty arguments. */
170 if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
171 {
172 PG_FREE_IF_COPY(g1, 0);
173 PG_FREE_IF_COPY(g2, 1);
174 PG_RETURN_NULL();
175 }
176
177 /* Make sure we have boxes attached */
178 lwgeom_add_bbox_deep(lwgeom1, NULL);
179 lwgeom_add_bbox_deep(lwgeom2, NULL);
180
181 distance = lwgeom_distance_spheroid(lwgeom1, lwgeom2, &s, tolerance);
182
183 POSTGIS_DEBUGF(2, "[GIST] '%s' got distance %g", __func__, distance);
184
185 /* Clean up */
186 lwgeom_free(lwgeom1);
187 lwgeom_free(lwgeom2);
188 PG_FREE_IF_COPY(g1, 0);
189 PG_FREE_IF_COPY(g2, 1);
190
191 /* Something went wrong, negative return... should already be eloged, return NULL */
192 if ( distance < 0.0 )
193 {
194 PG_RETURN_NULL();
195 }
196
197 PG_RETURN_FLOAT8(distance);
198}
char * s
Definition cu_in_wkt.c:23
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
int32_t gserialized_get_srid(const GSERIALIZED *g)
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)
Definition lwgeom.c:1138
void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox)
Compute a box for geom and all sub-geometries, if not already computed.
Definition lwgeom.c:696
#define FP_TOLERANCE
Floating point comparators.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:193
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032

References distance(), FP_TOLERANCE, gserialized_error_if_srid_mismatch(), gserialized_get_srid(), lwgeom_add_bbox_deep(), lwgeom_distance_spheroid(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), and s.

Here is the call graph for this function: