PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ST_FrechetDistance()

Datum ST_FrechetDistance ( PG_FUNCTION_ARGS  )

Definition at line 272 of file postgis/lwgeom_geos.c.

273 {
274 #if POSTGIS_GEOS_VERSION < 30700
275 
276  lwpgerror("The GEOS version this PostGIS binary "
277  "was compiled against (%d) doesn't support "
278  "'GEOSFechetDistance' function (3.7.0+ required)",
280  PG_RETURN_NULL();
281 
282 #else /* POSTGIS_GEOS_VERSION >= 30700 */
283  GSERIALIZED *geom1;
284  GSERIALIZED *geom2;
285  GEOSGeometry *g1;
286  GEOSGeometry *g2;
287  double densifyFrac;
288  double result;
289  int retcode;
290 
291  geom1 = PG_GETARG_GSERIALIZED_P(0);
292  geom2 = PG_GETARG_GSERIALIZED_P(1);
293  densifyFrac = PG_GETARG_FLOAT8(2);
294 
295  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
296  PG_RETURN_NULL();
297 
298  initGEOS(lwpgnotice, lwgeom_geos_error);
299 
300  g1 = POSTGIS2GEOS(geom1);
301  if (!g1)
302  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
303 
304  g2 = POSTGIS2GEOS(geom2);
305  if (!g2)
306  {
307  GEOSGeom_destroy(g1);
308  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
309  }
310 
311  if (densifyFrac <= 0.0)
312  {
313  retcode = GEOSFrechetDistance(g1, g2, &result);
314  }
315  else
316  {
317  retcode = GEOSFrechetDistanceDensify(g1, g2, densifyFrac, &result);
318  }
319 
320  GEOSGeom_destroy(g1);
321  GEOSGeom_destroy(g2);
322 
323  if (retcode == 0) HANDLE_GEOS_ERROR("GEOSFrechetDistance");
324 
325  PG_FREE_IF_COPY(geom1, 0);
326  PG_FREE_IF_COPY(geom2, 1);
327 
328  PG_RETURN_FLOAT8(result);
329 
330 #endif /* POSTGIS_GEOS_VERSION >= 30700 */
331 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:11

References gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), POSTGIS2GEOS(), POSTGIS_GEOS_VERSION, and result.

Here is the call graph for this function: