PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ CircTreePIP()

static int CircTreePIP ( const CIRC_NODE tree1,
const GSERIALIZED g1,
const POINT4D in_point 
)
static

Definition at line 100 of file geography_measurement_trees.c.

References circ_tree_contains_point(), gbox_contains_point3d(), gbox_pt_outside(), geog2cart(), geographic_point_init(), gserialized_get_gbox_p(), gserialized_get_type(), LW_FAILURE, LW_FALSE, lwgeom_calculate_gbox_geodetic(), lwgeom_free(), lwgeom_from_gserialized(), MULTIPOLYGONTYPE, POLYGONTYPE, POINT2D::x, POINT4D::x, POINT2D::y, and POINT4D::y.

Referenced by geography_distance_cache_tolerance(), and geography_tree_distance().

101 {
102  int tree1_type = gserialized_get_type(g1);
103  GBOX gbox1;
104  GEOGRAPHIC_POINT in_gpoint;
105  POINT3D in_point3d;
106 
107  POSTGIS_DEBUGF(3, "tree1_type=%d", tree1_type);
108 
109  /* If the tree'ed argument is a polygon, do the P-i-P using the tree-based P-i-P */
110  if ( tree1_type == POLYGONTYPE || tree1_type == MULTIPOLYGONTYPE )
111  {
112  POSTGIS_DEBUG(3, "tree is a polygon, using tree PiP");
113  /* Need a gbox to calculate an outside point */
114  if ( LW_FAILURE == gserialized_get_gbox_p(g1, &gbox1) )
115  {
116  LWGEOM* lwgeom1 = lwgeom_from_gserialized(g1);
117  POSTGIS_DEBUG(3, "unable to read gbox from gserialized, calculating from scratch");
118  lwgeom_calculate_gbox_geodetic(lwgeom1, &gbox1);
119  lwgeom_free(lwgeom1);
120  }
121 
122  /* Flip the candidate point into geographics */
123  geographic_point_init(in_point->x, in_point->y, &in_gpoint);
124  geog2cart(&in_gpoint, &in_point3d);
125 
126  /* If the candidate isn't in the tree box, it's not in the tree area */
127  if ( ! gbox_contains_point3d(&gbox1, &in_point3d) )
128  {
129  POSTGIS_DEBUG(3, "in_point3d is not inside the tree gbox, CircTreePIP returning FALSE");
130  return LW_FALSE;
131  }
132  /* The candidate point is in the box, so it *might* be inside the tree */
133  else
134  {
135  POINT2D pt2d_outside; /* latlon */
136  POINT2D pt2d_inside;
137  pt2d_inside.x = in_point->x;
138  pt2d_inside.y = in_point->y;
139  /* Calculate a definitive outside point */
140  gbox_pt_outside(&gbox1, &pt2d_outside);
141  POSTGIS_DEBUGF(3, "p2d_inside=POINT(%g %g) p2d_outside=POINT(%g %g)", pt2d_inside.x, pt2d_inside.y, pt2d_outside.x, pt2d_outside.y);
142  /* Test the candidate point for strict containment */
143  POSTGIS_DEBUG(3, "calling circ_tree_contains_point for PiP test");
144  return circ_tree_contains_point(tree1, &pt2d_inside, &pt2d_outside, NULL);
145  }
146  }
147  else
148  {
149  POSTGIS_DEBUG(3, "tree1 not polygonal, so CircTreePIP returning FALSE");
150  return LW_FALSE;
151  }
152 }
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
double x
Definition: liblwgeom.h:354
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2940
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define POLYGONTYPE
Definition: liblwgeom.h:86
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:254
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
#define LW_FAILURE
Definition: liblwgeom.h:78
double x
Definition: liblwgeom.h:330
#define LW_FALSE
Definition: liblwgeom.h:76
int circ_tree_contains_point(const CIRC_NODE *node, const POINT2D *pt, const POINT2D *pt_outside, int *on_boundary)
Walk the tree and count intersections between the stab line and the edges.
double y
Definition: liblwgeom.h:330
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesian coordinates on unit sphere.
Definition: lwgeodetic.c:373
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
void gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
Definition: lwgeodetic.c:1465
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:171
double y
Definition: liblwgeom.h:354
Here is the call graph for this function:
Here is the caller graph for this function: