PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ hausdorffdistancedensify()

Datum hausdorffdistancedensify ( PG_FUNCTION_ARGS  )

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

References gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), POSTGIS2GEOS(), and ST_FrechetDistance().

Referenced by hausdorffdistance().

232 {
233  GSERIALIZED *geom1;
234  GSERIALIZED *geom2;
235  GEOSGeometry *g1;
236  GEOSGeometry *g2;
237  double densifyFrac;
238  double result;
239  int retcode;
240 
241 
242  geom1 = PG_GETARG_GSERIALIZED_P(0);
243  geom2 = PG_GETARG_GSERIALIZED_P(1);
244  densifyFrac = PG_GETARG_FLOAT8(2);
245 
246  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
247  PG_RETURN_NULL();
248 
249  initGEOS(lwpgnotice, lwgeom_geos_error);
250 
251  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
252  if ( 0 == g1 ) /* exception thrown at construction */
253  {
254  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
255  PG_RETURN_NULL();
256  }
257 
258  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
259  if ( 0 == g2 ) /* exception thrown at construction */
260  {
261  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
262  GEOSGeom_destroy(g1);
263  PG_RETURN_NULL();
264  }
265 
266  retcode = GEOSHausdorffDistanceDensify(g1, g2, densifyFrac, &result);
267  GEOSGeom_destroy(g1);
268  GEOSGeom_destroy(g2);
269 
270  if (retcode == 0)
271  {
272  HANDLE_GEOS_ERROR("GEOSHausdorffDistanceDensify");
273  PG_RETURN_NULL(); /*never get here */
274  }
275 
276  PG_FREE_IF_COPY(geom1, 0);
277  PG_FREE_IF_COPY(geom2, 1);
278 
279  PG_RETURN_FLOAT8(result);
280 }
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: