PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum hausdorffdistance ( PG_FUNCTION_ARGS  )

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

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

118 {
119 #if POSTGIS_GEOS_VERSION < 32
120  lwpgerror("The GEOS version this PostGIS binary "
121  "was compiled against (%d) doesn't support "
122  "'ST_HausdorffDistance' function (3.2.0+ required)",
124  PG_RETURN_NULL();
125 #else
126  GSERIALIZED *geom1;
127  GSERIALIZED *geom2;
128  GEOSGeometry *g1;
129  GEOSGeometry *g2;
130  double result;
131  int retcode;
132 
133  POSTGIS_DEBUG(2, "hausdorff_distance called");
134 
135  geom1 = PG_GETARG_GSERIALIZED_P(0);
136  geom2 = PG_GETARG_GSERIALIZED_P(1);
137 
138  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
139  PG_RETURN_NULL();
140 
141  initGEOS(lwpgnotice, lwgeom_geos_error);
142 
143  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
144  if ( 0 == g1 ) /* exception thrown at construction */
145  {
146  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
147  PG_RETURN_NULL();
148  }
149 
150  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
151  if ( 0 == g2 ) /* exception thrown */
152  {
153  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
154  GEOSGeom_destroy(g1);
155  PG_RETURN_NULL();
156  }
157 
158  retcode = GEOSHausdorffDistance(g1, g2, &result);
159  GEOSGeom_destroy(g1);
160  GEOSGeom_destroy(g2);
161 
162  if (retcode == 0)
163  {
164  HANDLE_GEOS_ERROR("GEOSHausdorffDistance");
165  PG_RETURN_NULL(); /*never get here */
166  }
167 
168  PG_FREE_IF_COPY(geom1, 0);
169  PG_FREE_IF_COPY(geom2, 1);
170 
171  PG_RETURN_FLOAT8(result);
172 #endif
173 }
#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: