void a_geonames_wikipedia_box(VikWindow *vw, VikTrwLayer *vtl, VikLayersPanel *vlp, struct LatLon maxmin[2]) { gchar *uri; gchar *tmpname; GList *wiki_places; GList *selected; GList *wp_runner; VikWaypoint *wiki_wp; found_geoname *wiki_geoname; /* encode doubles in a C locale */ gchar *north = a_coords_dtostr(maxmin[0].lat); gchar *south = a_coords_dtostr(maxmin[1].lat); gchar *east = a_coords_dtostr(maxmin[0].lon); gchar *west = a_coords_dtostr(maxmin[1].lon); uri = g_strdup_printf(GEONAMES_WIKIPEDIA_URL_FMT, north, south, east, west); g_free(north); north = NULL; g_free(south); south = NULL; g_free(east); east = NULL; g_free(west); west = NULL; tmpname = download_url(uri); if (!tmpname) { none_found(vw); return; } wiki_places = get_entries_from_file(tmpname); if (g_list_length(wiki_places) == 0) { none_found(vw); return; } selected = a_select_geoname_from_list(VIK_GTK_WINDOW_FROM_WIDGET(vw), wiki_places, TRUE, "Select articles", "Select the articles you want to add."); wp_runner = selected; while (wp_runner) { wiki_geoname = (found_geoname *)wp_runner->data; wiki_wp = vik_waypoint_new(); wiki_wp->visible = TRUE; vik_coord_load_from_latlon(&(wiki_wp->coord), vik_trw_layer_get_coord_mode ( vtl ), &(wiki_geoname->ll)); vik_waypoint_set_comment(wiki_wp, wiki_geoname->desc); vik_trw_layer_filein_add_waypoint ( vtl, wiki_geoname->name, wiki_wp ); wp_runner = g_list_next(wp_runner); } free_geoname_list(wiki_places); free_geoname_list(selected); g_free(uri); if (tmpname) { g_free(tmpname); } vik_layers_panel_emit_update(vlp); }
static void gpx_write_waypoint ( const gchar *name, VikWaypoint *wp, GpxWritingContext *context ) { FILE *f = context->file; static struct LatLon ll; gchar *s_lat,*s_lon; gchar *tmp; vik_coord_to_latlon ( &(wp->coord), &ll ); s_lat = a_coords_dtostr( ll.lat ); s_lon = a_coords_dtostr( ll.lon ); fprintf ( f, "<wpt lat=\"%s\" lon=\"%s\"%s>\n", s_lat, s_lon, wp->visible ? "" : " hidden=\"hidden\"" ); g_free ( s_lat ); g_free ( s_lon ); tmp = entitize ( name ); fprintf ( f, " <name>%s</name>\n", tmp ); g_free ( tmp); if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) { tmp = a_coords_dtostr ( wp->altitude ); fprintf ( f, " <ele>%s</ele>\n", tmp ); g_free ( tmp ); } if ( wp->comment ) { tmp = entitize(wp->comment); fprintf ( f, " <desc>%s</desc>\n", tmp ); g_free ( tmp ); } if ( wp->image ) { tmp = entitize(wp->image); fprintf ( f, " <link>%s</link>\n", tmp ); g_free ( tmp ); } if ( wp->symbol ) { tmp = entitize(wp->symbol); fprintf ( f, " <sym>%s</sym>\n", tmp); g_free ( tmp ); } fprintf ( f, "</wpt>\n" ); }
static void a_gpspoint_write_trackpoint ( VikTrackpoint *tp, FILE *f ) { static struct LatLon ll; gchar *s_lat, *s_lon; vik_coord_to_latlon ( &(tp->coord), &ll ); /* TODO: modify a_coords_dtostr() to accept (optional) buffer * instead of doing malloc/free everytime */ s_lat = a_coords_dtostr(ll.lat); s_lon = a_coords_dtostr(ll.lon); fprintf ( f, "type=\"trackpoint\" latitude=\"%s\" longitude=\"%s\"", s_lat, s_lon ); g_free ( s_lat ); g_free ( s_lon ); if ( tp->altitude != VIK_DEFAULT_ALTITUDE ) { gchar *s_alt = a_coords_dtostr(tp->altitude); fprintf ( f, " altitude=\"%s\"", s_alt ); g_free(s_alt); } if ( tp->has_timestamp ) fprintf ( f, " unixtime=\"%ld\"", tp->timestamp ); if ( tp->newsegment ) fprintf ( f, " newsegment=\"yes\"" ); if (tp->extended) { fprintf ( f, " extended=\"yes\"" ); if (!isnan(tp->speed)) { gchar *s_speed = a_coords_dtostr(tp->speed); fprintf ( f, " speed=\"%s\"", s_speed ); g_free(s_speed); } if (!isnan(tp->course)) { gchar *s_course = a_coords_dtostr(tp->course); fprintf ( f, " course=\"%s\"", s_course ); g_free(s_course); } if (tp->nsats > 0) fprintf ( f, " sat=\"%d\"", tp->nsats ); if (tp->fix_mode > 0) fprintf ( f, " fix=\"%d\"", tp->fix_mode ); } fprintf ( f, "\n" ); }
static void a_gpspoint_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f ) { static struct LatLon ll; gchar *s_lat, *s_lon; vik_coord_to_latlon ( &(wp->coord), &ll ); s_lat = a_coords_dtostr(ll.lat); s_lon = a_coords_dtostr(ll.lon); fprintf ( f, "type=\"waypoint\" latitude=\"%s\" longitude=\"%s\" name=\"%s\"", s_lat, s_lon, name ); g_free ( s_lat ); g_free ( s_lon ); if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) { gchar *s_alt = a_coords_dtostr(wp->altitude); fprintf ( f, " altitude=\"%s\"", s_alt ); g_free(s_alt); } if ( wp->comment ) { gchar *tmp_comment = slashdup(wp->comment); fprintf ( f, " comment=\"%s\"", tmp_comment ); g_free ( tmp_comment ); } if ( wp->image ) { gchar *tmp_image = slashdup(wp->image); fprintf ( f, " image=\"%s\"", tmp_image ); g_free ( tmp_image ); } if ( wp->symbol ) { fprintf ( f, " symbol=\"%s\"", wp->symbol ); } if ( ! wp->visible ) fprintf ( f, " visible=\"n\"" ); fprintf ( f, "\n" ); }
static void gpx_write_trackpoint ( VikTrackpoint *tp, GpxWritingContext *context ) { FILE *f = context->file; static struct LatLon ll; gchar *s_lat,*s_lon, *s_alt, *s_dop; gchar *time_iso8601; vik_coord_to_latlon ( &(tp->coord), &ll ); // No such thing as a rteseg! So make sure we don't put them in if ( context->options && !context->options->is_route && tp->newsegment ) fprintf ( f, " </trkseg>\n <trkseg>\n" ); s_lat = a_coords_dtostr( ll.lat ); s_lon = a_coords_dtostr( ll.lon ); fprintf ( f, " <%spt lat=\"%s\" lon=\"%s\">\n", (context->options && context->options->is_route) ? "rte" : "trk", s_lat, s_lon ); g_free ( s_lat ); s_lat = NULL; g_free ( s_lon ); s_lon = NULL; if (tp->name) { gchar *s_name = entitize(tp->name); fprintf ( f, " <name>%s</name>\n", s_name ); g_free(s_name); } s_alt = NULL; if ( tp->altitude != VIK_DEFAULT_ALTITUDE ) { s_alt = a_coords_dtostr ( tp->altitude ); } else if ( context->options != NULL && context->options->force_ele ) { s_alt = a_coords_dtostr ( 0 ); } if (s_alt != NULL) fprintf ( f, " <ele>%s</ele>\n", s_alt ); g_free ( s_alt ); s_alt = NULL; time_iso8601 = NULL; if ( tp->has_timestamp ) { GTimeVal timestamp; timestamp.tv_sec = tp->timestamp; timestamp.tv_usec = 0; time_iso8601 = g_time_val_to_iso8601 ( ×tamp ); } else if ( context->options != NULL && context->options->force_time ) { GTimeVal current; g_get_current_time ( ¤t ); time_iso8601 = g_time_val_to_iso8601 ( ¤t ); } if ( time_iso8601 != NULL ) fprintf ( f, " <time>%s</time>\n", time_iso8601 ); g_free(time_iso8601); time_iso8601 = NULL; if (!isnan(tp->course)) { gchar *s_course = a_coords_dtostr(tp->course); fprintf ( f, " <course>%s</course>\n", s_course ); g_free(s_course); } if (!isnan(tp->speed)) { gchar *s_speed = a_coords_dtostr(tp->speed); fprintf ( f, " <speed>%s</speed>\n", s_speed ); g_free(s_speed); } if (tp->fix_mode == VIK_GPS_MODE_2D) fprintf ( f, " <fix>2d</fix>\n"); if (tp->fix_mode == VIK_GPS_MODE_3D) fprintf ( f, " <fix>3d</fix>\n"); if (tp->nsats > 0) fprintf ( f, " <sat>%d</sat>\n", tp->nsats ); s_dop = NULL; if ( tp->hdop != VIK_DEFAULT_DOP ) { s_dop = a_coords_dtostr ( tp->hdop ); } if (s_dop != NULL) fprintf ( f, " <hdop>%s</hdop>\n", s_dop ); g_free ( s_dop ); s_dop = NULL; if ( tp->vdop != VIK_DEFAULT_DOP ) { s_dop = a_coords_dtostr ( tp->vdop ); } if (s_dop != NULL) fprintf ( f, " <vdop>%s</vdop>\n", s_dop ); g_free ( s_dop ); s_dop = NULL; if ( tp->pdop != VIK_DEFAULT_DOP ) { s_dop = a_coords_dtostr ( tp->pdop ); } if (s_dop != NULL) fprintf ( f, " <pdop>%s</pdop>\n", s_dop ); g_free ( s_dop ); s_dop = NULL; fprintf ( f, " </%spt>\n", (context->options && context->options->is_route) ? "rte" : "trk" ); }
static void gpx_write_waypoint ( VikWaypoint *wp, GpxWritingContext *context ) { // Don't write invisible waypoints when specified if (context->options && !context->options->hidden && !wp->visible) return; FILE *f = context->file; static struct LatLon ll; gchar *s_lat,*s_lon; gchar *tmp; vik_coord_to_latlon ( &(wp->coord), &ll ); s_lat = a_coords_dtostr( ll.lat ); s_lon = a_coords_dtostr( ll.lon ); // NB 'hidden' is not part of any GPX standard - this appears to be a made up Viking 'extension' // luckily most other GPX processing software ignores things they don't understand fprintf ( f, "<wpt lat=\"%s\" lon=\"%s\"%s>\n", s_lat, s_lon, wp->visible ? "" : " hidden=\"hidden\"" ); g_free ( s_lat ); g_free ( s_lon ); // Sanity clause if ( wp->name ) tmp = entitize ( wp->name ); else tmp = g_strdup ("waypoint"); fprintf ( f, " <name>%s</name>\n", tmp ); g_free ( tmp); if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) { tmp = a_coords_dtostr ( wp->altitude ); fprintf ( f, " <ele>%s</ele>\n", tmp ); g_free ( tmp ); } if ( wp->has_timestamp ) { GTimeVal timestamp; timestamp.tv_sec = wp->timestamp; timestamp.tv_usec = 0; gchar *time_iso8601 = g_time_val_to_iso8601 ( ×tamp ); if ( time_iso8601 != NULL ) fprintf ( f, " <time>%s</time>\n", time_iso8601 ); g_free ( time_iso8601 ); } if ( wp->comment ) { tmp = entitize(wp->comment); fprintf ( f, " <cmt>%s</cmt>\n", tmp ); g_free ( tmp ); } if ( wp->description ) { tmp = entitize(wp->description); fprintf ( f, " <desc>%s</desc>\n", tmp ); g_free ( tmp ); } if ( wp->url ) { tmp = entitize(wp->url); fprintf ( f, " <url>%s</url>\n", tmp ); g_free ( tmp ); } if ( wp->image ) { tmp = entitize(wp->image); fprintf ( f, " <link>%s</link>\n", tmp ); g_free ( tmp ); } if ( wp->symbol ) { tmp = entitize(wp->symbol); if ( a_vik_gpx_export_wpt_sym_name ( ) ) { // Lowercase the symbol name gchar *tmp2 = g_utf8_strdown ( tmp, -1 ); fprintf ( f, " <sym>%s</sym>\n", tmp2 ); g_free ( tmp2 ); } else fprintf ( f, " <sym>%s</sym>\n", tmp); g_free ( tmp ); } fprintf ( f, "</wpt>\n" ); }