PostGIS  2.3.7dev-r@@SVN_REVISION@@
static CIRC_NODE* circ_node_leaf_new ( const POINTARRAY pa,
int  i 
)
static

Create a new leaf node, storing pointers back to the end points for later.

Definition at line 67 of file lwgeodetic_tree.c.

References cart2geog(), circ_node::center, circ_node::edge_num, FP_EQUALS, geog2cart(), geographic_point_init(), circ_node::geom_type, getPoint_internal(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, lwalloc(), LWDEBUGF, circ_node::nodes, normalize(), circ_node::num_nodes, circ_node::p1, circ_node::p2, circ_node::pt_outside, circ_node::radius, sphere_distance(), vector_sum(), POINT2D::x, and POINT2D::y.

Referenced by circ_tree_new().

68 {
69  POINT2D *p1, *p2;
70  POINT3D q1, q2, c;
71  GEOGRAPHIC_POINT g1, g2, gc;
72  CIRC_NODE *node;
73  double diameter;
74 
75  p1 = (POINT2D*)getPoint_internal(pa, i);
76  p2 = (POINT2D*)getPoint_internal(pa, i+1);
77  geographic_point_init(p1->x, p1->y, &g1);
78  geographic_point_init(p2->x, p2->y, &g2);
79 
80  LWDEBUGF(3,"edge #%d (%g %g, %g %g)", i, p1->x, p1->y, p2->x, p2->y);
81 
82  diameter = sphere_distance(&g1, &g2);
83 
84  /* Zero length edge, doesn't get a node */
85  if ( FP_EQUALS(diameter, 0.0) )
86  return NULL;
87 
88  /* Allocate */
89  node = lwalloc(sizeof(CIRC_NODE));
90  node->p1 = p1;
91  node->p2 = p2;
92 
93  /* Convert ends to X/Y/Z, sum, and normalize to get mid-point */
94  geog2cart(&g1, &q1);
95  geog2cart(&g2, &q2);
96  vector_sum(&q1, &q2, &c);
97  normalize(&c);
98  cart2geog(&c, &gc);
99  node->center = gc;
100  node->radius = diameter / 2.0;
101 
102  LWDEBUGF(3,"edge #%d CENTER(%g %g) RADIUS=%g", i, gc.lon, gc.lat, node->radius);
103 
104  /* Leaf has no children */
105  node->num_nodes = 0;
106  node->nodes = NULL;
107  node->edge_num = i;
108 
109  /* Zero out metadata */
110  node->pt_outside.x = 0.0;
111  node->pt_outside.y = 0.0;
112  node->geom_type = 0;
113 
114  return node;
115 }
double sphere_distance(const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
Given two points on a unit sphere, calculate their distance apart in radians.
Definition: lwgeodetic.c:913
Note that p1 and p2 are pointers into an independent POINTARRAY, do not free them.
GEOGRAPHIC_POINT center
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:580
POINT2D * p2
POINT2D * p1
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:379
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
double x
Definition: liblwgeom.h:327
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1706
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
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:430
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:171
POINT2D pt_outside
#define FP_EQUALS(A, B)
double radius
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
struct circ_node ** nodes

Here is the call graph for this function:

Here is the caller graph for this function: