PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ optimistic_overlap()

Datum optimistic_overlap ( PG_FUNCTION_ARGS  )

Definition at line 2429 of file lwgeom_functions_basic.c.

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

Referenced by LWGEOM_azimuth().

2430 {
2431  GSERIALIZED *pg_geom1 = PG_GETARG_GSERIALIZED_P(0);
2432  GSERIALIZED *pg_geom2 = PG_GETARG_GSERIALIZED_P(1);
2433  double dist = PG_GETARG_FLOAT8(2);
2434  GBOX g1_bvol;
2435  double calc_dist;
2436 
2437  LWGEOM *geom1 = lwgeom_from_gserialized(pg_geom1);
2438  LWGEOM *geom2 = lwgeom_from_gserialized(pg_geom2);
2439 
2440  error_if_srid_mismatch(geom1->srid, geom2->srid);
2441 
2442  if (geom1->type != POLYGONTYPE)
2443  {
2444  elog(ERROR,"optimistic_overlap: first arg isn't a polygon\n");
2445  PG_RETURN_NULL();
2446  }
2447 
2448  if (geom2->type != POLYGONTYPE && geom2->type != MULTIPOLYGONTYPE)
2449  {
2450  elog(ERROR,"optimistic_overlap: 2nd arg isn't a [multi-]polygon\n");
2451  PG_RETURN_NULL();
2452  }
2453 
2454  /*bbox check */
2455  gserialized_get_gbox_p(pg_geom1, &g1_bvol );
2456 
2457  g1_bvol.xmin = g1_bvol.xmin - dist;
2458  g1_bvol.ymin = g1_bvol.ymin - dist;
2459  g1_bvol.xmax = g1_bvol.xmax + dist;
2460  g1_bvol.ymax = g1_bvol.ymax + dist;
2461 
2462  if ( (g1_bvol.xmin > geom2->bbox->xmax) ||
2463  (g1_bvol.xmax < geom2->bbox->xmin) ||
2464  (g1_bvol.ymin > geom2->bbox->ymax) ||
2465  (g1_bvol.ymax < geom2->bbox->ymin) )
2466  {
2467  PG_RETURN_BOOL(FALSE); /*bbox not overlap */
2468  }
2469 
2470  /*
2471  * compute distances
2472  * should be a fast calc if they actually do intersect
2473  */
2474  calc_dist = DatumGetFloat8 ( DirectFunctionCall2(LWGEOM_mindistance2d, PointerGetDatum( pg_geom1 ), PointerGetDatum( pg_geom2 )));
2475 
2476  PG_RETURN_BOOL(calc_dist < dist);
2477 }
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:642
GBOX * bbox
Definition: liblwgeom.h:398
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define POLYGONTYPE
Definition: liblwgeom.h:87
double xmax
Definition: liblwgeom.h:293
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:371
int32_t srid
Definition: liblwgeom.h:399
double ymin
Definition: liblwgeom.h:294
double xmin
Definition: liblwgeom.h:292
double ymax
Definition: liblwgeom.h:295
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define FALSE
Definition: dbfopen.c:168
Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS)
uint8_t type
Definition: liblwgeom.h:396
Here is the call graph for this function:
Here is the caller graph for this function: