PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum relate_pattern ( PG_FUNCTION_ARGS  )

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

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

2572 {
2573  GSERIALIZED *geom1;
2574  GSERIALIZED *geom2;
2575  char *patt;
2576  bool result;
2577  GEOSGeometry *g1, *g2;
2578  int i;
2579 
2580  geom1 = PG_GETARG_GSERIALIZED_P(0);
2581  geom2 = PG_GETARG_GSERIALIZED_P(1);
2582 
2583 
2584  /* TODO handle empty */
2585 
2586  errorIfGeometryCollection(geom1,geom2);
2588 
2589  initGEOS(lwpgnotice, lwgeom_geos_error);
2590 
2591  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2592  if ( 0 == g1 ) /* exception thrown at construction */
2593  {
2594  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2595  PG_RETURN_NULL();
2596  }
2597  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2598  if ( 0 == g2 ) /* exception thrown at construction */
2599  {
2600  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2601  GEOSGeom_destroy(g1);
2602  PG_RETURN_NULL();
2603  }
2604 
2605  patt = DatumGetCString(DirectFunctionCall1(textout,
2606  PointerGetDatum(PG_GETARG_DATUM(2))));
2607 
2608  /*
2609  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
2610  */
2611  for ( i = 0; i < strlen(patt); i++ )
2612  {
2613  if ( patt[i] == 't' ) patt[i] = 'T';
2614  if ( patt[i] == 'f' ) patt[i] = 'F';
2615  }
2616 
2617  result = GEOSRelatePattern(g1,g2,patt);
2618  GEOSGeom_destroy(g1);
2619  GEOSGeom_destroy(g2);
2620  pfree(patt);
2621 
2622  if (result == 2)
2623  {
2624  HANDLE_GEOS_ERROR("GEOSRelatePattern");
2625  PG_RETURN_NULL(); /* never get here */
2626  }
2627 
2628  PG_FREE_IF_COPY(geom1, 0);
2629  PG_FREE_IF_COPY(geom2, 1);
2630 
2631  PG_RETURN_BOOL(result);
2632 }
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
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:83
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.

Here is the call graph for this function: