]> Pileus Git - grits/blob - src/gis-world.h
Add Shuttle Radar Topography Mission plugin and height code
[grits] / src / gis-world.h
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 #ifndef __GIS_WORLD_H__
19 #define __GIS_WORLD_H__
20
21 #include <glib-object.h>
22
23 #ifndef M_PI
24 #define M_PI 3.14159265358979323846
25 #endif
26
27 #define EARTH_R (6371000)
28 #define EARTH_C (2*M_PI*EARTH_R)
29 #define NORTH  90
30 #define SOUTH -90
31 #define EAST  180
32 #define WEST -180
33
34 /**
35  * Terms
36  * -----
37  * deg    - Degrees
38  * rad    - Radians, also radius
39  * m      - Meters, for earth-based distances
40  * px     - Pixels, for screen-based distances
41  *
42  * height - Height, the distance above the geoid (ground)
43  * elev   - Elevation, the distance above the spheroid
44  * rad    - Radius, the distance from the center of the earth
45  *
46  * lat    - Latitude, amount north-south, -90 (S) .. 90 (N)
47  * lon    - Longitude, amount east-west, -180 (W) .. 180 (E)
48  * incl   - Inclination, polar equiv of  latitude, Pi .. 0
49  * azim   - Azimuth, polar equiv of longitude, -Pi .. Pi
50  *
51  * x      -  0° lon is positive
52  * y      - 90° lon is positive
53  * z      - North pole is positive
54  *
55  * llh    - lat,lon,height
56  * lle    - lat,lon,elev
57  * llr    - lat,lon,rad
58  * pol    - incl,azim,rad
59  * xyz    - x,y,z
60  */
61
62 /**
63  *             lat    lon   elev ->      x      y      z
64  * lle2xyz:    0.0,   0.0,   0.0 ->    0.0,   0.0,  10.0
65  * lle2xyz:   90.0,   0.0,   0.0 ->    0.0,  10.0,   0.0
66  * lle2xyz:    0.0,  90.0,   0.0 ->   10.0,   0.0,   0.0
67  *
68  *               x      y      z ->    lat    lon   elev
69  * xyz2lle:   10.0,   0.0,   0.0 ->    0.0,  90.0,   0.0
70  * xyz2lle:    0.0,  10.0,   0.0 ->   90.0,   0.0,   0.0
71  * xyz2lle:    0.0,   0.0,  10.0 ->    0.0,   0.0,   0.0
72  */
73
74 #define azim2lon(azim) ((azim)*180/M_PI)
75 #define lon2azim(lon)  ((lon)*M_PI/180)
76 #define incl2lat(incl) (90-(incl)*180/M_PI)
77 #define lat2incl(lat)  ((90-(lat))*M_PI/180)
78 #define rad2elev(rad)  ((rad)-EARTH_R)
79 #define elev2rad(elev) ((elev)+EARTH_R)
80
81 #define deg2rad(deg) (((deg)*M_PI)/180.0)
82 #define rad2deg(rad) (((rad)*180.0)/M_PI)
83
84 #define FOV_DIST   2000.0
85 #define MPPX(dist) (4*dist/FOV_DIST)
86
87 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
88                 gdouble *x, gdouble *y, gdouble *z);
89
90 void xyz2lle(gdouble x, gdouble y, gdouble z,
91                 gdouble *lat, gdouble *lon, gdouble *elev);
92
93 void xyz2ll(gdouble x, gdouble y, gdouble z,
94                 gdouble *lat, gdouble *lon);
95
96 gdouble ll2m(gdouble lon_dist, gdouble lat);
97
98 gdouble distd(gdouble *a, gdouble *b);
99
100 /************
101  * GisWorld *
102  ************/
103 #define GIS_TYPE_WORLD            (gis_world_get_type())
104 #define GIS_WORLD(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),   GIS_TYPE_WORLD, GisWorld))
105 #define GIS_IS_WORLD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),   GIS_TYPE_WORLD))
106 #define GIS_WORLD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST   ((klass), GIS_TYPE_WORLD, GisWorldClass))
107 #define GIS_IS_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE   ((klass), GIS_TYPE_WORLD))
108 #define GIS_WORLD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),   GIS_TYPE_WORLD, GisWorldClass))
109
110 typedef struct _GisWorld      GisWorld;
111 typedef struct _GisWorldClass GisWorldClass;
112
113 struct _GisWorld {
114         GObject parent_instance;
115
116         /* instance members */
117         gboolean offline;
118 };
119
120 struct _GisWorldClass {
121         GObjectClass parent_class;
122         
123         /* class members */
124 };
125
126 GType gis_world_get_type(void);
127
128 /* Methods */
129 GisWorld *gis_world_new();
130
131 void gis_world_refresh(GisWorld *world);
132
133 void gis_world_set_offline(GisWorld *world, gboolean offline);
134 gboolean gis_world_get_offline(GisWorld *world);
135
136 #endif