PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ST_Equals()

Datum ST_Equals ( PG_FUNCTION_ARGS  )

Definition at line 2778 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().

2779 {
2780  GSERIALIZED *geom1;
2781  GSERIALIZED *geom2;
2782  GEOSGeometry *g1, *g2;
2783  char result;
2784  GBOX box1, box2;
2785 
2786  geom1 = PG_GETARG_GSERIALIZED_P(0);
2787  geom2 = PG_GETARG_GSERIALIZED_P(1);
2788 
2789  errorIfGeometryCollection(geom1,geom2);
2791 
2792  /* Empty == Empty */
2793  if ( gserialized_is_empty(geom1) && gserialized_is_empty(geom2) )
2794  PG_RETURN_BOOL(TRUE);
2795 
2796  /*
2797  * short-circuit: If geom1 and geom2 do not have the same bounding box
2798  * we can return FALSE.
2799  */
2800  if ( gserialized_get_gbox_p(geom1, &box1) &&
2801  gserialized_get_gbox_p(geom2, &box2) )
2802  {
2803  if ( gbox_same_2d_float(&box1, &box2) == LW_FALSE )
2804  {
2805  PG_RETURN_BOOL(FALSE);
2806  }
2807  }
2808 
2809  /*
2810  * short-circuit: if geom1 and geom2 are binary-equivalent, we can return
2811  * TRUE. This is much faster than doing the comparison using GEOS.
2812  */
2813  if (VARSIZE(geom1) == VARSIZE(geom2) && !memcmp(geom1, geom2, VARSIZE(geom1))) {
2814  PG_RETURN_BOOL(TRUE);
2815  }
2816 
2817  initGEOS(lwpgnotice, lwgeom_geos_error);
2818 
2819  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2820 
2821  if ( 0 == g1 ) /* exception thrown at construction */
2822  {
2823  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2824  PG_RETURN_NULL();
2825  }
2826 
2827  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2828 
2829  if ( 0 == g2 ) /* exception thrown at construction */
2830  {
2831  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2832  GEOSGeom_destroy(g1);
2833  PG_RETURN_NULL();
2834  }
2835 
2836  result = GEOSEquals(g1,g2);
2837 
2838  GEOSGeom_destroy(g1);
2839  GEOSGeom_destroy(g2);
2840 
2841  if (result == 2)
2842  {
2843  HANDLE_GEOS_ERROR("GEOSEquals");
2844  PG_RETURN_NULL(); /*never get here */
2845  }
2846 
2847  PG_FREE_IF_COPY(geom1, 0);
2848  PG_FREE_IF_COPY(geom2, 1);
2849 
2850  PG_RETURN_BOOL(result);
2851 }
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:642
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:371
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:77
#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:100
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: