PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum optimistic_overlap ( PG_FUNCTION_ARGS  )

Definition at line 2562 of file lwgeom_functions_basic.c.

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.

2563 {
2564  GSERIALIZED *pg_geom1 = PG_GETARG_GSERIALIZED_P(0);
2565  GSERIALIZED *pg_geom2 = PG_GETARG_GSERIALIZED_P(1);
2566  double dist = PG_GETARG_FLOAT8(2);
2567  GBOX g1_bvol;
2568  double calc_dist;
2569 
2570  LWGEOM *geom1 = lwgeom_from_gserialized(pg_geom1);
2571  LWGEOM *geom2 = lwgeom_from_gserialized(pg_geom2);
2572 
2573  error_if_srid_mismatch(geom1->srid, geom2->srid);
2574 
2575  if (geom1->type != POLYGONTYPE)
2576  {
2577  elog(ERROR,"optimistic_overlap: first arg isn't a polygon\n");
2578  PG_RETURN_NULL();
2579  }
2580 
2581  if (geom2->type != POLYGONTYPE && geom2->type != MULTIPOLYGONTYPE)
2582  {
2583  elog(ERROR,"optimistic_overlap: 2nd arg isn't a [multi-]polygon\n");
2584  PG_RETURN_NULL();
2585  }
2586 
2587  /*bbox check */
2588  gserialized_get_gbox_p(pg_geom1, &g1_bvol );
2589 
2590  g1_bvol.xmin = g1_bvol.xmin - dist;
2591  g1_bvol.ymin = g1_bvol.ymin - dist;
2592  g1_bvol.xmax = g1_bvol.xmax + dist;
2593  g1_bvol.ymax = g1_bvol.ymax + dist;
2594 
2595  if ( (g1_bvol.xmin > geom2->bbox->xmax) ||
2596  (g1_bvol.xmax < geom2->bbox->xmin) ||
2597  (g1_bvol.ymin > geom2->bbox->ymax) ||
2598  (g1_bvol.ymax < geom2->bbox->ymin) )
2599  {
2600  PG_RETURN_BOOL(false); /*bbox not overlap */
2601  }
2602 
2603  /*
2604  * compute distances
2605  * should be a fast calc if they actually do intersect
2606  */
2607  calc_dist = DatumGetFloat8 ( DirectFunctionCall2(LWGEOM_mindistance2d, PointerGetDatum( pg_geom1 ), PointerGetDatum( pg_geom2 )));
2608 
2609  PG_RETURN_BOOL(calc_dist < dist);
2610 }
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
GBOX * bbox
Definition: liblwgeom.h:397
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define POLYGONTYPE
Definition: liblwgeom.h:86
double xmax
Definition: liblwgeom.h:292
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
int32_t srid
Definition: liblwgeom.h:398
double ymin
Definition: liblwgeom.h:293
double xmin
Definition: liblwgeom.h:291
double ymax
Definition: liblwgeom.h:294
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS)
uint8_t type
Definition: liblwgeom.h:395

Here is the call graph for this function: