From de2fc9aa9e8db8e0258c8328161c6b5eda176a0a Mon Sep 17 00:00:00 2001 From: "(null)" <(null)> Date: Thu, 4 Sep 2008 19:03:56 +0200 Subject: [PATCH 1/1] Add Terraserver --- src/Makefile.am | 1 + src/terraserver-map-type.gob | 105 +++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/terraserver-map-type.gob diff --git a/src/Makefile.am b/src/Makefile.am index da7b0551..e11ae984 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -88,6 +88,7 @@ endif if TERRASERVER libviking_a_SOURCES += \ + terraserver-map-type.c terraserver-map-type.h \ terraserver.c terraserver.h endif diff --git a/src/terraserver-map-type.gob b/src/terraserver-map-type.gob new file mode 100644 index 00000000..4ebdc276 --- /dev/null +++ b/src/terraserver-map-type.gob @@ -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 +#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 -- 2.39.5