PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum relate_full ( PG_FUNCTION_ARGS  )

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

References error_if_srid_mismatch(), errorIfGeometryCollection(), gserialized_get_srid(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), POSTGIS_GEOS_VERSION, and result.

2936 {
2937  GSERIALIZED *geom1;
2938  GSERIALIZED *geom2;
2939  GEOSGeometry *g1, *g2;
2940  char *relate_str;
2941  text *result;
2942 #if POSTGIS_GEOS_VERSION >= 33
2943  int bnr = GEOSRELATE_BNR_OGC;
2944 #endif
2945 
2946  POSTGIS_DEBUG(2, "in relate_full()");
2947 
2948  /* TODO handle empty */
2949 
2950  geom1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2951  geom2 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2952 
2953  if ( PG_NARGS() > 2 ) {
2954 #if POSTGIS_GEOS_VERSION >= 33
2955  bnr = PG_GETARG_INT32(2);
2956 #else
2957  lwerror("The GEOS version this PostGIS binary "
2958  "was compiled against (%d) doesn't support "
2959  "specifying a boundary node rule with ST_Relate"
2960  " (3.3.0+ required)",
2962  PG_RETURN_NULL();
2963 #endif
2964  }
2965 
2966  errorIfGeometryCollection(geom1,geom2);
2968 
2969  initGEOS(lwnotice, lwgeom_geos_error);
2970 
2971  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1 );
2972  if ( 0 == g1 ) /* exception thrown at construction */
2973  {
2974  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
2975  PG_RETURN_NULL();
2976  }
2977  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2 );
2978  if ( 0 == g2 ) /* exception thrown at construction */
2979  {
2980  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
2981  GEOSGeom_destroy(g1);
2982  PG_RETURN_NULL();
2983  }
2984 
2985  POSTGIS_DEBUG(3, "constructed geometries ");
2986 
2987  if ((g1==NULL) || (g2 == NULL))
2988  elog(NOTICE,"g1 or g2 are null");
2989 
2990  POSTGIS_DEBUGF(3, "%s", GEOSGeomToWKT(g1));
2991  POSTGIS_DEBUGF(3, "%s", GEOSGeomToWKT(g2));
2992 
2993 #if POSTGIS_GEOS_VERSION >= 33
2994  relate_str = GEOSRelateBoundaryNodeRule(g1, g2, bnr);
2995 #else
2996  relate_str = GEOSRelate(g1, g2);
2997 #endif
2998 
2999  GEOSGeom_destroy(g1);
3000  GEOSGeom_destroy(g2);
3001 
3002  if (relate_str == NULL)
3003  {
3004  lwerror("GEOSRelate: %s", lwgeom_geos_errmsg);
3005  PG_RETURN_NULL(); /* never get here */
3006  }
3007 
3008  result = cstring2text(relate_str);
3009  GEOSFree(relate_str);
3010 
3011  PG_FREE_IF_COPY(geom1, 0);
3012  PG_FREE_IF_COPY(geom2, 1);
3013 
3014  PG_RETURN_TEXT_P(result);
3015 }
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:317
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
char ** result
Definition: liblwgeom.h:218
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
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:70
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.

Here is the call graph for this function: