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

Definition at line 2466 of file lwgeom_functions_basic.c.

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

2467 {
2468  GSERIALIZED *pg_geom1 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2469  GSERIALIZED *pg_geom2 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2470  double dist = PG_GETARG_FLOAT8(2);
2471  GBOX g1_bvol;
2472  double calc_dist;
2473 
2474  LWGEOM *geom1 = lwgeom_from_gserialized(pg_geom1);
2475  LWGEOM *geom2 = lwgeom_from_gserialized(pg_geom2);
2476 
2477  if (geom1->srid != geom2->srid)
2478  {
2479  elog(ERROR,"optimistic_overlap:Operation on two GEOMETRIES with different SRIDs\\n");
2480  PG_RETURN_NULL();
2481  }
2482 
2483  if (geom1->type != POLYGONTYPE)
2484  {
2485  elog(ERROR,"optimistic_overlap: first arg isnt a polygon\n");
2486  PG_RETURN_NULL();
2487  }
2488 
2489  if (geom2->type != POLYGONTYPE && geom2->type != MULTIPOLYGONTYPE)
2490  {
2491  elog(ERROR,"optimistic_overlap: 2nd arg isnt a [multi-]polygon\n");
2492  PG_RETURN_NULL();
2493  }
2494 
2495  /*bbox check */
2496  gserialized_get_gbox_p(pg_geom1, &g1_bvol );
2497 
2498  g1_bvol.xmin = g1_bvol.xmin - dist;
2499  g1_bvol.ymin = g1_bvol.ymin - dist;
2500  g1_bvol.xmax = g1_bvol.xmax + dist;
2501  g1_bvol.ymax = g1_bvol.ymax + dist;
2502 
2503  if ( (g1_bvol.xmin > geom2->bbox->xmax) ||
2504  (g1_bvol.xmax < geom2->bbox->xmin) ||
2505  (g1_bvol.ymin > geom2->bbox->ymax) ||
2506  (g1_bvol.ymax < geom2->bbox->ymin) )
2507  {
2508  PG_RETURN_BOOL(FALSE); /*bbox not overlap */
2509  }
2510 
2511  /*
2512  * compute distances
2513  * should be a fast calc if they actually do intersect
2514  */
2515  calc_dist = DatumGetFloat8 ( DirectFunctionCall2(LWGEOM_mindistance2d, PointerGetDatum( pg_geom1 ), PointerGetDatum( pg_geom2 )));
2516 
2517  PG_RETURN_BOOL(calc_dist < dist);
2518 }
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:373
GBOX * bbox
Definition: liblwgeom.h:354
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define POLYGONTYPE
Definition: liblwgeom.h:62
double xmax
Definition: liblwgeom.h:249
int32_t srid
Definition: liblwgeom.h:355
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
double ymax
Definition: liblwgeom.h:251
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
#define FALSE
Definition: dbfopen.c:169
Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS)
uint8_t type
Definition: liblwgeom.h:352

Here is the call graph for this function: