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

       1                 : /******************************************************************************
       2                 : * $Id: ogr_fgdb.h 25025 2012-10-01 21:06:59Z rouault $
       3                 : *
       4                 : * Project:  OpenGIS Simple Features Reference Implementation
       5                 : * Purpose:  Standard includes and class definitions ArcObjects OGR driver.
       6                 : * Author:   Ragi Yaser Burhum, ragi@burhum.com
       7                 : *
       8                 : ******************************************************************************
       9                 : * Copyright (c) 2009, Ragi Yaser Burhum
      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_FGDB_H_INCLUDED
      31                 : #define _OGR_FGDB_H_INCLUDED
      32                 : 
      33                 : #include <vector>
      34                 : #include "ogrsf_frmts.h"
      35                 : 
      36                 : /* GDAL string utilities */
      37                 : #include "cpl_string.h"
      38                 : 
      39                 : /* GDAL XML handler */
      40                 : #include "cpl_minixml.h"
      41                 : 
      42                 : /* FGDB API headers */
      43                 : #include "FileGDBAPI.h"
      44                 : 
      45                 : /* Workaround needed for Linux, at least for FileGDB API 1.1 (#4455) */
      46                 : #if defined(__linux__)
      47                 : #define EXTENT_WORKAROUND
      48                 : #endif
      49                 : 
      50                 : /************************************************************************
      51                 : * Default layer creation options
      52                 : */
      53                 : 
      54                 : #define FGDB_FEATURE_DATASET "";
      55                 : #define FGDB_GEOMETRY_NAME "SHAPE"
      56                 : #define FGDB_OID_NAME "OBJECTID"
      57                 : 
      58                 : 
      59                 : /* The ESRI FGDB API namespace */
      60                 : using namespace FileGDBAPI;
      61                 : 
      62                 : /************************************************************************/
      63                 : /*                           FGdbBaseLayer                              */
      64                 : /************************************************************************/
      65                 : 
      66                 : class FGdbBaseLayer : public OGRLayer
      67                 : {
      68                 : protected:
      69                 : 
      70                 :   FGdbBaseLayer();
      71                 :   virtual ~FGdbBaseLayer();
      72                 : 
      73                 :   OGRFeatureDefn* m_pFeatureDefn;
      74                 :   OGRSpatialReference* m_pSRS;
      75                 : 
      76                 :   EnumRows*    m_pEnumRows;
      77                 : 
      78                 :   std::vector<std::wstring> m_vOGRFieldToESRIField; //OGR Field Index to ESRI Field Name Mapping
      79                 :   std::vector<std::string> m_vOGRFieldToESRIFieldType; //OGR Field Index to ESRI Field Type Mapping
      80                 : 
      81                 :   bool  m_supressColumnMappingError;
      82                 :   bool  m_forceMulti;
      83                 : 
      84                 :   bool OGRFeatureFromGdbRow(Row* pRow, OGRFeature** ppFeature);
      85                 : 
      86                 : public:
      87                 :           virtual OGRFeature* GetNextFeature();
      88                 : };
      89                 : 
      90                 : /************************************************************************/
      91                 : /*                            FGdbLayer                                 */
      92                 : /************************************************************************/
      93                 : 
      94                 : class FGdbDataSource;
      95                 : 
      96                 : class FGdbLayer : public FGdbBaseLayer
      97                 : {
      98                 :   int                 m_bBulkLoadAllowed;
      99                 :   int                 m_bBulkLoadInProgress;
     100                 : 
     101                 :   void                StartBulkLoad();
     102                 :   void                EndBulkLoad();
     103                 : 
     104                 : #ifdef EXTENT_WORKAROUND
     105                 :   bool                m_bLayerJustCreated;
     106                 :   OGREnvelope         sLayerEnvelope;
     107                 :   bool                m_bLayerEnvelopeValid;
     108                 :   void                WorkAroundExtentProblem();
     109                 :   bool                UpdateRowWithGeometry(Row& row, OGRGeometry* poGeom);
     110                 : #endif
     111                 : 
     112                 :   OGRErr              PopulateRowWithFeature( Row& row, OGRFeature *poFeature );
     113                 :   OGRErr              GetRow( EnumRows& enumRows, Row& row, long nFID );
     114                 : 
     115                 :   char*               CreateFieldDefn(OGRFieldDefn& oField,
     116                 :                                       int bApproxOK,
     117                 :                                       std::string& fieldname_clean,
     118                 :                                       std::string& gdbFieldType);
     119                 : 
     120                 : public:
     121                 : 
     122                 :   FGdbLayer();
     123                 :   virtual ~FGdbLayer();
     124                 : 
     125                 :   // Internal used by FGDB driver */
     126                 :   bool Initialize(FGdbDataSource* pParentDataSource, Table* pTable, std::wstring wstrTablePath, std::wstring wstrType);
     127                 :   bool Create(FGdbDataSource* pParentDataSource, const char * pszLayerName, OGRSpatialReference *poSRS, OGRwkbGeometryType eType, char ** papszOptions);
     128                 :   bool CreateFeatureDataset(FGdbDataSource* pParentDataSource, std::string feature_dataset_name, OGRSpatialReference* poSRS, char** papszOptions );
     129                 : 
     130                 :   // virtual const char *GetName();
     131              73 :   virtual const char* GetFIDColumn() { return m_strOIDFieldName.c_str(); }
     132               0 :   virtual const char* GetGeometryColumn() { return m_strShapeFieldName.c_str(); }
     133                 : 
     134                 :   virtual void        ResetReading();
     135                 :   virtual OGRFeature* GetNextFeature();
     136                 :   virtual OGRFeature* GetFeature( long nFeatureId );
     137                 : 
     138               2 :   Table* GetTable() { return m_pTable; }
     139                 : 
     140               2 :   std::wstring GetTablePath() const { return m_wstrTablePath; }
     141               2 :   std::wstring GetType() const { return m_wstrType; }
     142                 : 
     143                 :   virtual OGRErr      CreateField( OGRFieldDefn *poField, int bApproxOK );
     144                 :   virtual OGRErr      DeleteField( int iFieldToDelete );
     145                 : #ifdef AlterFieldDefn_implemented_but_not_working
     146                 :   virtual OGRErr      AlterFieldDefn( int iFieldToAlter, OGRFieldDefn* poNewFieldDefn, int nFlags );
     147                 : #endif
     148                 : 
     149                 :   virtual OGRErr      CreateFeature( OGRFeature *poFeature );
     150                 :   virtual OGRErr      SetFeature( OGRFeature *poFeature );
     151                 :   virtual OGRErr      DeleteFeature( long nFID );
     152                 : 
     153                 :   virtual OGRErr      GetExtent( OGREnvelope *psExtent, int bForce );
     154                 :   virtual int         GetFeatureCount( int bForce );
     155                 :   virtual OGRErr      SetAttributeFilter( const char *pszQuery );
     156                 :   virtual void        SetSpatialFilterRect (double dfMinX, double dfMinY, double dfMaxX, double dfMaxY);
     157                 :   virtual void        SetSpatialFilter( OGRGeometry * );
     158                 : 
     159                 : //  virtual OGRErr        StartTransaction( );
     160                 : //  virtual OGRErr        CommitTransaction( );
     161                 : //  virtual OGRErr        RollbackTransaction( );
     162                 : 
     163            4040 :   OGRFeatureDefn *    GetLayerDefn() { return m_pFeatureDefn; }
     164                 :   
     165              35 :   virtual OGRSpatialReference *GetSpatialRef() { return m_pSRS; }
     166                 : 
     167                 :   virtual int         TestCapability( const char * );
     168                 : 
     169                 :   // Access the XML directly. The 2 following methods are not currently used by the driver, but
     170                 :   // can be used by external code for specific purposes.
     171                 :   OGRErr              GetLayerXML ( char **poXml );
     172                 :   OGRErr              GetLayerMetadataXML ( char **poXmlMeta );
     173                 :   
     174                 : protected:
     175                 : 
     176                 :   bool GDBToOGRFields(CPLXMLNode* psFields);  
     177                 :   bool ParseGeometryDef(CPLXMLNode* psGeometryDef);
     178                 :   bool ParseSpatialReference(CPLXMLNode* psSpatialRefNode, std::string* pOutWkt, std::string* pOutWKID);
     179                 : 
     180                 :   FGdbDataSource* m_pDS;
     181                 :   Table* m_pTable;
     182                 : 
     183                 :   std::string m_strName; //contains underlying FGDB table name (not catalog name)
     184                 : 
     185                 :   std::string m_strOIDFieldName;
     186                 :   std::string m_strShapeFieldName;
     187                 : 
     188                 :   std::wstring m_wstrTablePath;
     189                 :   std::wstring m_wstrType; // the type: "Table" or "Feature Class"
     190                 : 
     191                 :   std::wstring m_wstrSubfields;
     192                 :   std::wstring m_wstrWhereClause;
     193                 :   OGRGeometry* m_pOGRFilterGeometry;
     194                 : 
     195                 :   bool        m_bFilterDirty; //optimization to avoid multiple calls to search until necessary
     196                 : 
     197                 :   bool  m_bLaunderReservedKeywords;
     198                 : 
     199                 : };
     200                 : 
     201                 : /************************************************************************/
     202                 : /*                         FGdbResultLayer                              */
     203                 : /************************************************************************/
     204                 : 
     205                 : class FGdbResultLayer : public FGdbBaseLayer
     206                 : {
     207                 : public:
     208                 : 
     209                 :   FGdbResultLayer(FGdbDataSource* pParentDataSource, const char* pszStatement, EnumRows* pEnumRows);
     210                 :   virtual ~FGdbResultLayer();
     211                 : 
     212                 :   virtual void        ResetReading();
     213                 : 
     214               0 :   OGRFeatureDefn *    GetLayerDefn() { return m_pFeatureDefn; }
     215                 : 
     216                 :   //virtual OGRSpatialReference *GetSpatialRef() { return m_pSRS; }
     217                 : 
     218                 :   virtual int         TestCapability( const char * );
     219                 : 
     220                 : protected:
     221                 : 
     222                 :   FGdbDataSource* m_pDS;
     223                 :   CPLString       osSQL;
     224                 : };
     225                 : 
     226                 : /************************************************************************/
     227                 : /*                           FGdbDataSource                            */
     228                 : /************************************************************************/
     229                 : class FGdbDataSource : public OGRDataSource
     230                 : {
     231                 : 
     232                 : public:
     233                 :   FGdbDataSource();
     234                 :   virtual ~FGdbDataSource();
     235                 : 
     236                 :   int         Open(Geodatabase* pGeodatabase, const char *, int );
     237                 : 
     238              19 :   const char* GetName() { return m_pszName; }
     239            2125 :   int         GetLayerCount() { return static_cast<int>(m_layers.size()); }
     240                 : 
     241                 :   OGRLayer*   GetLayer( int );
     242                 : 
     243                 :   virtual OGRLayer* CreateLayer( const char *, OGRSpatialReference* = NULL, OGRwkbGeometryType = wkbUnknown, char** = NULL );
     244                 : 
     245                 :   virtual OGRErr DeleteLayer( int );
     246                 : 
     247                 :   virtual OGRLayer *  ExecuteSQL( const char *pszSQLCommand,
     248                 :                                   OGRGeometry *poSpatialFilter,
     249                 :                                   const char *pszDialect );
     250                 :   virtual void        ReleaseResultSet( OGRLayer * poResultsSet );
     251                 : 
     252                 :   int TestCapability( const char * );
     253                 : 
     254             223 :   Geodatabase* GetGDB() { return m_pGeodatabase; }
     255                 : 
     256                 :   /*
     257                 :   protected:
     258                 : 
     259                 :   void EnumerateSpatialTables();
     260                 :   void OpenSpatialTable( const char* pszTableName );
     261                 :   */
     262                 : protected:
     263                 :   bool LoadLayers(const std::wstring & parent);
     264                 :   bool OpenFGDBTables(const std::wstring &type,
     265                 :                       const std::vector<std::wstring> &layers);
     266                 : 
     267                 :   char* m_pszName;
     268                 :   std::vector <FGdbLayer*> m_layers;
     269                 :   Geodatabase* m_pGeodatabase;
     270                 : 
     271                 : };
     272                 : 
     273                 : /************************************************************************/
     274                 : /*                              FGdbDriver                                */
     275                 : /************************************************************************/
     276                 : 
     277                 : class FGdbDriver : public OGRSFDriver
     278                 : {
     279                 : 
     280                 : public:
     281                 :   FGdbDriver();
     282                 :   virtual ~FGdbDriver();
     283                 : 
     284                 :   virtual const char *GetName();
     285                 :   virtual OGRDataSource *Open( const char *, int );
     286                 :   virtual int TestCapability( const char * );
     287                 :   virtual OGRDataSource *CreateDataSource( const char *pszName, char ** = NULL);
     288                 :   virtual OGRErr DeleteDataSource( const char *pszDataSource );
     289                 : 
     290                 :   void OpenGeodatabase(std::string, Geodatabase** ppGeodatabase);
     291                 : 
     292                 : private:
     293                 : 
     294                 : };
     295                 : 
     296                 : CPL_C_START
     297                 : void CPL_DLL RegisterOGRFileGDB();
     298                 : CPL_C_END
     299                 : 
     300                 : #endif /* ndef _OGR_PG_H_INCLUDED */
     301                 : 
     302                 : 

Generated by: LCOV version 1.7