PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ST_FrechetDistance()

Datum ST_FrechetDistance ( PG_FUNCTION_ARGS  )

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

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