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

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

82 {
83  int tree1_type = gserialized_get_type(g1);
84  GBOX gbox1;
85  GEOGRAPHIC_POINT in_gpoint;
86  POINT3D in_point3d;
88  POSTGIS_DEBUGF(3, "tree1_type=%d", tree1_type);
90  /* If the tree'ed argument is a polygon, do the P-i-P using the tree-based P-i-P */
91  if ( tree1_type == POLYGONTYPE || tree1_type == MULTIPOLYGONTYPE )
92  {
93  POSTGIS_DEBUG(3, "tree is a polygon, using tree PiP");
94  /* Need a gbox to calculate an outside point */
95  if ( LW_FAILURE == gserialized_get_gbox_p(g1, &gbox1) )
96  {
97  LWGEOM* lwgeom1 = lwgeom_from_gserialized(g1);
98  POSTGIS_DEBUG(3, "unable to read gbox from gserialized, calculating from scratch");
99  lwgeom_calculate_gbox_geodetic(lwgeom1, &gbox1);
100  lwgeom_free(lwgeom1);
101  }
103  /* Flip the candidate point into geographics */
104  geographic_point_init(in_point->x, in_point->y, &in_gpoint);
105  geog2cart(&in_gpoint, &in_point3d);
107  /* If the candidate isn't in the tree box, it's not in the tree area */
108  if ( ! gbox_contains_point3d(&gbox1, &in_point3d) )
109  {
110  POSTGIS_DEBUG(3, "in_point3d is not inside the tree gbox, CircTreePIP returning FALSE");
111  return LW_FALSE;
112  }
113  /* The candidate point is in the box, so it *might* be inside the tree */
114  else
115  {
116  POINT2D pt2d_outside; /* latlon */
117  POINT2D pt2d_inside;
118  pt2d_inside.x = in_point->x;
119  pt2d_inside.y = in_point->y;
120  /* Calculate a definitive outside point */
121  gbox_pt_outside(&gbox1, &pt2d_outside);
122  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);
123  /* Test the candidate point for strict containment */
124  POSTGIS_DEBUG(3, "calling circ_tree_contains_point for PiP test");
125  return circ_tree_contains_point(tree1, &pt2d_inside, &pt2d_outside, NULL);
126  }
127  }
128  else
129  {
130  POSTGIS_DEBUG(3, "tree1 not polygonal, so CircTreePIP returning FALSE");
131  return LW_FALSE;
132  }
133 }
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
double x
Definition: liblwgeom.h:308
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:56
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2612
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: liblwgeom.h:62
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:205
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:33
#define LW_FAILURE
Definition: liblwgeom.h:54
double x
Definition: liblwgeom.h:284
#define LW_FALSE
Definition: liblwgeom.h:52
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:284
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:355
Definition: liblwgeom.h:65
void gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
Definition: lwgeodetic.c:1443
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:157
double y
Definition: liblwgeom.h:308

Here is the call graph for this function:

Here is the caller graph for this function: