PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ hausdorffdistance()

Datum hausdorffdistance ( PG_FUNCTION_ARGS  )

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

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

Referenced by pip_short_circuit().

174 {
175  GSERIALIZED *geom1;
176  GSERIALIZED *geom2;
177  GEOSGeometry *g1;
178  GEOSGeometry *g2;
179  double result;
180  int retcode;
181 
182  POSTGIS_DEBUG(2, "hausdorff_distance called");
183 
184  geom1 = PG_GETARG_GSERIALIZED_P(0);
185  geom2 = PG_GETARG_GSERIALIZED_P(1);
186 
187  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
188  PG_RETURN_NULL();
189 
190  initGEOS(lwpgnotice, lwgeom_geos_error);
191 
192  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
193  if ( 0 == g1 ) /* exception thrown at construction */
194  {
195  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
196  PG_RETURN_NULL();
197  }
198 
199  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
200  if ( 0 == g2 ) /* exception thrown */
201  {
202  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
203  GEOSGeom_destroy(g1);
204  PG_RETURN_NULL();
205  }
206 
207  retcode = GEOSHausdorffDistance(g1, g2, &result);
208  GEOSGeom_destroy(g1);
209  GEOSGeom_destroy(g2);
210 
211  if (retcode == 0)
212  {
213  HANDLE_GEOS_ERROR("GEOSHausdorffDistance");
214  PG_RETURN_NULL(); /*never get here */
215  }
216 
217  PG_FREE_IF_COPY(geom1, 0);
218  PG_FREE_IF_COPY(geom2, 1);
219 
220  PG_RETURN_FLOAT8(result);
221 }
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: