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

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

References error_if_srid_mismatch(), errorIfGeometryCollection(), gserialized_get_srid(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), and result.

2870 {
2871  GSERIALIZED *geom1;
2872  GSERIALIZED *geom2;
2873  char *patt;
2874  bool result;
2875  GEOSGeometry *g1, *g2;
2876  int i;
2877 
2878  geom1 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2879  geom2 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2880 
2881 
2882  /* TODO handle empty */
2883 
2884  errorIfGeometryCollection(geom1,geom2);
2886 
2887  initGEOS(lwnotice, lwgeom_geos_error);
2888 
2889  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2890  if ( 0 == g1 ) /* exception thrown at construction */
2891  {
2892  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
2893  PG_RETURN_NULL();
2894  }
2895  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2896  if ( 0 == g2 ) /* exception thrown at construction */
2897  {
2898  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
2899  GEOSGeom_destroy(g1);
2900  PG_RETURN_NULL();
2901  }
2902 
2903  patt = DatumGetCString(DirectFunctionCall1(textout,
2904  PointerGetDatum(PG_GETARG_DATUM(2))));
2905 
2906  /*
2907  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
2908  */
2909  for ( i = 0; i < strlen(patt); i++ )
2910  {
2911  if ( patt[i] == 't' ) patt[i] = 'T';
2912  if ( patt[i] == 'f' ) patt[i] = 'F';
2913  }
2914 
2915  result = GEOSRelatePattern(g1,g2,patt);
2916  GEOSGeom_destroy(g1);
2917  GEOSGeom_destroy(g2);
2918  pfree(patt);
2919 
2920  if (result == 2)
2921  {
2922  lwerror("GEOSRelatePattern: %s", lwgeom_geos_errmsg);
2923  PG_RETURN_NULL(); /* never get here */
2924  }
2925 
2926  PG_FREE_IF_COPY(geom1, 0);
2927  PG_FREE_IF_COPY(geom2, 1);
2928 
2929  PG_RETURN_BOOL(result);
2930 }
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:317
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
char ** result
Definition: liblwgeom.h:218
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)
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:70
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.

Here is the call graph for this function: