PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ relate_pattern()

Datum relate_pattern ( PG_FUNCTION_ARGS  )

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

2583 {
2584  GSERIALIZED *geom1;
2585  GSERIALIZED *geom2;
2586  char *patt;
2587  text *ptxt;
2588  char result;
2589  GEOSGeometry *g1, *g2;
2590  size_t i;
2591 
2592  geom1 = PG_GETARG_GSERIALIZED_P(0);
2593  geom2 = PG_GETARG_GSERIALIZED_P(1);
2594  gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
2595 
2596  /* TODO handle empty */
2597 
2598  initGEOS(lwpgnotice, lwgeom_geos_error);
2599 
2600  g1 = POSTGIS2GEOS(geom1);
2601  if (!g1)
2602  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2603  g2 = POSTGIS2GEOS(geom2);
2604  if (!g2)
2605  {
2606  GEOSGeom_destroy(g1);
2607  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2608  }
2609 
2610  /* Ensure DE9IM pattern is no more than 9 chars */
2611  ptxt = DatumGetTextP(DirectFunctionCall2(text_left,
2612  PG_GETARG_DATUM(2), Int32GetDatum(9)));
2613  patt = text_to_cstring(ptxt);
2614 
2615  /*
2616  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
2617  */
2618  for ( i = 0; i < strlen(patt); i++ )
2619  {
2620  if ( patt[i] == 't' ) patt[i] = 'T';
2621  if ( patt[i] == 'f' ) patt[i] = 'F';
2622  }
2623 
2624  result = GEOSRelatePattern(g1,g2,patt);
2625  GEOSGeom_destroy(g1);
2626  GEOSGeom_destroy(g2);
2627  pfree(patt);
2628 
2629  if (result == 2) HANDLE_GEOS_ERROR("GEOSRelatePattern");
2630 
2631  PG_FREE_IF_COPY(geom1, 0);
2632  PG_FREE_IF_COPY(geom2, 1);
2633 
2634  PG_RETURN_BOOL(result);
2635 }
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: