]> git.street.me.uk Git - andy/viking.git/commitdiff
Add Terraserver
author(null) <(null)>
Thu, 4 Sep 2008 17:03:56 +0000 (19:03 +0200)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Fri, 27 Mar 2009 11:14:39 +0000 (12:14 +0100)
src/Makefile.am
src/terraserver-map-type.gob [new file with mode: 0644]

index da7b0551312e9b32ed0c755323bb63bdf99093e4..e11ae984f35af2ff518597998646f265009cd060 100644 (file)
@@ -88,6 +88,7 @@ endif
 
 if TERRASERVER
 libviking_a_SOURCES += \
 
 if TERRASERVER
 libviking_a_SOURCES += \
+       terraserver-map-type.c terraserver-map-type.h \
        terraserver.c terraserver.h
 endif
 
        terraserver.c terraserver.h
 endif
 
diff --git a/src/terraserver-map-type.gob b/src/terraserver-map-type.gob
new file mode 100644 (file)
index 0000000..4ebdc27
--- /dev/null
@@ -0,0 +1,105 @@
+%headertop{
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vikcoord.h"
+#include "mapcoord.h"
+#include "vik-map-type.h"
+%}
+
+%{
+#ifdef HAVE_MATH_H
+#include <math.h>
+#endif
+
+#include "download.h"
+%}
+
+%h{
+
+%}
+
+%{
+
+static DownloadOptions terraserver_options = { NULL, 0, a_check_map_file };
+
+#define TERRASERVER_SITE "terraserver-usa.com"
+#define MARGIN_OF_ERROR 0.001
+
+static int mpp_to_scale ( gdouble mpp, guint8 type )
+{
+  mpp *= 4;
+  gint t = (gint) mpp;
+  if ( ABS(mpp - t) > MARGIN_OF_ERROR )
+    return FALSE;
+
+  switch ( t ) {
+    case 1: return (type == 4) ? 8 : 0;
+    case 2: return (type == 4) ? 9 : 0;
+    case 4: return (type != 2) ? 10 : 0;
+    case 8: return 11;
+    case 16: return 12;
+    case 32: return 13;
+    case 64: return 14;
+    case 128: return 15;
+    case 256: return 16;
+    case 512: return 17;
+    case 1024: return 18;
+    case 2048: return 19;
+    default: return 0;
+  }
+}
+
+static gdouble scale_to_mpp ( gint scale )
+{
+  return pow(2,scale - 10);
+}
+
+%}
+
+class Terraserver:Map:Type from Vik:Map:Type {
+  private int type;
+
+  override (Vik:Map:Type) gboolean
+  coord_to_mapcoord ( Vik:Map:Type *self, const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest )
+  {
+  int type = TERRASERVER_MAP_TYPE(self)->_priv->type;
+  g_assert ( src->mode == VIK_COORD_UTM );
+
+  if ( xmpp != ympp )
+    return FALSE;
+
+  dest->scale = mpp_to_scale ( xmpp, type );
+  if ( ! dest->scale )
+    return FALSE;
+
+  dest->x = (gint)(((gint)(src->east_west))/(200*xmpp));
+  dest->y = (gint)(((gint)(src->north_south))/(200*xmpp));
+  dest->z = src->utm_zone;
+  return TRUE;
+  }
+
+  override (Vik:Map:Type) void
+  mapcoord_to_center_coord ( Vik:Map:Type *self, MapCoord *src, VikCoord *dest )
+  {
+  // FIXME: slowdown here!
+  gdouble mpp = scale_to_mpp ( src->scale );
+  dest->mode = VIK_COORD_UTM;
+  dest->utm_zone = src->z;
+  dest->east_west = ((src->x * 200) + 100) * mpp;
+  dest->north_south = ((src->y * 200) + 100) * mpp;
+  }
+
+  override (Vik:Map:Type) int
+   download ( Vik:Map:Type *self, MapCoord *src, const gchar *dest_fn )
+  {
+  int res = -1;
+  int type = TERRASERVER_MAP_TYPE(self)->_priv->type;
+  gchar *uri = g_strdup_printf ( "/tile.ashx?T=%d&S=%d&X=%d&Y=%d&Z=%d", type,
+                                  src->scale, src->x, src->y, src->z );
+  res = a_http_download_get_url ( TERRASERVER_SITE, uri, dest_fn, &terraserver_options );
+  g_free ( uri );
+  return(res);
+  }
+}
\ No newline at end of file