PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ ST_FrechetDistance()

Datum ST_FrechetDistance ( PG_FUNCTION_ARGS  )

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

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