PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ optimistic_overlap()

Datum optimistic_overlap ( PG_FUNCTION_ARGS  )

Definition at line 2595 of file lwgeom_functions_basic.c.

2596 {
2597  GSERIALIZED *pg_geom1 = PG_GETARG_GSERIALIZED_P(0);
2598  GSERIALIZED *pg_geom2 = PG_GETARG_GSERIALIZED_P(1);
2599  double dist = PG_GETARG_FLOAT8(2);
2600  GBOX g1_bvol;
2601  double calc_dist;
2602  LWGEOM *geom1 = lwgeom_from_gserialized(pg_geom1);
2603  LWGEOM *geom2 = lwgeom_from_gserialized(pg_geom2);
2604  gserialized_error_if_srid_mismatch(pg_geom1, pg_geom2, __func__);
2605 
2606  if (geom1->type != POLYGONTYPE)
2607  {
2608  elog(ERROR, "optimistic_overlap: first arg isn't a polygon\n");
2609  PG_RETURN_NULL();
2610  }
2611 
2612  if (geom2->type != POLYGONTYPE && geom2->type != MULTIPOLYGONTYPE)
2613  {
2614  elog(ERROR, "optimistic_overlap: 2nd arg isn't a [multi-]polygon\n");
2615  PG_RETURN_NULL();
2616  }
2617 
2618  /*bbox check */
2619  gserialized_get_gbox_p(pg_geom1, &g1_bvol);
2620 
2621  g1_bvol.xmin = g1_bvol.xmin - dist;
2622  g1_bvol.ymin = g1_bvol.ymin - dist;
2623  g1_bvol.xmax = g1_bvol.xmax + dist;
2624  g1_bvol.ymax = g1_bvol.ymax + dist;
2625 
2626  if ((g1_bvol.xmin > geom2->bbox->xmax) || (g1_bvol.xmax < geom2->bbox->xmin) ||
2627  (g1_bvol.ymin > geom2->bbox->ymax) || (g1_bvol.ymax < geom2->bbox->ymin))
2628  {
2629  PG_RETURN_BOOL(false); /*bbox not overlap */
2630  }
2631 
2632  /*
2633  * compute distances
2634  * should be a fast calc if they actually do intersect
2635  */
2636  calc_dist =
2637  DatumGetFloat8(DirectFunctionCall2(ST_Distance, PointerGetDatum(pg_geom1), PointerGetDatum(pg_geom2)));
2638 
2639  PG_RETURN_BOOL(calc_dist < dist);
2640 }
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:404
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
Definition: gserialized.c:65
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:121
#define POLYGONTYPE
Definition: liblwgeom.h:118
Datum ST_Distance(PG_FUNCTION_ARGS)
double ymax
Definition: liblwgeom.h:343
double xmax
Definition: liblwgeom.h:341
double ymin
Definition: liblwgeom.h:342
double xmin
Definition: liblwgeom.h:340
uint8_t type
Definition: liblwgeom.h:448
GBOX * bbox
Definition: liblwgeom.h:444

References LWGEOM::bbox, gserialized_error_if_srid_mismatch(), gserialized_get_gbox_p(), lwgeom_from_gserialized(), MULTIPOLYGONTYPE, POLYGONTYPE, ST_Distance(), LWGEOM::type, GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Here is the call graph for this function: