2005-11-23 Guilhem BONNEFILLE <guilhem.bonnefille@gmail.com>
-
* src/gpx.c (gpx_dtostr): add better GPX export
+Evan Battaglia <gtoevan@gmx.net>:
+ * dtostr -> coords.c; use in gpsmapper.c and gpspoint.c (locale-independent output)
2005-11-21
Alex Foobarian <foobarian@gmail.com>:
Debugging output shouldn't be printf'd but g_debug'd
fix KH maps download
'zoom in too much' line drawing (ruler, tracks) bugs. maybe fix coord-to-screen to clip values (or make vik_viewport_coord_to_screen_clip)?
+ fix SEGFAULT when clicking too far right on elevation diagram
acquire crashes, sometimes (???)
google maps download stops (try auto-download), extra processes in background doing nothing
renaming functions and defining LatLon and UTM structs.
2004-02-10 -- I also added a function of my own -- a_coords_utm_diff() -- that I felt belonged in coords.c
2004-02-21 -- I also added a_coords_utm_equal().
+2005-11-23 -- Added a_coords_dtostr() for lack of a better place.
+
*/
/* coords.h - include file for coords routines
**
#define M_PI 3.14159265358979
#endif
+/**
+ * Convert a double to a string WITHOUT LOCALE.
+ *
+ * Following GPX specifications, decimal values are xsd:decimal
+ * So, they must use the period separator, not the localized one.
+ *
+ * The returned value must be freed by g_free.
+ */
+char *a_coords_dtostr ( double d )
+{
+ /* In order to ignore locale, we do all the stuff manually */
+ double integer, decimal;
+ integer = trunc(d);
+
+ /* 6 decimals are sufficient (~0,1m) */
+ /* Cf. http://www.tbs-sct.gc.ca/rpm-gbi/guides/Latlong_f.asp */
+ decimal = d - integer;
+ decimal = decimal * 1000000;
+ decimal = trunc ( decimal );
+ decimal = fabs ( decimal );
+
+ /* Format */
+ return g_strdup_printf ( "%g.%06g", integer, decimal );
+}
+
#define PIOVER180 0.01745329252
#define K0 0.9996
double a_coords_utm_diff( const struct UTM *utm1, const struct UTM *utm2 );
double a_coords_latlon_diff ( const struct LatLon *ll1, const struct LatLon *ll2 );
+/**
+ * Convert a double to a string WITHOUT LOCALE.
+ *
+ * Following GPX specifications, decimal values are xsd:decimal
+ * So, they must use the period separator, not the localized one.
+ *
+ * The returned value must be freed by g_free.
+ */
+char *a_coords_dtostr ( double d );
+
+
#endif
guint len = print_rgn_stuff ( wp->comment, f );
if ( len )
{
+ gchar *s_lat, *s_lon;
vik_coord_to_latlon ( &(wp->coord), &ll );
- fprintf ( f, "Data0=(%f,%f)\n", ll.lat, ll.lon );
+ s_lat = a_coords_dtostr(ll.lat);
+ s_lon = a_coords_dtostr(ll.lon);
+ fprintf ( f, "Data0=(%s,%s)\n", s_lat, s_lon );
+ g_free ( s_lat );
+ g_free ( s_lon );
fprintf ( f, "[END-%.5s]\n\n", wp->comment+len+1 );
}
}
static void write_trackpoint ( VikTrackpoint *tp, FILE *f )
{
static struct LatLon ll;
- vik_coord_to_latlon ( &(tp->coord), &ll );
-
- fprintf ( f, "(%f,%f),", ll.lat, ll.lon );
+ gchar *s_lat, *s_lon;
+ vik_coord_to_latlon ( &(tp->coord), &ll );
+ s_lat = a_coords_dtostr(ll.lat);
+ s_lon = a_coords_dtostr(ll.lon);
+ fprintf ( f, "(%s,%s),", s_lat, s_lon );
+ g_free ( s_lat );
+ g_free ( s_lon );
}
static void write_track ( const gchar *name, VikTrack *t, FILE *f )
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 );
- fprintf ( f, "type=\"waypoint\" latitude=\"%f\" longitude=\"%f\" name=\"%s\"", ll.lat, ll.lon, name );
- if ( wp->altitude != VIK_DEFAULT_ALTITUDE )
- fprintf ( f, " altitude=\"%f\"", wp->altitude );
+ 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);
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 );
- fprintf ( f, "type=\"trackpoint\" latitude=\"%f\" longitude=\"%f\"", ll.lat, ll.lon );
+ 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 )
- fprintf ( f, " altitude=\"%f\"", tp->altitude );
+ 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 )
/* export GPX */
-/**
- * Convert a double to a string WITHOUT LOCALE.
- *
- * Following GPX specifications, decimal values are xsd:decimal
- * So, they must use the period separator, not the localized one.
- *
- * The returned value must be freed by g_free.
- */
-static gchar *gpx_dtostr ( double d )
-{
- /* In order to ignore locale, we do all the stuff manually */
- double integer, decimal;
- integer = trunc(d);
-
- /* 6 decimals are sufficient (~0,1m) */
- /* Cf. http://www.tbs-sct.gc.ca/rpm-gbi/guides/Latlong_f.asp */
- decimal = d - integer;
- decimal = decimal * 1000000;
- decimal = trunc ( decimal );
- decimal = fabs ( decimal );
-
- /* Format */
- return g_strdup_printf ( "%g.%06g", integer, decimal );
-}
-
static void gpx_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f )
{
static struct LatLon ll;
gchar *s_lat,*s_lon;
gchar *tmp;
vik_coord_to_latlon ( &(wp->coord), &ll );
- s_lat = gpx_dtostr( ll.lat );
- s_lon = gpx_dtostr( ll.lon );
+ 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 );
if ( wp->altitude != VIK_DEFAULT_ALTITUDE )
{
- tmp = gpx_dtostr ( wp->altitude );
+ tmp = a_coords_dtostr ( wp->altitude );
fprintf ( f, " <ele>%s</ele>\n", tmp );
g_free ( tmp );
}
if ( tp->newsegment )
fprintf ( f, " </trkseg>\n <trkseg>\n" );
- s_lat = gpx_dtostr( ll.lat );
- s_lon = gpx_dtostr( ll.lon );
+ s_lat = a_coords_dtostr( ll.lat );
+ s_lon = a_coords_dtostr( ll.lon );
fprintf ( f, " <trkpt lat=\"%s\" lon=\"%s\">\n", s_lat, s_lon );
g_free ( s_lat );
g_free ( s_lon );
if ( tp->altitude != VIK_DEFAULT_ALTITUDE )
{
- s_alt = gpx_dtostr ( tp->altitude );
+ s_alt = a_coords_dtostr ( tp->altitude );
fprintf ( f, " <ele>%s</ele>\n", s_alt );
g_free ( s_alt );
}