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

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

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

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