2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef __GIS_UTIL_H__
19 #define __GIS_UTIL_H__
23 #define EARTH_R (6371000)
24 #define EARTH_C (2*G_PI*EARTH_R)
34 * rad - Radians, also radius
35 * m - Meters, for earth-based distances
36 * px - Pixels, for screen-based distances
38 * height - Height, the distance above the geoid (ground)
39 * elev - Elevation, the distance above the spheroid
40 * rad - Radius, the distance from the center of the earth
42 * lat - Latitude, amount north-south, -90 (S) .. 90 (N)
43 * lon - Longitude, amount east-west, -180 (W) .. 180 (E)
44 * incl - Inclination, polar equiv of latitude, Pi .. 0
45 * azim - Azimuth, polar equiv of longitude, -Pi .. Pi
47 * x - 0° lon is positive
48 * y - 90° lon is positive
49 * z - North pole is positive
51 * llh - lat,lon,height
59 * lat lon elev -> x y z
60 * lle2xyz: 0.0, 0.0, 0.0 -> 0.0, 0.0, 10.0
61 * lle2xyz: 90.0, 0.0, 0.0 -> 0.0, 10.0, 0.0
62 * lle2xyz: 0.0, 90.0, 0.0 -> 10.0, 0.0, 0.0
64 * x y z -> lat lon elev
65 * xyz2lle: 10.0, 0.0, 0.0 -> 0.0, 90.0, 0.0
66 * xyz2lle: 0.0, 10.0, 0.0 -> 90.0, 0.0, 0.0
67 * xyz2lle: 0.0, 0.0, 10.0 -> 0.0, 0.0, 0.0
70 #define azim2lon(azim) ((azim)*180/G_PI)
71 #define lon2azim(lon) ((lon)*G_PI/180)
72 #define incl2lat(incl) (90-(incl)*180/G_PI)
73 #define lat2incl(lat) ((90-(lat))*G_PI/180)
74 #define rad2elev(rad) ((rad)-EARTH_R)
75 #define elev2rad(elev) ((elev)+EARTH_R)
77 #define deg2rad(deg) (((deg)*G_PI)/180.0)
78 #define rad2deg(rad) (((rad)*180.0)/G_PI)
80 #define FOV_DIST 2000.0
81 #define MPPX(dist) (4*dist/FOV_DIST)
83 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
84 gdouble *x, gdouble *y, gdouble *z);
86 void xyz2lle(gdouble x, gdouble y, gdouble z,
87 gdouble *lat, gdouble *lon, gdouble *elev);
89 void xyz2ll(gdouble x, gdouble y, gdouble z,
90 gdouble *lat, gdouble *lon);
92 gdouble ll2m(gdouble lon_dist, gdouble lat);
94 gdouble distd(gdouble *a, gdouble *b);
96 gdouble lon_avg(gdouble a, gdouble b);