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: 2010-01-09 Functions: 10 10 100.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_gpx.h 17549 2009-08-21 11:16:41Z 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                 :     FILE*              fpGPX; /* Large file API */
      71                 :     const char*        pszElementToScan;
      72                 : #ifdef HAVE_EXPAT
      73                 :     XML_Parser         oParser;
      74                 :     XML_Parser         oSchemaParser;
      75                 : #endif
      76                 :     int                doParse;
      77                 :     int                inInterestingElement;
      78                 :     int                hasFoundLat;
      79                 :     int                hasFoundLon;
      80                 :     double             latVal;
      81                 :     double             lonVal;
      82                 :     char*              pszSubElementName;
      83                 :     char*              pszSubElementValue;
      84                 :     int                nSubElementValueLen;
      85                 :     int                iCurrentField;
      86                 : 
      87                 :     OGRFeature*        poFeature;
      88                 :     OGRFeature **      ppoFeatureTab;
      89                 :     int                nFeatureTabLength;
      90                 :     int                nFeatureTabIndex;
      91                 :     
      92                 :     OGRMultiLineString* multiLineString;
      93                 :     OGRLineString*      lineString;
      94                 :     
      95                 :     int                depthLevel;
      96                 :     int                interestingDepthLevel;
      97                 :     
      98                 :     OGRFieldDefn*      currentFieldDefn;
      99                 :     int                inExtensions;
     100                 :     int                extensionsDepthLevel;
     101                 :     
     102                 :     int                inLink;
     103                 :     int                iCountLink;
     104                 :     int                nMaxLinks;
     105                 :     
     106                 :     int                bEleAs25D;
     107                 :     
     108                 :     int                trkFID;
     109                 :     int                trkSegId;
     110                 :     int                trkSegPtId;
     111                 :     
     112                 :     int                rteFID;
     113                 :     int                rtePtId;
     114                 :     
     115                 :     int                bStopParsing;
     116                 :     int                nWithoutEventCounter;
     117                 :     int                nDataHandlerCounter;
     118                 :     
     119                 :   private:
     120                 :     void               WriteFeatureAttributes( OGRFeature *poFeature );
     121                 :     void               LoadExtensionsSchema();
     122                 : #ifdef HAVE_EXPAT
     123                 :     void               AddStrToSubElementValue(const char* pszStr);
     124                 : #endif
     125                 : 
     126                 :   public:
     127                 :                         OGRGPXLayer(const char *pszFilename,
     128                 :                                     const char* layerName,
     129                 :                                     GPXGeometryType gpxGeomType,
     130                 :                                     OGRGPXDataSource* poDS,
     131                 :                                     int bWriteMode = FALSE);
     132                 :                         ~OGRGPXLayer();
     133                 : 
     134                 :     void                ResetReading();
     135                 :     OGRFeature *        GetNextFeature();
     136                 :     
     137                 :     OGRErr              CreateFeature( OGRFeature *poFeature );
     138                 :     OGRErr              CreateField( OGRFieldDefn *poField, int bApproxOK );
     139                 : 
     140              55 :     OGRFeatureDefn *    GetLayerDefn() { return poFeatureDefn; }
     141                 :     
     142                 :     int                 TestCapability( const char * );
     143                 :     
     144                 :     OGRSpatialReference *GetSpatialRef();
     145                 :     
     146                 : #ifdef HAVE_EXPAT
     147                 :     void                startElementCbk(const char *pszName, const char **ppszAttr);
     148                 :     void                endElementCbk(const char *pszName);
     149                 :     void                dataHandlerCbk(const char *data, int nLen);
     150                 :     
     151                 :     void                startElementLoadSchemaCbk(const char *pszName, const char **ppszAttr);
     152                 :     void                endElementLoadSchemaCbk(const char *pszName);
     153                 :     void                dataHandlerLoadSchemaCbk(const char *data, int nLen);
     154                 : #endif
     155                 : 
     156                 :     static OGRErr       CheckAndFixCoordinatesValidity( double* pdfLatitude, double* pdfLongitude );
     157                 : };
     158                 : 
     159                 : /************************************************************************/
     160                 : /*                           OGRGPXDataSource                           */
     161                 : /************************************************************************/
     162                 : 
     163                 : typedef enum
     164                 : {
     165                 :     GPX_VALIDITY_UNKNOWN,
     166                 :     GPX_VALIDITY_INVALID,
     167                 :     GPX_VALIDITY_VALID
     168                 : } OGRGPXValidity;
     169                 : 
     170                 : class OGRGPXDataSource : public OGRDataSource
     171                 : {
     172                 :     char*               pszName;
     173                 : 
     174                 :     OGRGPXLayer**       papoLayers;
     175                 :     int                 nLayers;
     176                 : 
     177                 :     /*  Export related */
     178                 :     FILE                *fpOutput; /* Standard file API */
     179                 :     int                 nOffsetBounds;
     180                 :     double              dfMinLat, dfMinLon, dfMaxLat, dfMaxLon;
     181                 :     
     182                 :     GPXGeometryType     lastGPXGeomTypeWritten;
     183                 :     
     184                 :     int                 bUseExtensions;
     185                 :     char*               pszExtensionsNS;
     186                 :     
     187                 :     OGRGPXValidity      validity;
     188                 :     int                 nElementsRead;
     189                 :     char*               pszVersion;
     190                 : #ifdef HAVE_EXPAT
     191                 :     XML_Parser          oCurrentParser;
     192                 :     int                 nDataHandlerCounter;
     193                 : #endif
     194                 : 
     195                 :   public:
     196                 :                         OGRGPXDataSource();
     197                 :                         ~OGRGPXDataSource();
     198                 : 
     199                 :     int                 Open( const char * pszFilename,
     200                 :                               int bUpdate );
     201                 :     
     202                 :     int                 Create( const char *pszFilename, 
     203                 :                               char **papszOptions );
     204                 :     
     205               5 :     const char*         GetName() { return pszName; }
     206                 : 
     207              29 :     int                 GetLayerCount() { return nLayers; }
     208                 :     OGRLayer*           GetLayer( int );
     209                 :     
     210                 :     OGRLayer *          CreateLayer( const char * pszLayerName,
     211                 :                                     OGRSpatialReference *poSRS,
     212                 :                                     OGRwkbGeometryType eType,
     213                 :                                     char ** papszOptions );
     214                 : 
     215                 :     int                 TestCapability( const char * );
     216                 :     
     217              18 :     FILE *              GetOutputFP() { return fpOutput; }
     218               9 :     void                SetLastGPXGeomTypeWritten(GPXGeometryType gpxGeomType)
     219               9 :                             { lastGPXGeomTypeWritten = gpxGeomType; }
     220              10 :     GPXGeometryType     GetLastGPXGeomTypeWritten() { return lastGPXGeomTypeWritten; }
     221                 :     
     222              35 :     int                 GetUseExtensions() { return bUseExtensions; }
     223               2 :     const char*         GetExtensionsNS() { return pszExtensionsNS; }
     224                 :     
     225                 : #ifdef HAVE_EXPAT
     226                 :     void                startElementValidateCbk(const char *pszName, const char **ppszAttr);
     227                 :     void                dataHandlerValidateCbk(const char *data, int nLen);
     228                 : #endif
     229                 : 
     230              19 :     const char*         GetVersion() { return pszVersion; }
     231                 :     
     232                 :     void                AddCoord(double dfLon, double dfLat);
     233                 : };
     234                 : 
     235                 : /************************************************************************/
     236                 : /*                             OGRGPXDriver                             */
     237                 : /************************************************************************/
     238                 : 
     239                 : class OGRGPXDriver : public OGRSFDriver
     240              64 : {
     241                 :   public:
     242                 :                 ~OGRGPXDriver();
     243                 : 
     244                 :     const char*         GetName();
     245                 :     OGRDataSource*      Open( const char *, int );
     246                 :     OGRDataSource*      CreateDataSource( const char * pszName, char **papszOptions );
     247                 :     int                 DeleteDataSource( const char *pszFilename );
     248                 :     int                 TestCapability( const char * );
     249                 :     
     250                 : };
     251                 : 
     252                 : 
     253                 : #endif /* ndef _OGR_GPX_H_INCLUDED */

Generated by: LCOV version 1.7