/** * Process the list of DEM files and convert each one to a relative path */ static GList *dem_layer_convert_to_relative_filenaming ( GList *files ) { gchar *cwd = g_get_current_dir(); if ( !cwd ) return files; GList *relfiles = NULL; while ( files ) { gchar *file = g_strdup ( file_GetRelativeFilename ( cwd, files->data ) ); relfiles = g_list_prepend ( relfiles, file ); files = files->next; } g_free ( cwd ); if ( relfiles ) { // Replacing current list, so delete old values first. GList *iter = files; while ( iter ) { g_free ( iter->data ); iter = iter->next; } g_list_free ( files ); return relfiles; } return files; }
static VikLayerParamData georef_layer_get_param ( VikGeorefLayer *vgl, guint16 id, gboolean is_file_operation ) { VikLayerParamData rv; switch ( id ) { case PARAM_IMAGE: { gboolean set = FALSE; if ( is_file_operation ) { if ( vgl->pixbuf && !vgl->image ) { // Force creation of image file create_image_file ( vgl ); } if ( a_vik_get_file_ref_format() == VIK_FILE_REF_FORMAT_RELATIVE ) { gchar *cwd = g_get_current_dir(); if ( cwd ) { rv.s = file_GetRelativeFilename ( cwd, vgl->image ); if ( !rv.s ) rv.s = ""; set = TRUE; } } } if ( !set ) rv.s = vgl->image ? vgl->image : ""; break; } case PARAM_CN: rv.d = vgl->corner.northing; break; case PARAM_CE: rv.d = vgl->corner.easting; break; case PARAM_MN: rv.d = vgl->mpp_northing; break; case PARAM_ME: rv.d = vgl->mpp_easting; break; case PARAM_CZ: rv.u = vgl->corner.zone; break; case PARAM_CL: rv.u = vgl->corner.letter; break; case PARAM_AA: rv.u = vgl->alpha; break; default: break; } return rv; }
static void a_gpspoint_write_waypoint ( const gpointer id, const VikWaypoint *wp, FILE *f ) { struct LatLon ll; gchar s_lat[COORDS_STR_BUFFER_SIZE]; gchar s_lon[COORDS_STR_BUFFER_SIZE]; // Sanity clauses if ( !wp ) return; if ( !(wp->name) ) return; vik_coord_to_latlon ( &(wp->coord), &ll ); a_coords_dtostr_buffer ( ll.lat, s_lat ); a_coords_dtostr_buffer ( ll.lon, s_lon ); gchar *tmp_name = slashdup(wp->name); fprintf ( f, "type=\"waypoint\" latitude=\"%s\" longitude=\"%s\" name=\"%s\"", s_lat, s_lon, tmp_name ); g_free ( tmp_name ); if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) { gchar s_alt[COORDS_STR_BUFFER_SIZE]; a_coords_dtostr_buffer ( wp->altitude, s_alt ); fprintf ( f, " altitude=\"%s\"", s_alt ); } if ( wp->has_timestamp ) fprintf ( f, " unixtime=\"%ld\"", wp->timestamp ); if ( wp->comment ) { gchar *tmp_comment = slashdup(wp->comment); fprintf ( f, " comment=\"%s\"", tmp_comment ); g_free ( tmp_comment ); } if ( wp->description ) { gchar *tmp_description = slashdup(wp->description); fprintf ( f, " description=\"%s\"", tmp_description ); g_free ( tmp_description ); } if ( wp->source ) { gchar *tmp_source = slashdup(wp->source); fprintf ( f, " source=\"%s\"", tmp_source ); g_free ( tmp_source ); } if ( wp->type ) { gchar *tmp_type = slashdup(wp->type); fprintf ( f, " xtype=\"%s\"", tmp_type ); g_free ( tmp_type ); } if ( wp->image ) { gchar *tmp_image = NULL; gchar *cwd = NULL; if ( a_vik_get_file_ref_format() == VIK_FILE_REF_FORMAT_RELATIVE ) { cwd = g_get_current_dir(); if ( cwd ) tmp_image = g_strdup ( file_GetRelativeFilename ( cwd, wp->image ) ); } // if cwd not available - use image filename as is // this should be an absolute path as set in thumbnails if ( !cwd ) tmp_image = slashdup(wp->image); if ( tmp_image ) fprintf ( f, " image=\"%s\"", tmp_image ); g_free ( cwd ); g_free ( tmp_image ); } if ( wp->symbol ) { // Due to changes in garminsymbols - the symbol name is now in Title Case // However to keep newly generated .vik files better compatible with older Viking versions // The symbol names will always be lowercase gchar *tmp_symbol = g_utf8_strdown(wp->symbol, -1); fprintf ( f, " symbol=\"%s\"", tmp_symbol ); g_free ( tmp_symbol ); } if ( ! wp->visible ) fprintf ( f, " visible=\"n\"" ); fprintf ( f, "\n" ); }