GPS4Palm

Source Code Documentation


geo.c File Reference

#include <PalmOS.h>
#include <PalmCompatibility.h>
#include "MathLib.h"
#include "geo.h"
#include "common.h"
#include "utm.h"
#include "fp.h"

Include dependency graph for geo.c:

Go to the source code of this file.

Defines

#define SQR(x)   ((x) * (x))
 square, i.e.
#define EPS   0.00000000000000000000005
 epsilon, i.e.

Functions

double calcR (double lat)
 Calculate Earth radius at given latitude according to GRS80/WGS84 Ellipsoid.
void init_radius (void)
 Initialize look-up table with Earth's radii (in meters) at given latitudes.
void calcxy (Int32 *posx, Int32 *posy, double lon, double lat, double zero_lon, double zero_lat, UInt32 scale)
 Calculate screen position from current position and map parameters.
char Lat_To_UTM_Belt (double lat)
 Calculate UTM Belt from latitude.
double semi2deg (Int32 semi)
 Convert semicircles to degrees.
Int32 deg2semi (double deg)
 Convert degrees to semicircles.
double rad2deg (double rad)
 Convert radians to degrees.
double deg2rad (double deg)
 Convert degrees to radians.
void deg_to_d_str (double lat, double lon, char *lat_d_str, char *lon_d_str)
 Convert degrees to degrees string for latitude and longitude.
void deg_to_dm_str (double lat, double lon, char *lat_dm_str, char *lon_dm_str)
 Convert degrees to degrees and minutes string for latitude and longitude.
void deg_to_dms_str (double lat, double lon, char *lat_dms_str, char *lon_dms_str)
 Convert degrees to degrees, minutes and seconds string for latitude and longitude.
void deg_to_geodb_str (double lat, double lon, char *lat_str, char *lon_str)
 Convert degrees to degrees and minutes string for latitude and longitude as required by GeoDB.
Boolean deg_to_str (double lat, double lon, UInt8 pos_unit, char *lat_strP, char *lon_strP, char *field_strP, double *eastP, double *northP)
 Convert position to string according to selected position unit.
double gc_dist_sphere (double lat1, double lon1, double lat2, double lon2)
 Calculate Great Circle distance on spheroid of two points specified by latitude and longitude in degrees.
double gc_course_sphere (double lat1, double lon1, double lat2, double lon2)
 Calculate initial Great Circle course between two points on spheroid specified by latitude and longitude in degrees.

Variables

double Ra [101]
 Earth's radius in meters at given latitude (in integer degrees).


Define Documentation

#define EPS   0.00000000000000000000005
 

epsilon, i.e.

a really small number greater than zero

Definition at line 99 of file geo.c.

Referenced by gc_course_sphere().

#define SQR  )     ((x) * (x))
 

square, i.e.

x^2

Definition at line 96 of file geo.c.

Referenced by gc_dist_sphere().


Function Documentation

double calcR double  lat  ) 
 

Calculate Earth radius at given latitude according to GRS80/WGS84 Ellipsoid.

see: The Universal Grids: Universal Transverse Mercator (UTM) and Universal Polar Stereographic (UPS) Defense Mapping Agency Technical Manual 8358.2 http://www.nima.mil/GandG/pubs.html (Section 2-2.1 Ellipsoid Parameters)

Parameters:
lat latitude in degrees
Returns:
Earth's radius at given latitude in meters

Definition at line 127 of file geo.c.

References a, M_PI, pow(), r, SEMIMAJOR_AXIS, and sin().

Referenced by ApproachFormHandleEvent(), CheckApproach(), init_radius(), NavigationFormHandleEvent(), and TrackIntervalCheck().

void calcxy Int32 *  posx,
Int32 *  posy,
double  lon,
double  lat,
double  zero_lon,
double  zero_lat,
UInt32  scale
 

Calculate screen position from current position and map parameters.

Parameters:
posx horizontal map position
posy vertical map position
lon current longitude
lat current latitude
zero_lon longitude of map's center
zero_lat latitude of map's center
scale scale factor
Changes as compared to original version (GPSDrive):
  • data types: gdouble to double, gint to UInt16
  • removed screen specific calculations
  • added zero_lon and zero_lat to parameters
  • renamed zero_long to zero_lon for consistency
  • changed type of posx/posy from double * to Int32 *

TBD: Check geodetic background of formulae!

Definition at line 200 of file geo.c.

References cos(), fabs(), M_PI, PIXELFACT, and Ra.

Referenced by MapFormHandleEvent(), and search_map().

double deg2rad double  deg  ) 
 

Convert degrees to radians.

Parameters:
deg angle in degrees
Returns:
angle in radians

Definition at line 305 of file geo.c.

References M_PI.

Referenced by deg_to_str(), gc_course_sphere(), gc_dist_sphere(), and NavigationFormHandleEvent().

Int32 deg2semi double  deg  ) 
 

Convert degrees to semicircles.

semicircles = degrees * (2^31 / 180)

Parameters:
deg angle in degrees
Returns:
angle in semicircles

Definition at line 277 of file geo.c.

Referenced by TrackWriteLog().

void deg_to_d_str double  lat,
double  lon,
char *  lat_d_str,
char *  lon_d_str
 

Convert degrees to degrees string for latitude and longitude.

Parameters:
lat latitude in degrees
lon longitude in degrees
lat_d_str string buffer for returning latitude in degrees
lon_d_str string buffer for returning longitude in degrees

Definition at line 324 of file geo.c.

References StrCopy, and StrLen.

Referenced by deg_to_str().

void deg_to_dm_str double  lat,
double  lon,
char *  lat_dm_str,
char *  lon_dm_str
 

Convert degrees to degrees and minutes string for latitude and longitude.

Parameters:
lat latitude in degrees
lon longitude in degrees
lat_dm_str string buffer for returning latitude in degrees and minutes
lon_dm_str string buffer for returning longitude in degrees and minutes

Definition at line 385 of file geo.c.

References StrCopy, and StrLen.

Referenced by deg_to_str().

void deg_to_dms_str double  lat,
double  lon,
char *  lat_dms_str,
char *  lon_dms_str
 

Convert degrees to degrees, minutes and seconds string for latitude and longitude.

Parameters:
lat latitude in degrees
lon longitude in degrees
lat_dms_str string buffer for returning latitude in degrees, minutes and seconds
lon_dms_str string buffer for returning longitude in degrees, minutes and seconds

Definition at line 459 of file geo.c.

References StrCopy, and StrLen.

Referenced by deg_to_str().

void deg_to_geodb_str double  lat,
double  lon,
char *  lat_str,
char *  lon_str
 

Convert degrees to degrees and minutes string for latitude and longitude as required by GeoDB.

Parameters:
lat latitude in degrees
lon longitude in degrees
lat_str string buffer for returning latitude in degrees, minutes and hemisphere
lon_str string buffer for returning longitude in degrees, minutes and hemisphere
Note:
Mostly identical to deg_to_dm_str()

Definition at line 547 of file geo.c.

Referenced by Position2Geodb().

Boolean deg_to_str double  lat,
double  lon,
UInt8  pos_unit,
char *  lat_strP,
char *  lon_strP,
char *  field_strP,
double *  eastP,
double *  northP
 

Convert position to string according to selected position unit.

Parameters:
lat Latitude
lon Longitude
pos_unit position unit <POS_D|POS_DM|POS_DMS|POS_UTM>
lat_strP ptr to Latitude/Easting String buffer (>=20 bytes)
lon_strP ptr to Longitude/Northing String buffer (>=20 bytes)
field_strP ptr to UTM field String buffer If pos_unit != POS_UTM, an empty string is returned. If conversion to UTM failed, "n.a." is returned. (>=5 bytes)
eastP UTM Easting returned by reference (pass NULL if not needed)
northP UTM Northing returned by reference (pass NULL if not needed)
Returns:
Conversion to UTM successful. Always true, if any position format other than UTM is set in the preferences.
Note:
eastP and northP are updated only if pos_unit == POS_UTM and conversion to UTM was successful

Definition at line 634 of file geo.c.

References Convert_Geodetic_To_UTM(), deg2rad(), deg_to_d_str(), deg_to_dm_str(), deg_to_dms_str(), format_number(), Lat_To_UTM_Belt(), POS_D, POS_DM, POS_DMS, POS_UTM, StrCopy, and UTM_NO_ERROR.

Referenced by Position2Clipboard().

double gc_course_sphere double  lat1,
double  lon1,
double  lat2,
double  lon2
 

Calculate initial Great Circle course between two points on spheroid specified by latitude and longitude in degrees.

As opposed to the source (see below), the following convention is followed:

  • East longitude: positive
  • West longitude: negative

Source: Aviation Formulary V1.41 By Ed Williams http://williams.best.vwh.net/avform.htm

Parameters:
lat1 latitude of point 1
lon1 longitude of point 1
lat2 latitude of point 2
lon2 longitude of point 2
Returns:
initial course in radians

Definition at line 753 of file geo.c.

References atan2(), cos(), deg2rad(), EPS, fmod(), M_PI, and sin().

Referenced by NavigationFormHandleEvent().

double gc_dist_sphere double  lat1,
double  lon1,
double  lat2,
double  lon2
 

Calculate Great Circle distance on spheroid of two points specified by latitude and longitude in degrees.

Source: Aviation Formulary V1.41 By Ed Williams http://williams.best.vwh.net/avform.htm

Parameters:
lat1 latitude of point 1
lon1 longitude of point 1
lat2 latitude of point 2
lon2 longitude of point 2
Returns:
distance in radians

Definition at line 714 of file geo.c.

References asin(), cos(), deg2rad(), sin(), SQR, and sqrt().

Referenced by ApproachFormHandleEvent(), CheckApproach(), NavigationFormHandleEvent(), TrackIntervalCheck(), and UpdateActWpt().

void init_radius void   ) 
 

Initialize look-up table with Earth's radii (in meters) at given latitudes.

To save memory and to reduce time required for initialization, the symmetry is exploitet. ( sin(90°+x) = sin(90°-x) )

Definition at line 169 of file geo.c.

References calcR(), and Ra.

char Lat_To_UTM_Belt double  lat  ) 
 

Calculate UTM Belt from latitude.

Parameters:
lat latitude in degrees
Returns:
UTM Belt Designator

Definition at line 231 of file geo.c.

References floor().

Referenced by deg_to_str().

double rad2deg double  rad  ) 
 

Convert radians to degrees.

Parameters:
rad angle in radians
Returns:
angle in degrees

Definition at line 291 of file geo.c.

References M_PI.

Referenced by NavigationFormHandleEvent(), and WayptEditFormHandleEvent().

double semi2deg Int32  semi  ) 
 

Convert semicircles to degrees.

degrees = semicircles * (180 / 2^31)

Parameters:
semi angle in semicircles
Returns:
angle in degrees

Definition at line 263 of file geo.c.

Referenced by ApproachFormHandleEvent(), CheckApproach(), UpdateActWpt(), and WayptEditFormHandleEvent().


Variable Documentation

double Ra[101]
 

Earth's radius in meters at given latitude (in integer degrees).

Definition at line 102 of file geo.c.

Referenced by calcxy(), and init_radius().


Created: Mon, 08 Oct 2007 22:33:16 +0200
Copyright ©2004 M. Prinke