PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ST_FrechetDistance()

Datum ST_FrechetDistance ( PG_FUNCTION_ARGS  )

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

References gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), pgis_union_geometry_array(), POSTGIS2GEOS(), and POSTGIS_GEOS_VERSION.

Referenced by hausdorffdistancedensify().

291 {
292 #if POSTGIS_GEOS_VERSION < 37
293 
294  lwpgerror("The GEOS version this PostGIS binary "
295  "was compiled against (%d) doesn't support "
296  "'GEOSFechetDistance' function (3.7.0+ required)",
298  PG_RETURN_NULL();
299 
300 #else /* POSTGIS_GEOS_VERSION >= 37 */
301  GSERIALIZED *geom1;
302  GSERIALIZED *geom2;
303  GEOSGeometry *g1;
304  GEOSGeometry *g2;
305  double densifyFrac;
306  double result;
307  int retcode;
308 
309  geom1 = PG_GETARG_GSERIALIZED_P(0);
310  geom2 = PG_GETARG_GSERIALIZED_P(1);
311  densifyFrac = PG_GETARG_FLOAT8(2);
312 
313  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
314  PG_RETURN_NULL();
315 
316  initGEOS(lwpgnotice, lwgeom_geos_error);
317 
318  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
319  if ( 0 == g1 ) /* exception thrown at construction */
320  {
321  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
322  PG_RETURN_NULL();
323  }
324 
325  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
326  if ( 0 == g2 ) /* exception thrown at construction */
327  {
328  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
329  GEOSGeom_destroy(g1);
330  PG_RETURN_NULL();
331  }
332 
333  if (densifyFrac <= 0.0)
334  {
335  retcode = GEOSFrechetDistance(g1, g2, &result);
336  }
337  else
338  {
339  retcode = GEOSFrechetDistanceDensify(g1, g2, densifyFrac, &result);
340  }
341 
342  GEOSGeom_destroy(g1);
343  GEOSGeom_destroy(g2);
344 
345  if (retcode == 0)
346  {
347  HANDLE_GEOS_ERROR("GEOSFrechetDistance");
348  PG_RETURN_NULL(); /*never get here */
349  }
350 
351  PG_FREE_IF_COPY(geom1, 0);
352  PG_FREE_IF_COPY(geom2, 1);
353 
354  PG_RETURN_FLOAT8(result);
355 
356 #endif /* POSTGIS_GEOS_VERSION >= 37 */
357 }
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
Here is the call graph for this function:
Here is the caller graph for this function: