PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ relate_pattern()

Datum relate_pattern ( PG_FUNCTION_ARGS  )

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

2386 {
2387  GSERIALIZED *geom1;
2388  GSERIALIZED *geom2;
2389  char *patt;
2390  char result;
2391  GEOSGeometry *g1, *g2;
2392  size_t i;
2393 
2394  geom1 = PG_GETARG_GSERIALIZED_P(0);
2395  geom2 = PG_GETARG_GSERIALIZED_P(1);
2396 
2397  /* TODO handle empty */
2398 
2399  errorIfGeometryCollection(geom1,geom2);
2401 
2402  initGEOS(lwpgnotice, lwgeom_geos_error);
2403 
2404  g1 = POSTGIS2GEOS(geom1);
2405  if (!g1)
2406  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2407  g2 = POSTGIS2GEOS(geom2);
2408  if (!g2)
2409  {
2410  GEOSGeom_destroy(g1);
2411  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2412  }
2413 
2414  patt = DatumGetCString(DirectFunctionCall1(textout,
2415  PointerGetDatum(PG_GETARG_DATUM(2))));
2416 
2417  /*
2418  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
2419  */
2420  for ( i = 0; i < strlen(patt); i++ )
2421  {
2422  if ( patt[i] == 't' ) patt[i] = 'T';
2423  if ( patt[i] == 'f' ) patt[i] = 'F';
2424  }
2425 
2426  result = GEOSRelatePattern(g1,g2,patt);
2427  GEOSGeom_destroy(g1);
2428  GEOSGeom_destroy(g2);
2429  pfree(patt);
2430 
2431  if (result == 2) HANDLE_GEOS_ERROR("GEOSRelatePattern");
2432 
2433  PG_FREE_IF_COPY(geom1, 0);
2434  PG_FREE_IF_COPY(geom2, 1);
2435 
2436  PG_RETURN_BOOL(result);
2437 }
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:100
void lwgeom_geos_error(const char *fmt,...)
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
#define HANDLE_GEOS_ERROR(label)
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)

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

Here is the call graph for this function: