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

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

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

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

Here is the call graph for this function: