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

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

References error_if_srid_mismatch(), errorIfGeometryCollection(), gserialized_get_srid(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), and POSTGIS2GEOS().

2868 {
2869  GSERIALIZED *geom1;
2870  GSERIALIZED *geom2;
2871  char *patt;
2872  bool result;
2873  GEOSGeometry *g1, *g2;
2874  int i;
2875 
2876  geom1 = PG_GETARG_GSERIALIZED_P(0);
2877  geom2 = PG_GETARG_GSERIALIZED_P(1);
2878 
2879 
2880  /* TODO handle empty */
2881 
2882  errorIfGeometryCollection(geom1,geom2);
2884 
2885  initGEOS(lwpgnotice, lwgeom_geos_error);
2886 
2887  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2888  if ( 0 == g1 ) /* exception thrown at construction */
2889  {
2890  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2891  PG_RETURN_NULL();
2892  }
2893  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2894  if ( 0 == g2 ) /* exception thrown at construction */
2895  {
2896  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2897  GEOSGeom_destroy(g1);
2898  PG_RETURN_NULL();
2899  }
2900 
2901  patt = DatumGetCString(DirectFunctionCall1(textout,
2902  PointerGetDatum(PG_GETARG_DATUM(2))));
2903 
2904  /*
2905  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
2906  */
2907  for ( i = 0; i < strlen(patt); i++ )
2908  {
2909  if ( patt[i] == 't' ) patt[i] = 'T';
2910  if ( patt[i] == 'f' ) patt[i] = 'F';
2911  }
2912 
2913  result = GEOSRelatePattern(g1,g2,patt);
2914  GEOSGeom_destroy(g1);
2915  GEOSGeom_destroy(g2);
2916  pfree(patt);
2917 
2918  if (result == 2)
2919  {
2920  HANDLE_GEOS_ERROR("GEOSRelatePattern");
2921  PG_RETURN_NULL(); /* never get here */
2922  }
2923 
2924  PG_FREE_IF_COPY(geom1, 0);
2925  PG_FREE_IF_COPY(geom2, 1);
2926 
2927  PG_RETURN_BOOL(result);
2928 }
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
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:69
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.

Here is the call graph for this function: