LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/gpx - ogr_gpx.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 11 11 100.0 %
Date: 2012-12-26 Functions: 10 10 100.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_gpx.h 25311 2012-12-15 12:48:14Z rouault $
       3                 :  *
       4                 :  * Project:  GPX Translator
       5                 :  * Purpose:  Definition of classes for OGR .gpx driver.
       6                 :  * Author:   Even Rouault, even dot rouault at mines dash paris dot org
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2007, Even Rouault
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #ifndef _OGR_GPX_H_INCLUDED
      31                 : #define _OGR_GPX_H_INCLUDED
      32                 : 
      33                 : #include "ogrsf_frmts.h"
      34                 : 
      35                 : #ifdef HAVE_EXPAT
      36                 : #include "ogr_expat.h"
      37                 : #endif
      38                 : 
      39                 : class OGRGPXDataSource;
      40                 : 
      41                 : 
      42                 : typedef enum
      43                 : {
      44                 :     GPX_NONE,
      45                 :     GPX_WPT,
      46                 :     GPX_TRACK,
      47                 :     GPX_ROUTE,
      48                 :     GPX_ROUTE_POINT,
      49                 :     GPX_TRACK_POINT,
      50                 : } GPXGeometryType;
      51                 : 
      52                 : /************************************************************************/
      53                 : /*                             OGRGPXLayer                              */
      54                 : /************************************************************************/
      55                 : 
      56                 : class OGRGPXLayer : public OGRLayer
      57                 : {
      58                 :     OGRFeatureDefn*    poFeatureDefn;
      59                 :     OGRSpatialReference *poSRS;
      60                 :     OGRGPXDataSource*  poDS;
      61                 :     
      62                 :     GPXGeometryType    gpxGeomType;
      63                 : 
      64                 :     int                nGPXFields;
      65                 : 
      66                 :     int                bWriteMode;
      67                 :     int                nFeatures;
      68                 :     int                eof;
      69                 :     int                nNextFID;
      70                 :     VSILFILE*          fpGPX; /* Large file API */
      71                 :     const char*        pszElementToScan;
      72                 : #ifdef HAVE_EXPAT
      73                 :     XML_Parser         oParser;
      74                 :     XML_Parser         oSchemaParser;
      75                 : #endif
      76                 :     int                inInterestingElement;
      77                 :     int                hasFoundLat;
      78                 :     int                hasFoundLon;
      79                 :     double             latVal;
      80                 :     double             lonVal;
      81                 :     char*              pszSubElementName;
      82                 :     char*              pszSubElementValue;
      83                 :     int                nSubElementValueLen;
      84                 :     int                iCurrentField;
      85                 : 
      86                 :     OGRFeature*        poFeature;
      87                 :     OGRFeature **      ppoFeatureTab;
      88                 :     int                nFeatureTabLength;
      89                 :     int                nFeatureTabIndex;
      90                 :     
      91                 :     OGRMultiLineString* multiLineString;
      92                 :     OGRLineString*      lineString;
      93                 :     
      94                 :     int                depthLevel;
      95                 :     int                interestingDepthLevel;
      96                 :     
      97                 :     OGRFieldDefn*      currentFieldDefn;
      98                 :     int                inExtensions;
      99                 :     int                extensionsDepthLevel;
     100                 :     
     101                 :     int                inLink;
     102                 :     int                iCountLink;
     103                 :     int                nMaxLinks;
     104                 :     
     105                 :     int                bEleAs25D;
     106                 :     
     107                 :     int                trkFID;
     108                 :     int                trkSegId;
     109                 :     int                trkSegPtId;
     110                 :     
     111                 :     int                rteFID;
     112                 :     int                rtePtId;
     113                 :     
     114                 :     int                bStopParsing;
     115                 :     int                nWithoutEventCounter;
     116                 :     int                nDataHandlerCounter;
     117                 :     
     118                 :     int                iFirstGPXField;
     119                 :     
     120                 :   private:
     121                 :     void               WriteFeatureAttributes( OGRFeature *poFeature, int nIdentLevel = 1 );
     122                 :     void               LoadExtensionsSchema();
     123                 : #ifdef HAVE_EXPAT
     124                 :     void               AddStrToSubElementValue(const char* pszStr);
     125                 : #endif
     126                 :     int                OGRGPX_WriteXMLExtension(const char* pszTagName,
     127                 :                                                 const char* pszContent);
     128                 : 
     129                 :   public:
     130                 :                         OGRGPXLayer(const char *pszFilename,
     131                 :                                     const char* layerName,
     132                 :                                     GPXGeometryType gpxGeomType,
     133                 :                                     OGRGPXDataSource* poDS,
     134                 :                                     int bWriteMode = FALSE);
     135                 :                         ~OGRGPXLayer();
     136                 : 
     137                 :     void                ResetReading();
     138                 :     OGRFeature *        GetNextFeature();
     139                 :     
     140                 :     OGRErr              CreateFeature( OGRFeature *poFeature );
     141                 :     OGRErr              CreateField( OGRFieldDefn *poField, int bApproxOK );
     142                 : 
     143              94 :     OGRFeatureDefn *    GetLayerDefn() { return poFeatureDefn; }
     144                 :     
     145                 :     int                 TestCapability( const char * );
     146                 :     
     147                 :     OGRSpatialReference *GetSpatialRef();
     148                 :     
     149                 : #ifdef HAVE_EXPAT
     150                 :     void                startElementCbk(const char *pszName, const char **ppszAttr);
     151                 :     void                endElementCbk(const char *pszName);
     152                 :     void                dataHandlerCbk(const char *data, int nLen);
     153                 :     
     154                 :     void                startElementLoadSchemaCbk(const char *pszName, const char **ppszAttr);
     155                 :     void                endElementLoadSchemaCbk(const char *pszName);
     156                 :     void                dataHandlerLoadSchemaCbk(const char *data, int nLen);
     157                 : #endif
     158                 : 
     159                 :     static OGRErr       CheckAndFixCoordinatesValidity( double* pdfLatitude, double* pdfLongitude );
     160                 : };
     161                 : 
     162                 : /************************************************************************/
     163                 : /*                           OGRGPXDataSource                           */
     164                 : /************************************************************************/
     165                 : 
     166                 : typedef enum
     167                 : {
     168                 :     GPX_VALIDITY_UNKNOWN,
     169                 :     GPX_VALIDITY_INVALID,
     170                 :     GPX_VALIDITY_VALID
     171                 : } OGRGPXValidity;
     172                 : 
     173                 : class OGRGPXDataSource : public OGRDataSource
     174                 : {
     175                 :     char*               pszName;
     176                 : 
     177                 :     OGRGPXLayer**       papoLayers;
     178                 :     int                 nLayers;
     179                 : 
     180                 :     /*  Export related */
     181                 :     VSILFILE           *fpOutput; /* Large file API */
     182                 :     int                 bIsBackSeekable;
     183                 :     const char         *pszEOL;
     184                 :     int                 nOffsetBounds;
     185                 :     double              dfMinLat, dfMinLon, dfMaxLat, dfMaxLon;
     186                 :     
     187                 :     GPXGeometryType     lastGPXGeomTypeWritten;
     188                 :     
     189                 :     int                 bUseExtensions;
     190                 :     char*               pszExtensionsNS;
     191                 :     
     192                 :     OGRGPXValidity      validity;
     193                 :     int                 nElementsRead;
     194                 :     char*               pszVersion;
     195                 : #ifdef HAVE_EXPAT
     196                 :     XML_Parser          oCurrentParser;
     197                 :     int                 nDataHandlerCounter;
     198                 : #endif
     199                 : 
     200                 :   public:
     201                 :                         OGRGPXDataSource();
     202                 :                         ~OGRGPXDataSource();
     203                 : 
     204                 :     int                nLastRteId;
     205                 :     int                nLastTrkId;
     206                 :     int                nLastTrkSegId;
     207                 : 
     208                 :     int                 Open( const char * pszFilename,
     209                 :                               int bUpdate );
     210                 :     
     211                 :     int                 Create( const char *pszFilename, 
     212                 :                               char **papszOptions );
     213                 :     
     214               7 :     const char*         GetName() { return pszName; }
     215                 : 
     216              59 :     int                 GetLayerCount() { return nLayers; }
     217                 :     OGRLayer*           GetLayer( int );
     218                 :     
     219                 :     OGRLayer *          CreateLayer( const char * pszLayerName,
     220                 :                                     OGRSpatialReference *poSRS,
     221                 :                                     OGRwkbGeometryType eType,
     222                 :                                     char ** papszOptions );
     223                 : 
     224                 :     int                 TestCapability( const char * );
     225                 :     
     226              36 :     VSILFILE *              GetOutputFP() { return fpOutput; }
     227              18 :     void                SetLastGPXGeomTypeWritten(GPXGeometryType gpxGeomType)
     228              18 :                             { lastGPXGeomTypeWritten = gpxGeomType; }
     229              33 :     GPXGeometryType     GetLastGPXGeomTypeWritten() { return lastGPXGeomTypeWritten; }
     230                 :     
     231              50 :     int                 GetUseExtensions() { return bUseExtensions; }
     232               2 :     const char*         GetExtensionsNS() { return pszExtensionsNS; }
     233                 :     
     234                 : #ifdef HAVE_EXPAT
     235                 :     void                startElementValidateCbk(const char *pszName, const char **ppszAttr);
     236                 :     void                dataHandlerValidateCbk(const char *data, int nLen);
     237                 : #endif
     238                 : 
     239              37 :     const char*         GetVersion() { return pszVersion; }
     240                 :     
     241                 :     void                AddCoord(double dfLon, double dfLat);
     242                 :     
     243                 :     void                PrintLine(const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (2, 3);
     244                 : };
     245                 : 
     246                 : /************************************************************************/
     247                 : /*                             OGRGPXDriver                             */
     248                 : /************************************************************************/
     249                 : 
     250                 : class OGRGPXDriver : public OGRSFDriver
     251             226 : {
     252                 :   public:
     253                 :                 ~OGRGPXDriver();
     254                 : 
     255                 :     const char*         GetName();
     256                 :     OGRDataSource*      Open( const char *, int );
     257                 :     OGRDataSource*      CreateDataSource( const char * pszName, char **papszOptions );
     258                 :     int                 DeleteDataSource( const char *pszFilename );
     259                 :     int                 TestCapability( const char * );
     260                 :     
     261                 : };
     262                 : 
     263                 : 
     264                 : #endif /* ndef _OGR_GPX_H_INCLUDED */

Generated by: LCOV version 1.7