]> err.no Git - mapper/commitdiff
Start to move lat/lon conversion functions/helpers here
authorKaj-Michael Lang <milang@onion.tal.org>
Mon, 16 Jul 2007 11:02:52 +0000 (14:02 +0300)
committerKaj-Michael Lang <milang@onion.tal.org>
Mon, 16 Jul 2007 11:02:52 +0000 (14:02 +0300)
src/latlon.c [new file with mode: 0644]
src/latlon.h [new file with mode: 0644]

diff --git a/src/latlon.c b/src/latlon.c
new file mode 100644 (file)
index 0000000..472a983
--- /dev/null
@@ -0,0 +1,26 @@
+#define _GNU_SOURCE
+
+#include <math.h>
+#include <glib.h>
+
+#include "osm.h"
+
+/* Int ranges for integerized lat/lon */
+#define LATLON_MAX 2147483646
+#define LATLON_MIN -2147483646
+
+/* Convert latitude to integerized+mercator projected value */
+gint32
+lat2mp_int(gdouble lat)
+{
+return lat > 85.051128779 ? LATLON_MAX : lat < -85.051128779 ? LATLON_MIN :
+       lrint(log(tan(M_PI_4l+lat*M_PIl/360))/M_PIl*LATLON_MAX);
+}
+
+/* Convert longitude to integerized+mercator projected value */
+gint32
+lon2mp_int(gdouble lon)
+{
+return lrint(lon/180*LATLON_MAX);
+}
+
diff --git a/src/latlon.h b/src/latlon.h
new file mode 100644 (file)
index 0000000..774756d
--- /dev/null
@@ -0,0 +1,5 @@
+#include <glib.h>
+
+gint32 lon2mp_int(gdouble lon);
+gint32 lat2mp_int(gdouble lat);
+