static void srtm_dem_download_thread ( DEMDownloadParams *p, gpointer threaddata ) { gint intlat, intlon; const gchar *continent_dir; intlat = (int)floor(p->lat); intlon = (int)floor(p->lon); continent_dir = srtm_continent_dir(intlat, intlon); if (!continent_dir) { if ( p->vdl ) { gchar *msg = g_strdup_printf ( _("No SRTM data available for %f, %f"), p->lat, p->lon ); vik_window_statusbar_update ( (VikWindow*)VIK_GTK_WINDOW_FROM_LAYER(p->vdl), msg, VIK_STATUSBAR_INFO ); g_free ( msg ); } return; } gchar *src_fn = g_strdup_printf("%s%s/%c%02d%c%03d.hgt.zip", SRTM_HTTP_URI, continent_dir, (intlat >= 0) ? 'N' : 'S', ABS(intlat), (intlon >= 0) ? 'E' : 'W', ABS(intlon) ); static DownloadMapOptions options = { FALSE, FALSE, NULL, 0, a_check_map_file, NULL, NULL }; a_http_download_get_url ( SRTM_HTTP_SITE, src_fn, p->dest, &options, NULL ); g_free ( src_fn ); }
/** * a_babel_convert_from_url_filter: * @vt: The #VikTrwLayer where to insert the collected data * @url: the URL to fetch * @input_type: If input_type is %NULL, input must be GPX. * @babelfilters: The filter arguments to pass to gpsbabel * @cb: Optional callback function. Same usage as in a_babel_convert(). * @user_data: Passed along to cb * @options: Download options. If %NULL then default download options will be used. * * Download the file pointed by the URL and optionally uses GPSBabel to convert from input_type. * If input_type and babelfilters are %NULL, gpsbabel is not used. * * Returns: %TRUE on successful invocation of GPSBabel or read of the GPX * */ gboolean a_babel_convert_from_url_filter ( VikTrwLayer *vt, const char *url, const char *input_type, const char *babelfilters, BabelStatusFunc cb, gpointer user_data, DownloadFileOptions *options ) { // If no download options specified, use defaults: DownloadFileOptions myoptions = { FALSE, FALSE, NULL, 2, NULL, NULL, NULL }; if ( options ) myoptions = *options; gint fd_src; int fetch_ret; gboolean ret = FALSE; gchar *name_src = NULL; gchar *babelargs = NULL; g_debug("%s: input_type=%s url=%s", __FUNCTION__, input_type, url); if ((fd_src = g_file_open_tmp("tmp-viking.XXXXXX", &name_src, NULL)) >= 0) { g_debug ("%s: temporary file: %s", __FUNCTION__, name_src); close(fd_src); (void)g_remove(name_src); fetch_ret = a_http_download_get_url(url, "", name_src, &myoptions, NULL); if (fetch_ret == DOWNLOAD_SUCCESS) { if (input_type != NULL || babelfilters != NULL) { babelargs = (input_type) ? g_strdup_printf(" -i %s", input_type) : g_strdup(""); ret = a_babel_convert_from_filter( vt, babelargs, name_src, babelfilters, NULL, NULL, NULL ); } else { /* Process directly the retrieved file */ g_debug("%s: directly read GPX file %s", __FUNCTION__, name_src); FILE *f = g_fopen(name_src, "r"); if (f) { gchar *dirpath = g_path_get_dirname ( name_src ); ret = a_gpx_read_file ( vt, f, dirpath ); g_free ( dirpath ); fclose(f); } // Try to avoid adding the description if URL is OAuth signed if ( !g_ascii_strncasecmp(url, "?oauth_consumer_key=", 20) ) { VikTRWMetadata *meta = vik_trw_layer_get_metadata(vt); if ( meta && !meta->description ) { meta->description = g_strdup ( url ); } } } } (void)util_remove(name_src); g_free(babelargs); g_free(name_src); } return ret; }
/** * a_babel_convert_from_url: * @vt: The #VikTrwLayer where to insert the collected data * @url: the URL to fetch * @cb: Optional callback function. Same usage as in a_babel_convert(). * @user_data: passed along to cb * @options: download options. Maybe NULL. * * Download the file pointed by the URL and optionally uses GPSBabel to convert from input_file_type. * If input_file_type is %NULL, doesn't use GPSBabel. Input must be GPX. * * Returns: %TRUE on successful invocation of GPSBabel or read of the GPX * */ gboolean a_babel_convert_from_url ( VikTrwLayer *vt, const char *url, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options ) { // If no download options specified, use defaults: DownloadMapOptions myoptions = { FALSE, FALSE, NULL, 2, NULL, NULL, NULL }; if ( options ) myoptions = *options; gint fd_src; int fetch_ret; gboolean ret = FALSE; gchar *name_src = NULL; gchar *babelargs = NULL; g_debug("%s: input_type=%s url=%s", __FUNCTION__, input_type, url); if ((fd_src = g_file_open_tmp("tmp-viking.XXXXXX", &name_src, NULL)) >= 0) { g_debug ("%s: temporary file: %s", __FUNCTION__, name_src); close(fd_src); g_remove(name_src); fetch_ret = a_http_download_get_url(url, "", name_src, &myoptions, NULL); if (fetch_ret == 0) { if (input_type != NULL) { babelargs = g_strdup_printf(" -i %s", input_type); ret = a_babel_convert_from( vt, babelargs, name_src, NULL, NULL, NULL ); } else { /* Process directly the retrieved file */ g_debug("%s: directly read GPX file %s", __FUNCTION__, name_src); FILE *f = g_fopen(name_src, "r"); if (f) { ret = a_gpx_read_file ( vt, f ); fclose(f); f = NULL; } } } g_remove(name_src); g_free(babelargs); g_free(name_src); } return ret; }
static DownloadResult_t expedia_download ( MapCoord *src, const gchar *dest_fn, void *handle ) { gint height, width; struct LatLon ll; gchar *uri; expedia_xy_to_latlon_middle ( src->scale, src->x, src->y, &ll ); height = HEIGHT_OF_LAT_DEGREE / expedia_altis_freq(src->scale) / (src->scale); width = height * cos ( ll.lat * DEGREES_TO_RADS ); height += 2*REAL_HEIGHT_BUFFER; width += 2*REAL_WIDTH_BUFFER; uri = g_strdup_printf ( "/pub/agent.dll?qscr=mrdt&ID=3XNsF.&CenP=%lf,%lf&Lang=%s&Alti=%d&Size=%d,%d&Offs=0.000000,0.000000&BCheck&tpid=1", ll.lat, ll.lon, (ll.lon > -30) ? "EUR0809" : "USA0409", src->scale, width, height ); DownloadResult_t res = a_http_download_get_url ( EXPEDIA_SITE, uri, dest_fn, &expedia_options, NULL ); if (res == DOWNLOAD_SUCCESS) expedia_snip ( dest_fn ); g_free(uri); return(res); }