PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ relate_pattern()

Datum relate_pattern ( PG_FUNCTION_ARGS  )

Definition at line 900 of file lwgeom_geos_predicates.c.

901 {
902  SHARED_GSERIALIZED *shared_geom1 = ToastCacheGetGeometry(fcinfo, 0);
903  SHARED_GSERIALIZED *shared_geom2 = ToastCacheGetGeometry(fcinfo, 1);
904  const GSERIALIZED *geom1 = shared_gserialized_get(shared_geom1);
905  const GSERIALIZED *geom2 = shared_gserialized_get(shared_geom2);
906 
907  /* Ensure DE9IM pattern is no more than 9 chars */
908  text *imPtr = DatumGetTextP(DirectFunctionCall2(text_left,
909  PG_GETARG_DATUM(2), Int32GetDatum(9)));
910  char *im = text_to_cstring(imPtr);
911  char result;
912  uint32_t i;
913 #if POSTGIS_GEOS_VERSION >= 31300
914  PrepGeomCache *prep_cache;
915 #endif
916 
917  gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
918 
919  /*
920  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
921  */
922  for (i = 0; i < strlen(im); i++)
923  im[i] = toupper(im[i]);
924 
925  initGEOS(lwpgnotice, lwgeom_geos_error);
926 
927 #if POSTGIS_GEOS_VERSION >= 31300
928  prep_cache = GetPrepGeomCache(fcinfo, shared_geom1, shared_geom2);
929  if ( prep_cache && prep_cache->prepared_geom )
930  {
931  GEOSGeometry *g = NULL;
932  if (prep_cache->gcache.argnum == 1)
933  {
934  g = POSTGIS2GEOS(geom2);
935  }
936  else
937  {
938  g = POSTGIS2GEOS(geom1);
939  imInvert(im);
940  }
941 
942  if (!g) HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
943  result = GEOSPreparedRelatePattern(prep_cache->prepared_geom, g, im);
944  GEOSGeom_destroy(g);
945  }
946  else
947 #endif
948  {
949  GEOSGeometry *g1, *g2;
950  g1 = POSTGIS2GEOS(geom1);
951  if (!g1) HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
952  g2 = POSTGIS2GEOS(geom2);
953  if (!g2)
954  {
955  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
956  GEOSGeom_destroy(g1);
957  }
958  result = GEOSRelatePattern(g1, g2, im);
959  GEOSGeom_destroy(g1);
960  GEOSGeom_destroy(g2);
961  }
962 
963  pfree(im);
964  if (result == 2) HANDLE_GEOS_ERROR("GEOSRelatePattern");
965 
966  PG_RETURN_BOOL(result);
967 }
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:432
void lwgeom_geos_error(const char *fmt,...)
PrepGeomCache * GetPrepGeomCache(FunctionCallInfo fcinfo, SHARED_GSERIALIZED *g1, SHARED_GSERIALIZED *g2)
Given a couple potential geometries and a function call context, return a prepared structure for one ...
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
const GEOSPreparedGeometry * prepared_geom

References PrepGeomCache::gcache, GetPrepGeomCache(), gserialized_error_if_srid_mismatch(), HANDLE_GEOS_ERROR, lwgeom_geos_error(), POSTGIS2GEOS(), PrepGeomCache::prepared_geom, and result.

Here is the call graph for this function: