Changeset 13469

Show
Ignore:
Timestamp:
12/31/07 12:35:58 (6 months ago)
Author:
rouault
Message:

Add support for GPX 1.0 reading

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/ogr/ogrsf_frmts/gpx/drv_gpx.html

    r13176 r13469  
    1111 
    1212OGR has support for GPX reading (if GDAL is build with <i>expat</i> library support) and writing.<p> 
     13 
     14Version supported are GPX 1.0 and 1.1 for reading, GPX 1.1 for writing.<p> 
    1315 
    1416The OGR driver supports reading and writing of all the GPX feature types : 
  • trunk/gdal/ogr/ogrsf_frmts/gpx/ogr_gpx.h

    r13357 r13469  
    176176    OGRGPXValidity      validity; 
    177177    int                 nElementsRead; 
     178    char*               pszVersion; 
    178179     
    179180  public: 
     
    208209     
    209210    void                startElementValidateCbk(const char *pszName, const char **ppszAttr); 
     211     
     212    const char*         GetVersion() { return pszVersion; } 
    210213}; 
    211214 
  • trunk/gdal/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp

    r13239 r13469  
    5050 
    5151    pszName = NULL; 
     52    pszVersion = NULL; 
    5253} 
    5354 
     
    7172    CPLFree( pszExtensionsNS ); 
    7273    CPLFree( pszName ); 
     74    CPLFree( pszVersion ); 
    7375} 
    7476 
     
    162164        if (strcmp(pszName, "gpx") == 0) 
    163165        { 
     166            int i; 
    164167            validity = GPX_VALIDITY_VALID; 
     168            for(i=0; ppszAttr[i] != NULL; i+= 2) 
     169            { 
     170                if (strcmp(ppszAttr[i], "version") == 0) 
     171                { 
     172                    pszVersion = CPLStrdup(ppszAttr[i+1]); 
     173                    break; 
     174                } 
     175            } 
    165176        } 
    166177        else 
     
    219230     
    220231    validity = GPX_VALIDITY_UNKNOWN; 
     232    CPLFree(pszVersion); 
     233    pszVersion = NULL; 
    221234    bUseExtensions = FALSE; 
    222235    nElementsRead = 0; 
     
    287300        if (bUseExtensions) 
    288301            CPLDebug("GPX", "It uses <extensions>"); 
     302 
     303        if (pszVersion == NULL) 
     304        { 
     305            /* Default to 1.1 */ 
     306            CPLError(CE_Warning, CPLE_AppDefined, "GPX schema version is unknown. " 
     307                     "The driver may not be able to handle the file correctly and will behave as if it is GPX 1.1."); 
     308            pszVersion = CPLStrdup("1.1"); 
     309        } 
     310        else if (strcmp(pszVersion, "1.0") == 0 || strcmp(pszVersion, "1.1") == 0) 
     311        { 
     312            /* Fine */ 
     313        } 
     314        else 
     315        { 
     316            CPLError(CE_Warning, CPLE_AppDefined, 
     317                     "GPX schema version '%s' is not handled by the driver. " 
     318                     "The driver may not be able to handle the file correctly and will behave as if it is GPX 1.1.", pszVersion); 
     319        } 
     320 
    289321        nLayers = 5; 
    290322        papoLayers = (OGRGPXLayer **) CPLRealloc(papoLayers, nLayers * sizeof(OGRGPXLayer*)); 
  • trunk/gdal/ogr/ogrsf_frmts/gpx/ogrgpxlayer.cpp

    r13463 r13469  
    4646 
    4747{ 
     48    const char* gpxVersion = poDS->GetVersion(); 
     49 
    4850    int i; 
    4951 
     
    106108        poFeatureDefn->AddFieldDefn( &oFieldTime ); 
    107109         
     110        if (gpxGeomType == GPX_TRACK_POINT && 
     111            gpxVersion && strcmp(gpxVersion, "1.0") == 0) 
     112        { 
     113            OGRFieldDefn oFieldCourse("course", OFTReal ); 
     114            poFeatureDefn->AddFieldDefn( &oFieldCourse ); 
     115             
     116            OGRFieldDefn oFieldSpeed("speed", OFTReal ); 
     117            poFeatureDefn->AddFieldDefn( &oFieldSpeed ); 
     118        } 
     119         
    108120        OGRFieldDefn oFieldMagVar("magvar", OFTReal ); 
    109121        poFeatureDefn->AddFieldDefn( &oFieldMagVar ); 
     
    126138        poFeatureDefn->AddFieldDefn( &oFieldSrc ); 
    127139         
    128         for(i=1;i<=nMaxLinks;i++) 
    129         { 
    130             char szFieldName[32]; 
    131             sprintf(szFieldName, "link%d_href", i); 
    132             OGRFieldDefn oFieldLinkHref( szFieldName, OFTString ); 
    133             poFeatureDefn->AddFieldDefn( &oFieldLinkHref ); 
     140        if (gpxVersion && strcmp(gpxVersion, "1.0") == 0) 
     141        { 
     142            OGRFieldDefn oFieldUrl("url", OFTString ); 
     143            poFeatureDefn->AddFieldDefn( &oFieldUrl ); 
    134144             
    135             sprintf(szFieldName, "link%d_text", i); 
    136             OGRFieldDefn oFieldLinkText( szFieldName, OFTString ); 
    137             poFeatureDefn->AddFieldDefn( &oFieldLinkText ); 
    138              
    139             sprintf(szFieldName, "link%d_type", i); 
    140             OGRFieldDefn oFieldLinkType( szFieldName, OFTString ); 
    141             poFeatureDefn->AddFieldDefn( &oFieldLinkType ); 
     145            OGRFieldDefn oFieldUrlName("urlname", OFTString ); 
     146            poFeatureDefn->AddFieldDefn( &oFieldUrlName ); 
     147        } 
     148        else 
     149        { 
     150            for(i=1;i<=nMaxLinks;i++) 
     151            { 
     152                char szFieldName[32]; 
     153                sprintf(szFieldName, "link%d_href", i); 
     154                OGRFieldDefn oFieldLinkHref( szFieldName, OFTString ); 
     155                poFeatureDefn->AddFieldDefn( &oFieldLinkHref ); 
     156                 
     157                sprintf(szFieldName, "link%d_text", i); 
     158                OGRFieldDefn oFieldLinkText( szFieldName, OFTString ); 
     159                poFeatureDefn->AddFieldDefn( &oFieldLinkText ); 
     160                 
     161                sprintf(szFieldName, "link%d_type", i); 
     162                OGRFieldDefn oFieldLinkType( szFieldName, OFTString ); 
     163                poFeatureDefn->AddFieldDefn( &oFieldLinkType ); 
     164            } 
    142165        } 
    143166