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

Definition at line 2707 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, LW_FALSE, lwgeom_geos_error(), POSTGIS2GEOS(), and TRUE.

2708 {
2709  GSERIALIZED *geom1;
2710  GSERIALIZED *geom2;
2711  GEOSGeometry *g1, *g2;
2712  bool result;
2713  GBOX box1, box2;
2714 
2715  geom1 = PG_GETARG_GSERIALIZED_P(0);
2716  geom2 = PG_GETARG_GSERIALIZED_P(1);
2717 
2718  errorIfGeometryCollection(geom1,geom2);
2720 
2721  /* Empty == Empty */
2722  if ( gserialized_is_empty(geom1) && gserialized_is_empty(geom2) )
2723  PG_RETURN_BOOL(TRUE);
2724 
2725  /*
2726  * short-circuit: If geom1 and geom2 do not have the same bounding box
2727  * we can return FALSE.
2728  */
2729  if ( gserialized_get_gbox_p(geom1, &box1) &&
2730  gserialized_get_gbox_p(geom2, &box2) )
2731  {
2732  if ( gbox_same_2d_float(&box1, &box2) == LW_FALSE )
2733  {
2734  PG_RETURN_BOOL(FALSE);
2735  }
2736  }
2737 
2738  /*
2739  * short-circuit: if geom1 and geom2 are binary-equivalent, we can return
2740  * TRUE. This is much faster than doing the comparison using GEOS.
2741  */
2742  if (VARSIZE(geom1) == VARSIZE(geom2) && !memcmp(geom1, geom2, VARSIZE(geom1))) {
2743  PG_RETURN_BOOL(TRUE);
2744  }
2745 
2746  initGEOS(lwpgnotice, lwgeom_geos_error);
2747 
2748  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2749 
2750  if ( 0 == g1 ) /* exception thrown at construction */
2751  {
2752  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2753  PG_RETURN_NULL();
2754  }
2755 
2756  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2757 
2758  if ( 0 == g2 ) /* exception thrown at construction */
2759  {
2760  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2761  GEOSGeom_destroy(g1);
2762  PG_RETURN_NULL();
2763  }
2764 
2765  result = GEOSEquals(g1,g2);
2766 
2767  GEOSGeom_destroy(g1);
2768  GEOSGeom_destroy(g2);
2769 
2770  if (result == 2)
2771  {
2772  HANDLE_GEOS_ERROR("GEOSEquals");
2773  PG_RETURN_NULL(); /*never get here */
2774  }
2775 
2776  PG_FREE_IF_COPY(geom1, 0);
2777  PG_FREE_IF_COPY(geom2, 1);
2778 
2779  PG_RETURN_BOOL(result);
2780 }
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:398
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:76
#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:199
#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:83
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.

Here is the call graph for this function: