PostGIS  2.3.7dev-r@@SVN_REVISION@@
lwgeodetic.c File Reference
#include "liblwgeom_internal.h"
#include "lwgeodetic.h"
#include "lwgeom_log.h"
Include dependency graph for lwgeodetic.c:

Go to the source code of this file.

Functions

double longitude_radians_normalize (double lon)
 Convert a longitude to the range of -PI,PI. More...
 
double latitude_radians_normalize (double lat)
 Convert a latitude to the range of -PI/2,PI/2. More...
 
double longitude_degrees_normalize (double lon)
 Convert a longitude to the range of -180,180. More...
 
double latitude_degrees_normalize (double lat)
 Convert a latitude to the range of -90,90. More...
 
void point_shift (GEOGRAPHIC_POINT *p, double shift)
 Shift a point around by a number of radians. More...
 
int geographic_point_equals (const GEOGRAPHIC_POINT *g1, const GEOGRAPHIC_POINT *g2)
 
void geographic_point_init (double lon, double lat, GEOGRAPHIC_POINT *g)
 Initialize a geographic point. More...
 
double gbox_angular_height (const GBOX *gbox)
 Returns the angular height (latitudinal span) of the box in radians. More...
 
double gbox_angular_width (const GBOX *gbox)
 Returns the angular width (longitudinal span) of the box in radians. More...
 
int gbox_centroid (const GBOX *gbox, POINT2D *out)
 Computes the average(ish) center of the box and returns success. More...
 
static int gbox_check_poles (GBOX *gbox)
 Check to see if this geocentric gbox is wrapped around a pole. More...
 
void geog2cart (const GEOGRAPHIC_POINT *g, POINT3D *p)
 Convert spherical coordinates to cartesion coordinates on unit sphere. More...
 
void cart2geog (const POINT3D *p, GEOGRAPHIC_POINT *g)
 Convert cartesion coordinates on unit sphere to spherical coordinates. More...
 
void ll2cart (const POINT2D *g, POINT3D *p)
 Convert lon/lat coordinates to cartesion coordinates on unit sphere. More...
 
static double dot_product (const POINT3D *p1, const POINT3D *p2)
 Convert cartesion coordinates on unit sphere to lon/lat coordinates static void cart2ll(const POINT3D *p, POINT2D *g) { g->x = longitude_degrees_normalize(180.0 * atan2(p->y, p->x) / M_PI); g->y = latitude_degrees_normalize(180.0 * asin(p->z) / M_PI); }. More...
 
static void cross_product (const POINT3D *a, const POINT3D *b, POINT3D *n)
 Calculate the cross product of two vectors. More...
 
void vector_sum (const POINT3D *a, const POINT3D *b, POINT3D *n)
 Calculate the sum of two vectors. More...
 
static void vector_difference (const POINT3D *a, const POINT3D *b, POINT3D *n)
 Calculate the difference of two vectors. More...
 
static void vector_scale (POINT3D *n, double scale)
 Scale a vector out by a factor. More...
 
double vector_angle (const POINT3D *v1, const POINT3D *v2)
 Angle between two unit vectors. More...
 
static void normalize2d (POINT2D *p)
 Normalize to a unit vector. More...
 
void unit_normal (const POINT3D *P1, const POINT3D *P2, POINT3D *normal)
 Calculates the unit normal to two vectors, trying to avoid problems with over-narrow or over-wide cases. More...
 
void vector_rotate (const POINT3D *v1, const POINT3D *v2, double angle, POINT3D *n)
 Rotates v1 through an angle (in radians) within the plane defined by v1/v2, returns the rotated vector in n. More...
 
void normalize (POINT3D *p)
 Normalize to a unit vector. More...
 
void robust_cross_product (const GEOGRAPHIC_POINT *p, const GEOGRAPHIC_POINT *q, POINT3D *a)
 Computes the cross product of two vectors using their lat, lng representations. More...
 
void x_to_z (POINT3D *p)
 
void y_to_z (POINT3D *p)
 
int crosses_dateline (const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
 
static int edge_point_side (const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *p)
 Returns -1 if the point is to the left of the plane formed by the edge, 1 if the point is to the right, and 0 if the point is on the plane. More...
 
static double sphere_angle (const GEOGRAPHIC_POINT *a, const GEOGRAPHIC_POINT *b, const GEOGRAPHIC_POINT *c)
 Returns the angle in radians at point B of the triangle formed by A-B-C. More...
 
static double sphere_signed_area (const GEOGRAPHIC_POINT *a, const GEOGRAPHIC_POINT *b, const GEOGRAPHIC_POINT *c)
 Computes the spherical area of a triangle. More...
 
int edge_point_on_plane (const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *p)
 Returns true if the point p is on the great circle plane. More...
 
int edge_point_in_cone (const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *p)
 Returns true if the point p is inside the cone defined by the two ends of the edge e. More...
 
int edge_contains_coplanar_point (const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *p)
 True if the longitude of p is within the range of the longitude of the ends of e. More...
 
double sphere_distance (const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
 Given two points on a unit sphere, calculate their distance apart in radians. More...
 
double sphere_distance_cartesian (const POINT3D *s, const POINT3D *e)
 Given two unit vectors, calculate their distance apart in radians. More...
 
double sphere_direction (const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e, double d)
 Given two points on a unit sphere, calculate the direction from s to e. More...
 
int edge_contains_point (const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *p)
 Returns true if the point p is on the minor edge defined by the end points of e. More...
 
double z_to_latitude (double z, int top)
 Used in great circle to compute the pole of the great circle. More...
 
int clairaut_cartesian (const POINT3D *start, const POINT3D *end, GEOGRAPHIC_POINT *g_top, GEOGRAPHIC_POINT *g_bottom)
 Computes the pole of the great circle disk which is the intersection of the great circle with the line of maximum/minimum gradiant that lies on the great circle plane. More...
 
int clairaut_geographic (const GEOGRAPHIC_POINT *start, const GEOGRAPHIC_POINT *end, GEOGRAPHIC_POINT *g_top, GEOGRAPHIC_POINT *g_bottom)
 Computes the pole of the great circle disk which is the intersection of the great circle with the line of maximum/minimum gradiant that lies on the great circle plane. More...
 
int edge_intersection (const GEOGRAPHIC_EDGE *e1, const GEOGRAPHIC_EDGE *e2, GEOGRAPHIC_POINT *g)
 Returns true if an intersection can be calculated, and places it in *g. More...
 
double edge_distance_to_point (const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *gp, GEOGRAPHIC_POINT *closest)
 
double edge_distance_to_edge (const GEOGRAPHIC_EDGE *e1, const GEOGRAPHIC_EDGE *e2, GEOGRAPHIC_POINT *closest1, GEOGRAPHIC_POINT *closest2)
 Calculate the distance between two edges. More...
 
int sphere_project (const GEOGRAPHIC_POINT *r, double distance, double azimuth, GEOGRAPHIC_POINT *n)
 Given a starting location r, a distance and an azimuth to the new point, compute the location of the projected point on the unit sphere. More...
 
int edge_calculate_gbox_slow (const GEOGRAPHIC_EDGE *e, GBOX *gbox)
 
int edge_calculate_gbox (const POINT3D *A1, const POINT3D *A2, GBOX *gbox)
 The magic function, given an edge in spherical coordinates, calculate a 3D bounding box that fully contains it, taking into account the curvature of the sphere on which it is inscribed. More...
 
void lwpoly_pt_outside (const LWPOLY *poly, POINT2D *pt_outside)
 
void gbox_pt_outside (const GBOX *gbox, POINT2D *pt_outside)
 Given a unit geocentric gbox, return a lon/lat (degrees) coordinate point point that is guaranteed to be outside the box (and therefore anything it contains). More...
 
static int ptarray_segmentize_sphere_edge_recursive (const POINT3D *p1, const POINT3D *p2, const POINT4D *v1, const POINT4D *v2, double d, double max_seg_length, POINTARRAY *pa)
 
static POINTARRAYptarray_segmentize_sphere (const POINTARRAY *pa_in, double max_seg_length)
 Create a new point array with no segment longer than the input segment length (expressed in radians!) More...
 
LWGEOMlwgeom_segmentize_sphere (const LWGEOM *lwg_in, double max_seg_length)
 Create a new, densified geometry where no segment is longer than max_seg_length. More...
 
double ptarray_area_sphere (const POINTARRAY *pa)
 Returns the area of the ring (ring must be closed) in square radians (surface of the sphere is 4*PI). More...
 
static double ptarray_distance_spheroid (const POINTARRAY *pa1, const POINTARRAY *pa2, const SPHEROID *s, double tolerance, int check_intersection)
 
double lwgeom_area_sphere (const LWGEOM *lwgeom, const SPHEROID *spheroid)
 Calculate the area of an LWGEOM. More...
 
LWPOINTlwgeom_project_spheroid (const LWPOINT *r, const SPHEROID *spheroid, double distance, double azimuth)
 Calculate a projected point given a source point, a distance and a bearing. More...
 
double lwgeom_azumith_spheroid (const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid)
 Calculate a bearing (azimuth) given a source and destination point. More...
 
double lwgeom_distance_spheroid (const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
 Calculate the distance between two LWGEOMs, using the coordinates are longitude and latitude. More...
 
int lwgeom_covers_lwgeom_sphere (const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
 Calculate covers predicate for two lwgeoms on the sphere. More...
 
int lwpoly_covers_point2d (const LWPOLY *poly, const POINT2D *pt_to_test)
 Given a polygon (lon/lat decimal degrees) and point (lon/lat decimal degrees) and a guaranteed outside point (lon/lat decimal degrees) (calculate with gbox_pt_outside()) return LW_TRUE if point is inside or on edge of polygon. More...
 
int getPoint2d_p_ro (const POINTARRAY *pa, int n, POINT2D **point)
 This function can only be used on LWGEOM that is built on top of GSERIALIZED, otherwise alignment errors will ensue. More...
 
int ptarray_calculate_gbox_geodetic (const POINTARRAY *pa, GBOX *gbox)
 Calculate geodetic (x/y/z) box and add values to gbox. More...
 
static int lwpoint_calculate_gbox_geodetic (const LWPOINT *point, GBOX *gbox)
 
static int lwline_calculate_gbox_geodetic (const LWLINE *line, GBOX *gbox)
 
static int lwpolygon_calculate_gbox_geodetic (const LWPOLY *poly, GBOX *gbox)
 
static int lwtriangle_calculate_gbox_geodetic (const LWTRIANGLE *triangle, GBOX *gbox)
 
static int lwcollection_calculate_gbox_geodetic (const LWCOLLECTION *coll, GBOX *gbox)
 
int lwgeom_calculate_gbox_geodetic (const LWGEOM *geom, GBOX *gbox)
 Calculate the geodetic bounding box for an LWGEOM. More...
 
static int ptarray_check_geodetic (const POINTARRAY *pa)
 
static int lwpoint_check_geodetic (const LWPOINT *point)
 
static int lwline_check_geodetic (const LWLINE *line)
 
static int lwpoly_check_geodetic (const LWPOLY *poly)
 
static int lwtriangle_check_geodetic (const LWTRIANGLE *triangle)
 
static int lwcollection_check_geodetic (const LWCOLLECTION *col)
 
int lwgeom_check_geodetic (const LWGEOM *geom)
 Check that coordinates of LWGEOM are all within the geodetic range (-180, -90, 180, 90) More...
 
static int ptarray_force_geodetic (POINTARRAY *pa)
 
static int lwpoint_force_geodetic (LWPOINT *point)
 
static int lwline_force_geodetic (LWLINE *line)
 
static int lwpoly_force_geodetic (LWPOLY *poly)
 
static int lwcollection_force_geodetic (LWCOLLECTION *col)
 
int lwgeom_force_geodetic (LWGEOM *geom)
 Force coordinates of LWGEOM into geodetic range (-180, -90, 180, 90) More...
 
double ptarray_length_spheroid (const POINTARRAY *pa, const SPHEROID *s)
 
double lwgeom_length_spheroid (const LWGEOM *geom, const SPHEROID *s)
 Calculate the geodetic length of a lwgeom on the unit sphere. More...
 
static int ptarray_nudge_geodetic (POINTARRAY *pa)
 When features are snapped or sometimes they are just this way, they are very close to the geodetic bounds but slightly over. More...
 
int lwgeom_nudge_geodetic (LWGEOM *geom)
 When features are snapped or sometimes they are just this way, they are very close to the geodetic bounds but slightly over. More...
 
static int point_in_cone (const POINT3D *A1, const POINT3D *A2, const POINT3D *P)
 Utility function for checking if P is within the cone defined by A1/A2. More...
 
static int point3d_equals (const POINT3D *p1, const POINT3D *p2)
 Utility function for ptarray_contains_point_sphere() More...
 
static int dot_product_side (const POINT3D *p, const POINT3D *q)
 Utility function for edge_intersects(), signum with a tolerance in determining if the value is zero. More...
 
int edge_intersects (const POINT3D *A1, const POINT3D *A2, const POINT3D *B1, const POINT3D *B2)
 Returns non-zero if edges A and B interact. More...
 
int ptarray_contains_point_sphere (const POINTARRAY *pa, const POINT2D *pt_outside, const POINT2D *pt_to_test)
 This routine returns LW_TRUE if the stabline joining the pt_outside and pt_to_test crosses the ring an odd number of times, or if the pt_to_test is on the ring boundary itself, returning LW_FALSE otherwise. More...
 

Variables

int gbox_geocentric_slow = LW_FALSE
 For testing geodetic bounding box, we have a magic global variable. More...