PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ circ_node_leaf_new()

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 42 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().

43 {
44  POINT2D *p1, *p2;
45  POINT3D q1, q2, c;
46  GEOGRAPHIC_POINT g1, g2, gc;
47  CIRC_NODE *node;
48  double diameter;
49 
50  p1 = (POINT2D*)getPoint_internal(pa, i);
51  p2 = (POINT2D*)getPoint_internal(pa, i+1);
52  geographic_point_init(p1->x, p1->y, &g1);
53  geographic_point_init(p2->x, p2->y, &g2);
54 
55  LWDEBUGF(3,"edge #%d (%g %g, %g %g)", i, p1->x, p1->y, p2->x, p2->y);
56 
57  diameter = sphere_distance(&g1, &g2);
58 
59  /* Zero length edge, doesn't get a node */
60  if ( FP_EQUALS(diameter, 0.0) )
61  return NULL;
62 
63  /* Allocate */
64  node = lwalloc(sizeof(CIRC_NODE));
65  node->p1 = p1;
66  node->p2 = p2;
67 
68  /* Convert ends to X/Y/Z, sum, and normalize to get mid-point */
69  geog2cart(&g1, &q1);
70  geog2cart(&g2, &q2);
71  vector_sum(&q1, &q2, &c);
72  normalize(&c);
73  cart2geog(&c, &gc);
74  node->center = gc;
75  node->radius = diameter / 2.0;
76 
77  LWDEBUGF(3,"edge #%d CENTER(%g %g) RADIUS=%g", i, gc.lon, gc.lat, node->radius);
78 
79  /* Leaf has no children */
80  node->num_nodes = 0;
81  node->nodes = NULL;
82  node->edge_num = i;
83 
84  /* Zero out metadata */
85  node->pt_outside.x = 0.0;
86  node->pt_outside.y = 0.0;
87  node->geom_type = 0;
88 
89  return node;
90 }
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:898
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:565
POINT2D * p2
POINT2D * p1
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:364
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:32
double x
Definition: liblwgeom.h:312
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1706
double y
Definition: liblwgeom.h:312
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:354
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:415
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:156
POINT2D pt_outside
#define FP_EQUALS(A, B)
double radius
void * lwalloc(size_t size)
Definition: lwutil.c:199
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
struct circ_node ** nodes
Here is the call graph for this function:
Here is the caller graph for this function: