PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ hausdorffdistancedensify()

Datum hausdorffdistancedensify ( PG_FUNCTION_ARGS  )

Definition at line 183 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 hausdorffdistance().

184 {
185 #if POSTGIS_GEOS_VERSION < 32
186  lwpgerror("The GEOS version this PostGIS binary "
187  "was compiled against (%d) doesn't support "
188  "'ST_HausdorffDistance' function (3.2.0+ required)",
190  PG_RETURN_NULL();
191 #else
192  GSERIALIZED *geom1;
193  GSERIALIZED *geom2;
194  GEOSGeometry *g1;
195  GEOSGeometry *g2;
196  double densifyFrac;
197  double result;
198  int retcode;
199 
200 
201  geom1 = PG_GETARG_GSERIALIZED_P(0);
202  geom2 = PG_GETARG_GSERIALIZED_P(1);
203  densifyFrac = PG_GETARG_FLOAT8(2);
204 
205  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
206  PG_RETURN_NULL();
207 
208  initGEOS(lwpgnotice, lwgeom_geos_error);
209 
210  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
211  if ( 0 == g1 ) /* exception thrown at construction */
212  {
213  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
214  PG_RETURN_NULL();
215  }
216 
217  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
218  if ( 0 == g2 ) /* exception thrown at construction */
219  {
220  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
221  GEOSGeom_destroy(g1);
222  PG_RETURN_NULL();
223  }
224 
225  retcode = GEOSHausdorffDistanceDensify(g1, g2, densifyFrac, &result);
226  GEOSGeom_destroy(g1);
227  GEOSGeom_destroy(g2);
228 
229  if (retcode == 0)
230  {
231  HANDLE_GEOS_ERROR("GEOSHausdorffDistanceDensify");
232  PG_RETURN_NULL(); /*never get here */
233  }
234 
235  PG_FREE_IF_COPY(geom1, 0);
236  PG_FREE_IF_COPY(geom2, 1);
237 
238  PG_RETURN_FLOAT8(result);
239 #endif
240 }
#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:139
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: