]> err.no Git - mapper/blobdiff - src/latlon.c
Add header and cast properly.
[mapper] / src / latlon.c
index 1d4e44f0675ff2fc2933fb99ec9c4d0195b21272..e4911662acfe900cebd3d1dfe355ea1619d46a95 100644 (file)
@@ -1,11 +1,36 @@
+/*
+ * This file is part of mapper
+ *
+ * Copyright (C) 2007 Kaj-Michael Lang
+ *
+ * Original Algorithms from misc web sites
+ *
+ * Default map data provided by http://www.openstreetmap.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
 /*
  * Different Lat/Lon and related functions
  * (conversion, distances, etc)
  */
-#define _GNU_SOURCE
+#include "config.h"
 
 #include <math.h>
 #include <glib.h>
+#include <glib/gi18n.h>
 
 #include "latlon.h"
 #include "osm.h"
 
 #define EARTH_RADIUS (3440.06479f)
 
+void
+latlon_init(void)
+{
+DEG_FORMAT_TEXT[DDPDDDDD] = "-dd.ddddd°";
+DEG_FORMAT_TEXT[DD_MMPMMM] = "-dd°mm.mmm'";
+DEG_FORMAT_TEXT[DD_MM_SSPS] = "-dd°mm'ss.s\"";
+DEG_FORMAT_TEXT[DDPDDDDD_NSEW] = "dd.ddddd° S";
+DEG_FORMAT_TEXT[DD_MMPMMM_NSEW] = "dd°mm.mmm' S";
+DEG_FORMAT_TEXT[DD_MM_SSPS_NSEW] = "dd°mm'ss.s\" S";
+
+UNITS_TEXT[UNITS_KM] = _("km");
+UNITS_TEXT[UNITS_MI] = _("mi.");
+UNITS_TEXT[UNITS_NM] = _("n.m.");
+}
+
 static inline gdouble 
 magnitude(gdouble x1, gdouble y1, gdouble x2, gdouble y2)
 {
@@ -185,3 +225,44 @@ c*=180.f/M_PIl;
 c=c+360 % 360;
 return c;
 }
+
+void
+deg_format(DegFormat degformat, gdouble coor, gchar * scoor, gchar neg_char, gchar pos_char)
+{
+gdouble min;
+gdouble acoor=fabs(coor);
+
+switch (degformat) {
+       case DDPDDDDD:
+               g_sprintf(scoor, "%.5f°", coor);
+               break;
+       case DDPDDDDD_NSEW:
+               g_sprintf(scoor, "%.5f° %c", acoor,
+                       coor < 0.f ? neg_char : pos_char);
+               break;
+
+       case DD_MMPMMM:
+               g_sprintf(scoor, "%d°%06.3f'",
+                       (int)coor, (acoor - (int)acoor) * 60.0);
+               break;
+       case DD_MMPMMM_NSEW:
+               g_sprintf(scoor, "%d°%06.3f' %c",
+                       (int)acoor, (acoor - (int)acoor) * 60.0,
+                       coor < 0.f ? neg_char : pos_char);
+               break;
+
+       case DD_MM_SSPS:
+               min = (acoor - (int)acoor) * 60.0;
+               g_sprintf(scoor, "%d°%02d'%04.1f\"", (int)coor, (int)min,
+                       ((min - (int)min) * 60.0));
+               break;
+       case DD_MM_SSPS_NSEW:
+               min = (acoor - (int)acoor) * 60.0;
+               g_sprintf(scoor, "%d°%02d'%04.1f\" %c", (int)acoor, (int)min,
+                       ((min - (int)min) * 60.0),
+                       coor < 0.f ? neg_char : pos_char);
+               break;
+       default:;
+}
+}
+