From 29935bc5ab0a66c55d566eb9262d697079452c51 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 16 Jul 2007 14:02:52 +0300 Subject: [PATCH] Start to move lat/lon conversion functions/helpers here --- src/latlon.c | 26 ++++++++++++++++++++++++++ src/latlon.h | 5 +++++ 2 files changed, 31 insertions(+) create mode 100644 src/latlon.c create mode 100644 src/latlon.h diff --git a/src/latlon.c b/src/latlon.c new file mode 100644 index 0000000..472a983 --- /dev/null +++ b/src/latlon.c @@ -0,0 +1,26 @@ +#define _GNU_SOURCE + +#include +#include + +#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 index 0000000..774756d --- /dev/null +++ b/src/latlon.h @@ -0,0 +1,5 @@ +#include + +gint32 lon2mp_int(gdouble lon); +gint32 lat2mp_int(gdouble lat); + -- 2.39.5