PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum hausdorffdistancedensify ( PG_FUNCTION_ARGS  )

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

References gserialized_is_empty(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), POSTGIS_GEOS_VERSION, and result.

178 {
179 #if POSTGIS_GEOS_VERSION < 32
180  lwerror("The GEOS version this PostGIS binary "
181  "was compiled against (%d) doesn't support "
182  "'ST_HausdorffDistance' function (3.2.0+ required)",
184  PG_RETURN_NULL();
185 #else
186  GSERIALIZED *geom1;
187  GSERIALIZED *geom2;
188  GEOSGeometry *g1;
189  GEOSGeometry *g2;
190  double densifyFrac;
191  double result;
192  int retcode;
193 
194 
195  geom1 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
196  geom2 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
197  densifyFrac = PG_GETARG_FLOAT8(2);
198 
199  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
200  PG_RETURN_NULL();
201 
202  initGEOS(lwnotice, lwgeom_geos_error);
203 
204  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
205  if ( 0 == g1 ) /* exception thrown at construction */
206  {
207  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
208  PG_RETURN_NULL();
209  }
210 
211  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
212  if ( 0 == g2 ) /* exception thrown at construction */
213  {
214  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
215  GEOSGeom_destroy(g1);
216  PG_RETURN_NULL();
217  }
218 
219  retcode = GEOSHausdorffDistanceDensify(g1, g2, densifyFrac, &result);
220  GEOSGeom_destroy(g1);
221  GEOSGeom_destroy(g2);
222 
223  if (retcode == 0)
224  {
225  lwerror("GEOSHausdorffDistanceDensify: %s", lwgeom_geos_errmsg);
226  PG_RETURN_NULL(); /*never get here */
227  }
228 
229  PG_FREE_IF_COPY(geom1, 0);
230  PG_FREE_IF_COPY(geom2, 1);
231 
232  PG_RETURN_FLOAT8(result);
233 #endif
234 }
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
char ** result
Definition: liblwgeom.h:218
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)

Here is the call graph for this function: