PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ optimistic_overlap()

Datum optimistic_overlap ( PG_FUNCTION_ARGS  )

Definition at line 2576 of file lwgeom_functions_basic.c.

2577 {
2578  GSERIALIZED *pg_geom1 = PG_GETARG_GSERIALIZED_P(0);
2579  GSERIALIZED *pg_geom2 = PG_GETARG_GSERIALIZED_P(1);
2580  double dist = PG_GETARG_FLOAT8(2);
2581  GBOX g1_bvol;
2582  double calc_dist;
2583 
2584  LWGEOM *geom1 = lwgeom_from_gserialized(pg_geom1);
2585  LWGEOM *geom2 = lwgeom_from_gserialized(pg_geom2);
2586 
2587  error_if_srid_mismatch(geom1->srid, geom2->srid);
2588 
2589  if (geom1->type != POLYGONTYPE)
2590  {
2591  elog(ERROR,"optimistic_overlap: first arg isn't a polygon\n");
2592  PG_RETURN_NULL();
2593  }
2594 
2595  if (geom2->type != POLYGONTYPE && geom2->type != MULTIPOLYGONTYPE)
2596  {
2597  elog(ERROR,"optimistic_overlap: 2nd arg isn't a [multi-]polygon\n");
2598  PG_RETURN_NULL();
2599  }
2600 
2601  /*bbox check */
2602  gserialized_get_gbox_p(pg_geom1, &g1_bvol );
2603 
2604  g1_bvol.xmin = g1_bvol.xmin - dist;
2605  g1_bvol.ymin = g1_bvol.ymin - dist;
2606  g1_bvol.xmax = g1_bvol.xmax + dist;
2607  g1_bvol.ymax = g1_bvol.ymax + dist;
2608 
2609  if ( (g1_bvol.xmin > geom2->bbox->xmax) ||
2610  (g1_bvol.xmax < geom2->bbox->xmin) ||
2611  (g1_bvol.ymin > geom2->bbox->ymax) ||
2612  (g1_bvol.ymax < geom2->bbox->ymin) )
2613  {
2614  PG_RETURN_BOOL(false); /*bbox not overlap */
2615  }
2616 
2617  /*
2618  * compute distances
2619  * should be a fast calc if they actually do intersect
2620  */
2621  calc_dist = DatumGetFloat8 ( DirectFunctionCall2(LWGEOM_mindistance2d, PointerGetDatum( pg_geom1 ), PointerGetDatum( pg_geom2 )));
2622 
2623  PG_RETURN_BOOL(calc_dist < dist);
2624 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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:640
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POLYGONTYPE
Definition: liblwgeom.h:87
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS)
double ymax
Definition: liblwgeom.h:298
double xmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
uint8_t type
Definition: liblwgeom.h:399
GBOX * bbox
Definition: liblwgeom.h:401
int32_t srid
Definition: liblwgeom.h:402

References LWGEOM::bbox, error_if_srid_mismatch(), gserialized_get_gbox_p(), lwgeom_from_gserialized(), LWGEOM_mindistance2d(), MULTIPOLYGONTYPE, POLYGONTYPE, LWGEOM::srid, LWGEOM::type, GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Here is the call graph for this function: