PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ relate_pattern()

Datum relate_pattern ( PG_FUNCTION_ARGS  )

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

2487 {
2488  GSERIALIZED *geom1;
2489  GSERIALIZED *geom2;
2490  char *patt;
2491  text *ptxt;
2492  char result;
2493  GEOSGeometry *g1, *g2;
2494  size_t i;
2495 
2496  geom1 = PG_GETARG_GSERIALIZED_P(0);
2497  geom2 = PG_GETARG_GSERIALIZED_P(1);
2498  gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
2499 
2500  /* TODO handle empty */
2501 
2502  initGEOS(lwpgnotice, lwgeom_geos_error);
2503 
2504  g1 = POSTGIS2GEOS(geom1);
2505  if (!g1)
2506  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2507  g2 = POSTGIS2GEOS(geom2);
2508  if (!g2)
2509  {
2510  GEOSGeom_destroy(g1);
2511  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2512  }
2513 
2514  /* Ensure DE9IM pattern is no more than 9 chars */
2515  ptxt = DatumGetTextP(DirectFunctionCall2(text_left,
2516  PG_GETARG_DATUM(2), Int32GetDatum(9)));
2517  patt = text_to_cstring(ptxt);
2518 
2519  /*
2520  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
2521  */
2522  for ( i = 0; i < strlen(patt); i++ )
2523  {
2524  if ( patt[i] == 't' ) patt[i] = 'T';
2525  if ( patt[i] == 'f' ) patt[i] = 'F';
2526  }
2527 
2528  result = GEOSRelatePattern(g1,g2,patt);
2529  GEOSGeom_destroy(g1);
2530  GEOSGeom_destroy(g2);
2531  pfree(patt);
2532 
2533  if (result == 2) HANDLE_GEOS_ERROR("GEOSRelatePattern");
2534 
2535  PG_FREE_IF_COPY(geom1, 0);
2536  PG_FREE_IF_COPY(geom2, 1);
2537 
2538  PG_RETURN_BOOL(result);
2539 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:403
void lwgeom_geos_error(const char *fmt,...)
#define HANDLE_GEOS_ERROR(label)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)

References gserialized_error_if_srid_mismatch(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), POSTGIS2GEOS(), and result.

Here is the call graph for this function: