On Tue, Oct 13, 2009 at 4:41 PM, Egil Hjelmeland <privat@egil-hjelmeland.no> wrote:
Hi.

I patched my gpsbabel 1.3.6 to handle altitude for OSM files:

For writing OSM file: If you specify "-o osm,ele", altitudes are written
to OSM as  " <tag k='ele' v='%.1f'/>".


Is there really any reason for this to be optional?  If we know the elevation, why not just always include it?

Oh, and xasprintf/free are preferred over staticly buffers.   Yes, in this specific case it's a bit dorky since you're not going to get 100 digits of fp....  

RJL


 
When reading OSM, "<tag k='ele' v='%f'/>" is read as altitude,
unconditonally.

I think it will be useful to merge into the gpsbabel sourcetree.

Best regards
Egil Hjelmeland.


--- osm.c.orig    2009-10-06 22:32:02.265000000 +0200
+++ osm.c    2009-10-13 00:48:38.804800000 +0200
@@ -25,12 +25,14 @@
 #include "xmlgeneric.h"

 static char *opt_tag, *opt_tagnd, *created_by;
+static char *opt_ele = NULL;

 static arglist_t osm_args[] =
 {
    { "tag", &opt_tag,     "Write additional way tag key/value pairs",
NULL, ARGTYPE_STRING, ARG_NOMINMAX },
    { "tagnd", &opt_tagnd,    "Write additional node tag key/value
pairs", NULL, ARGTYPE_STRING, ARG_NOMINMAX },
    { "created_by", &created_by, "Use this value as custom created_by
value","GPSBabel", ARGTYPE_STRING, ARG_NOMINMAX },
+     { "ele", &opt_ele,  "Include elevation tag for OSM nodes", "0",
ARGTYPE_BOOL, ARG_NOMINMAX },
    ARG_TERMINATOR
 };

@@ -551,6 +553,10 @@
        if (! wpt->shortname)
            wpt->shortname = xstrdup(str);
    }
+    if (strcmp(key, "ele") == 0) {
+        if ( wpt->altitude == unknown_alt)
+            wpt->altitude = atof(str);
+    }
    else if (strcmp(key, "name:en") == 0) {
        if (wpt->shortname)
            xfree(wpt->shortname);
@@ -835,6 +841,12 @@
                break;
        }

+       if ((*opt_ele != '0') &&(wpt->altitude != unknown_alt) ) {
+         char ele[100];
+           sprintf(ele, "%.1f", wpt->altitude);
+           osm_write_tag("ele", ele);
+       }
+
        if (strlen(created_by) !=0) {
            gbfprintf(fout, "    <tag k='created_by' v='%s",created_by);
            if (gpsbabel_time != 0)





------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Gpsbabel-code mailing list  http://www.gpsbabel.org
Gpsbabel-code@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gpsbabel-code