PostGIS  2.3.7dev-r@@SVN_REVISION@@
static int CircTreePIP ( const CIRC_NODE tree1,
const POINT4D in_point 

Definition at line 105 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().

106 {
107  int tree1_type = gserialized_get_type(g1);
108  GBOX gbox1;
109  GEOGRAPHIC_POINT in_gpoint;
110  POINT3D in_point3d;
112  POSTGIS_DEBUGF(3, "tree1_type=%d", tree1_type);
114  /* If the tree'ed argument is a polygon, do the P-i-P using the tree-based P-i-P */
115  if ( tree1_type == POLYGONTYPE || tree1_type == MULTIPOLYGONTYPE )
116  {
117  POSTGIS_DEBUG(3, "tree is a polygon, using tree PiP");
118  /* Need a gbox to calculate an outside point */
119  if ( LW_FAILURE == gserialized_get_gbox_p(g1, &gbox1) )
120  {
121  LWGEOM* lwgeom1 = lwgeom_from_gserialized(g1);
122  POSTGIS_DEBUG(3, "unable to read gbox from gserialized, calculating from scratch");
123  lwgeom_calculate_gbox_geodetic(lwgeom1, &gbox1);
124  lwgeom_free(lwgeom1);
125  }
127  /* Flip the candidate point into geographics */
128  geographic_point_init(in_point->x, in_point->y, &in_gpoint);
129  geog2cart(&in_gpoint, &in_point3d);
131  /* If the candidate isn't in the tree box, it's not in the tree area */
132  if ( ! gbox_contains_point3d(&gbox1, &in_point3d) )
133  {
134  POSTGIS_DEBUG(3, "in_point3d is not inside the tree gbox, CircTreePIP returning FALSE");
135  return LW_FALSE;
136  }
137  /* The candidate point is in the box, so it *might* be inside the tree */
138  else
139  {
140  POINT2D pt2d_outside; /* latlon */
141  POINT2D pt2d_inside;
142  pt2d_inside.x = in_point->x;
143  pt2d_inside.y = in_point->y;
144  /* Calculate a definitive outside point */
145  gbox_pt_outside(&gbox1, &pt2d_outside);
146  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);
147  /* Test the candidate point for strict containment */
148  POSTGIS_DEBUG(3, "calling circ_tree_contains_point for PiP test");
149  return circ_tree_contains_point(tree1, &pt2d_inside, &pt2d_outside, NULL);
150  }
151  }
152  else
153  {
154  POSTGIS_DEBUG(3, "tree1 not polygonal, so CircTreePIP returning FALSE");
155  return LW_FALSE;
156  }
157 }
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:398
double x
Definition: liblwgeom.h:351
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:69
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2626
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: liblwgeom.h:86
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:259
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
#define LW_FAILURE
Definition: liblwgeom.h:78
double x
Definition: liblwgeom.h:327
#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:327
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:369
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:1461
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:171
double y
Definition: liblwgeom.h:351

Here is the call graph for this function:

Here is the caller graph for this function: