56 if ( circ_cache->
index )
59 circ_cache->
index = 0;
64 circ_cache->
index = tree;
72 if ( circ_cache->
index )
75 circ_cache->
index = 0;
86 return (GeomCache*)cache;
111 POSTGIS_DEBUGF(3,
"tree1_type=%d", tree1_type);
116 POSTGIS_DEBUG(3,
"tree is a polygon, using tree PiP");
121 POSTGIS_DEBUG(3,
"unable to read gbox from gserialized, calculating from scratch");
133 POSTGIS_DEBUG(3,
"in_point3d is not inside the tree gbox, CircTreePIP returning FALSE");
141 pt2d_inside.
x = in_point->
x;
142 pt2d_inside.
y = in_point->
y;
146 lwpgerror(
"%s: Unable to generate outside point!", __func__);
148 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);
150 POSTGIS_DEBUG(3,
"calling circ_tree_contains_point for PiP test");
156 POSTGIS_DEBUG(3,
"tree1 not polygonal, so CircTreePIP returning FALSE");
185 if ( tree_cache && tree_cache->
argnum && tree_cache->
index )
197 if ( tree_cache->
argnum == 1 )
201 geomtype_cached = type1;
204 else if ( tree_cache->
argnum == 2 )
208 geomtype_cached = type2;
213 lwpgerror(
"geography_distance_cache this cannot happen!");
221 if (
CircTreePIP(circtree_cached, g_cached, &p4d) )
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.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
static int CircTreeFreer(GeomCache *cache)
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
static int geography_distance_cache_tolerance(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, double *distance)
int geography_distance_cache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double *distance)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int circ_tree_get_point(const CIRC_NODE *node, POINT2D *pt)
Returns a POINT2D that is a vertex of the input shape.
int lwgeom_startpoint(const LWGEOM *lwgeom, POINT4D *pt)
void lwgeom_free(LWGEOM *geom)
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
static int CircTreeBuilder(const LWGEOM *lwgeom, GeomCache *cache)
Builder, freeer and public accessor for cached CIRC_NODE trees.
static GeomCache * CircTreeAllocator(void)
double circ_tree_distance_tree(const CIRC_NODE *n1, const CIRC_NODE *n2, const SPHEROID *spheroid, double threshold)
int geography_tree_distance(const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, double *distance)
Point in spherical coordinates on the world.
CIRC_NODE * lwgeom_calculate_circ_tree(const LWGEOM *lwgeom)
int circ_tree_contains_point(const CIRC_NODE *node, const POINT2D *pt, const POINT2D *pt_outside, int level, int *on_boundary)
Walk the tree and count intersections between the stab line and the edges.
static int CircTreePIP(const CIRC_NODE *tree1, const GSERIALIZED *g1, const POINT4D *in_point)
static CircTreeGeomCache * GetCircTreeGeomCache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2)
#define LW_TRUE
Return types for functions with status returns.
int circ_tree_get_point_outside(const CIRC_NODE *node, POINT2D *pt)
#define FP_TOLERANCE
Floating point comparators.
Datum distance(PG_FUNCTION_ARGS)
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
void circ_tree_free(CIRC_NODE *node)
Recurse from top of node tree and free all children.
int geography_dwithin_cache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2, const SPHEROID *s, double tolerance, int *dwithin)
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
int gbox_pt_outside(const GBOX *gbox, POINT2D *pt_outside)
Calculate a spherical point that falls outside the geocentric gbox.
static GeomCacheMethods CircTreeCacheMethods