PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ relate_pattern()

Datum relate_pattern ( PG_FUNCTION_ARGS  )

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

2514 {
2515  GSERIALIZED *geom1;
2516  GSERIALIZED *geom2;
2517  char *patt;
2518  text *ptxt;
2519  char result;
2520  GEOSGeometry *g1, *g2;
2521  size_t i;
2522 
2523  geom1 = PG_GETARG_GSERIALIZED_P(0);
2524  geom2 = PG_GETARG_GSERIALIZED_P(1);
2525  gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
2526 
2527  /* TODO handle empty */
2528 
2529  initGEOS(lwpgnotice, lwgeom_geos_error);
2530 
2531  g1 = POSTGIS2GEOS(geom1);
2532  if (!g1)
2533  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2534  g2 = POSTGIS2GEOS(geom2);
2535  if (!g2)
2536  {
2537  GEOSGeom_destroy(g1);
2538  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2539  }
2540 
2541  /* Ensure DE9IM pattern is no more than 9 chars */
2542  ptxt = DatumGetTextP(DirectFunctionCall2(text_left,
2543  PG_GETARG_DATUM(2), Int32GetDatum(9)));
2544  patt = text_to_cstring(ptxt);
2545 
2546  /*
2547  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
2548  */
2549  for ( i = 0; i < strlen(patt); i++ )
2550  {
2551  if ( patt[i] == 't' ) patt[i] = 'T';
2552  if ( patt[i] == 'f' ) patt[i] = 'F';
2553  }
2554 
2555  result = GEOSRelatePattern(g1,g2,patt);
2556  GEOSGeom_destroy(g1);
2557  GEOSGeom_destroy(g2);
2558  pfree(patt);
2559 
2560  if (result == 2) HANDLE_GEOS_ERROR("GEOSRelatePattern");
2561 
2562  PG_FREE_IF_COPY(geom1, 0);
2563  PG_FREE_IF_COPY(geom2, 1);
2564 
2565  PG_RETURN_BOOL(result);
2566 }
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:404
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: