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

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

References error_if_srid_mismatch(), errorIfGeometryCollection(), FALSE, gbox_overlaps_2d(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_is_empty(), LW_FALSE, lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), result, and TRUE.

3020 {
3021  GSERIALIZED *geom1;
3022  GSERIALIZED *geom2;
3023  GEOSGeometry *g1, *g2;
3024  bool result;
3025  GBOX box1, box2;
3026 
3027  geom1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
3028  geom2 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
3029 
3030  errorIfGeometryCollection(geom1,geom2);
3032 
3033  /* Empty == Empty */
3034  if ( gserialized_is_empty(geom1) && gserialized_is_empty(geom2) )
3035  PG_RETURN_BOOL(TRUE);
3036 
3037  /*
3038  * short-circuit: Loose test, if geom2 bounding box does not overlap
3039  * geom1 bounding box we can prematurely return FALSE.
3040  *
3041  * TODO: use gbox_same_2d instead (not available at time of writing)
3042  */
3043  if ( gserialized_get_gbox_p(geom1, &box1) &&
3044  gserialized_get_gbox_p(geom2, &box2) )
3045  {
3046  if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
3047  {
3048  PG_RETURN_BOOL(FALSE);
3049  }
3050  }
3051 
3052  initGEOS(lwnotice, lwgeom_geos_error);
3053 
3054  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
3055 
3056  if ( 0 == g1 ) /* exception thrown at construction */
3057  {
3058  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
3059  PG_RETURN_NULL();
3060  }
3061 
3062  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
3063 
3064  if ( 0 == g2 ) /* exception thrown at construction */
3065  {
3066  lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
3067  GEOSGeom_destroy(g1);
3068  PG_RETURN_NULL();
3069  }
3070 
3071  result = GEOSEquals(g1,g2);
3072 
3073  GEOSGeom_destroy(g1);
3074  GEOSGeom_destroy(g2);
3075 
3076  if (result == 2)
3077  {
3078  lwerror("GEOSEquals: %s", lwgeom_geos_errmsg);
3079  PG_RETURN_NULL(); /*never get here */
3080  }
3081 
3082  PG_FREE_IF_COPY(geom1, 0);
3083  PG_FREE_IF_COPY(geom2, 1);
3084 
3085  PG_RETURN_BOOL(result);
3086 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:373
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
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
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,...)
#define LW_FALSE
Definition: liblwgeom.h:52
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
Definition: g_box.c:281
#define FALSE
Definition: dbfopen.c:169
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
#define TRUE
Definition: dbfopen.c:170
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: