]> err.no Git - mapper/blob - src/latlon.h
Parse directly but update informations in callbacks only if we got a sentence that...
[mapper] / src / latlon.h
1 #ifndef _LATLON_H
2 #define _LATLON_H
3
4 #include <glib.h>
5
6 /* Int ranges for integerized lat/lon */
7 #define LATLON_MAX 2147483646
8 #define LATLON_MIN -2147483646
9 #define EARTH_RADIUS (3440.06479f)
10
11 #define PI   (3.14159265358979323846f)
12 #define MERCATOR_SPAN (-6.28318377773622f)
13 #define MERCATOR_TOP (3.14159188886811f)
14
15 #define latlon2unit(lat, lon, unitx, unity) { \
16         gdouble tmp; \
17         unitx = (lon + 180.f) * (WORLD_SIZE_UNITS / 360.f) + 0.5f; \
18         tmp = sinf(lat * (PI / 180.f)); \
19         unity = 0.5f + (WORLD_SIZE_UNITS / MERCATOR_SPAN) \
20                 * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP); \
21 }
22
23 #define unit2latlon(unitx, unity, lat, lon) { \
24         (lon) = ((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f; \
25         (lat) = (360.f * (atanf(expf(((unity) * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) \
26                 + MERCATOR_TOP)))) * (1.f / PI) - 90.f; \
27 }
28
29 typedef enum {
30         DDPDDDDD,
31         DD_MMPMMM,
32         DD_MM_SSPS,
33         DDPDDDDD_NSEW,
34         DD_MMPMMM_NSEW,
35         DD_MM_SSPS_NSEW,
36         DEG_FORMAT_ENUM_COUNT
37 } DegFormat;
38 gchar *DEG_FORMAT_TEXT[DEG_FORMAT_ENUM_COUNT];
39
40 #define lat_format(F, A, B) deg_format((F),(A), (B), 'S', 'N')
41 #define lon_format(F, A, B) deg_format((F),(A), (B), 'W', 'E')
42
43 void latlon_init(void);
44
45 gint32 lon2mp_int(gdouble lon);
46 gint32 lat2mp_int(gdouble lat);
47 gdouble calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
48 gdouble calculate_ddistance(gint lat1, gint lon1, gint lat2, gint lon2);
49 gulong calculate_idistance(gint lat1, gint lon1, gint lat2, gint lon2);
50 gulong calculate_idistance_cmp(gint lat1, gint lon1, gint lat2, gint lon2);
51 gdouble calculate_course(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
52
53 gboolean distance_point_to_line(gdouble x, gdouble y, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble *d);
54
55 guint32 xy2tile(guint x, guint y);
56 guint32 lon2x(gdouble lon);
57 guint32 lat2y(gdouble lat);
58
59 void deg_format(DegFormat degformat, gdouble coor, gchar *scoor, gchar neg_char, gchar pos_char);
60
61 #endif