PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ ST_Equals()

Datum ST_Equals ( PG_FUNCTION_ARGS  )

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

References error_if_srid_mismatch(), errorIfGeometryCollection(), FALSE, gbox_same_2d_float(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_is_empty(), HANDLE_GEOS_ERROR, issimple(), LW_FALSE, lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), POSTGIS2GEOS(), and TRUE.

Referenced by relate_full().

3019 {
3020  GSERIALIZED *geom1;
3021  GSERIALIZED *geom2;
3022  GEOSGeometry *g1, *g2;
3023  bool result;
3024  GBOX box1, box2;
3025 
3026  geom1 = PG_GETARG_GSERIALIZED_P(0);
3027  geom2 = PG_GETARG_GSERIALIZED_P(1);
3028 
3029  errorIfGeometryCollection(geom1,geom2);
3031 
3032  /* Empty == Empty */
3033  if ( gserialized_is_empty(geom1) && gserialized_is_empty(geom2) )
3034  PG_RETURN_BOOL(TRUE);
3035 
3036  /*
3037  * short-circuit: If geom1 and geom2 do not have the same bounding box
3038  * we can return FALSE.
3039  */
3040  if ( gserialized_get_gbox_p(geom1, &box1) &&
3041  gserialized_get_gbox_p(geom2, &box2) )
3042  {
3043  if ( gbox_same_2d_float(&box1, &box2) == LW_FALSE )
3044  {
3045  PG_RETURN_BOOL(FALSE);
3046  }
3047  }
3048 
3049  /*
3050  * short-circuit: if geom1 and geom2 are binary-equivalent, we can return
3051  * TRUE. This is much faster than doing the comparison using GEOS.
3052  */
3053  if (VARSIZE(geom1) == VARSIZE(geom2) && !memcmp(geom1, geom2, VARSIZE(geom1))) {
3054  PG_RETURN_BOOL(TRUE);
3055  }
3056 
3057  initGEOS(lwpgnotice, lwgeom_geos_error);
3058 
3059  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
3060 
3061  if ( 0 == g1 ) /* exception thrown at construction */
3062  {
3063  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
3064  PG_RETURN_NULL();
3065  }
3066 
3067  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
3068 
3069  if ( 0 == g2 ) /* exception thrown at construction */
3070  {
3071  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
3072  GEOSGeom_destroy(g1);
3073  PG_RETURN_NULL();
3074  }
3075 
3076  result = GEOSEquals(g1,g2);
3077 
3078  GEOSGeom_destroy(g1);
3079  GEOSGeom_destroy(g2);
3080 
3081  if (result == 2)
3082  {
3083  HANDLE_GEOS_ERROR("GEOSEquals");
3084  PG_RETURN_NULL(); /*never get here */
3085  }
3086 
3087  PG_FREE_IF_COPY(geom1, 0);
3088  PG_FREE_IF_COPY(geom2, 1);
3089 
3090  PG_RETURN_BOOL(result);
3091 }
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:371
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:139
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:62
#define FALSE
Definition: dbfopen.c:168
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
Definition: g_box.c:164
#define TRUE
Definition: dbfopen.c:169
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:
Here is the caller graph for this function: