PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ relate_pattern()

Datum relate_pattern ( PG_FUNCTION_ARGS  )

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

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

Referenced by disjoint().

2643 {
2644  GSERIALIZED *geom1;
2645  GSERIALIZED *geom2;
2646  char *patt;
2647  char result;
2648  GEOSGeometry *g1, *g2;
2649  int i;
2650 
2651  geom1 = PG_GETARG_GSERIALIZED_P(0);
2652  geom2 = PG_GETARG_GSERIALIZED_P(1);
2653 
2654 
2655  /* TODO handle empty */
2656 
2657  errorIfGeometryCollection(geom1,geom2);
2659 
2660  initGEOS(lwpgnotice, lwgeom_geos_error);
2661 
2662  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2663  if ( 0 == g1 ) /* exception thrown at construction */
2664  {
2665  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2666  PG_RETURN_NULL();
2667  }
2668  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2669  if ( 0 == g2 ) /* exception thrown at construction */
2670  {
2671  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2672  GEOSGeom_destroy(g1);
2673  PG_RETURN_NULL();
2674  }
2675 
2676  patt = DatumGetCString(DirectFunctionCall1(textout,
2677  PointerGetDatum(PG_GETARG_DATUM(2))));
2678 
2679  /*
2680  ** Need to make sure 't' and 'f' are upper-case before handing to GEOS
2681  */
2682  for ( i = 0; i < strlen(patt); i++ )
2683  {
2684  if ( patt[i] == 't' ) patt[i] = 'T';
2685  if ( patt[i] == 'f' ) patt[i] = 'F';
2686  }
2687 
2688  result = GEOSRelatePattern(g1,g2,patt);
2689  GEOSGeom_destroy(g1);
2690  GEOSGeom_destroy(g2);
2691  pfree(patt);
2692 
2693  if (result == 2)
2694  {
2695  HANDLE_GEOS_ERROR("GEOSRelatePattern");
2696  PG_RETURN_NULL(); /* never get here */
2697  }
2698 
2699  PG_FREE_IF_COPY(geom1, 0);
2700  PG_FREE_IF_COPY(geom2, 1);
2701 
2702  PG_RETURN_BOOL(result);
2703 }
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:371
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:100
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.
Here is the call graph for this function:
Here is the caller graph for this function: