PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ ST_Equals()

Datum ST_Equals ( PG_FUNCTION_ARGS  )

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

References error_if_srid_mismatch(), errorIfGeometryCollection(), 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(), and POSTGIS2GEOS().

Referenced by relate_full().

2503 {
2504  GSERIALIZED *geom1;
2505  GSERIALIZED *geom2;
2506  GEOSGeometry *g1, *g2;
2507  char result;
2508  GBOX box1, box2;
2509 
2510  geom1 = PG_GETARG_GSERIALIZED_P(0);
2511  geom2 = PG_GETARG_GSERIALIZED_P(1);
2512 
2513  errorIfGeometryCollection(geom1,geom2);
2515 
2516  /* Empty == Empty */
2517  if ( gserialized_is_empty(geom1) && gserialized_is_empty(geom2) )
2518  PG_RETURN_BOOL(true);
2519 
2520  /*
2521  * short-circuit: If geom1 and geom2 do not have the same bounding box
2522  * we can return FALSE.
2523  */
2524  if ( gserialized_get_gbox_p(geom1, &box1) &&
2525  gserialized_get_gbox_p(geom2, &box2) )
2526  {
2527  if ( gbox_same_2d_float(&box1, &box2) == LW_FALSE )
2528  {
2529  PG_RETURN_BOOL(false);
2530  }
2531  }
2532 
2533  /*
2534  * short-circuit: if geom1 and geom2 are binary-equivalent, we can return
2535  * TRUE. This is much faster than doing the comparison using GEOS.
2536  */
2537  if (VARSIZE(geom1) == VARSIZE(geom2) && !memcmp(geom1, geom2, VARSIZE(geom1))) {
2538  PG_RETURN_BOOL(true);
2539  }
2540 
2541  initGEOS(lwpgnotice, lwgeom_geos_error);
2542 
2543  g1 = POSTGIS2GEOS(geom1);
2544 
2545  if (!g1)
2546  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2547 
2548  g2 = POSTGIS2GEOS(geom2);
2549 
2550  if (!g2)
2551  {
2552  GEOSGeom_destroy(g1);
2553  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2554  }
2555 
2556  result = GEOSEquals(g1,g2);
2557 
2558  GEOSGeom_destroy(g1);
2559  GEOSGeom_destroy(g2);
2560 
2561  if (result == 2) HANDLE_GEOS_ERROR("GEOSEquals");
2562 
2563  PG_FREE_IF_COPY(geom1, 0);
2564  PG_FREE_IF_COPY(geom2, 1);
2565 
2566  PG_RETURN_BOOL(result);
2567 }
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:639
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:336
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:76
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:194
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:99
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: