1 : /******************************************************************************
2 : * $Id: ogr_fgdb.h 23027 2011-09-02 22:19:29Z 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 : /************************************************************************
46 : * Default layer creation options
47 : */
48 :
49 : #define FGDB_FEATURE_DATASET "";
50 : #define FGDB_GEOMETRY_NAME "SHAPE"
51 : #define FGDB_OID_NAME "OBJECTID"
52 :
53 :
54 : /* The ESRI FGDB API namespace */
55 : using namespace FileGDBAPI;
56 :
57 :
58 : /************************************************************************/
59 : /* FGdbLayer */
60 : /************************************************************************/
61 :
62 : class FGdbDataSource;
63 :
64 : class FGdbLayer : public OGRLayer
65 : {
66 : public:
67 :
68 : FGdbLayer();
69 : virtual ~FGdbLayer();
70 :
71 : // Internal used by FGDB driver */
72 : bool Initialize(FGdbDataSource* pParentDataSource, Table* pTable, std::wstring wstrTablePath, std::wstring wstrType);
73 : bool Create(FGdbDataSource* pParentDataSource, const char * pszLayerName, OGRSpatialReference *poSRS, OGRwkbGeometryType eType, char ** papszOptions);
74 : bool CreateFeatureDataset(FGdbDataSource* pParentDataSource, std::string feature_dataset_name, OGRSpatialReference* poSRS, char** papszOptions );
75 :
76 : // virtual const char *GetName();
77 41 : virtual const char* GetFIDColumn() { return m_strOIDFieldName.c_str(); }
78 0 : virtual const char* GetGeometryColumn() { return m_strShapeFieldName.c_str(); }
79 :
80 : virtual void ResetReading();
81 : virtual OGRFeature* GetNextFeature();
82 : virtual OGRFeature* GetFeature( long nFeatureId );
83 :
84 2 : Table* GetTable() { return m_pTable; }
85 :
86 2 : std::wstring GetTablePath() const { return m_wstrTablePath; }
87 2 : std::wstring GetType() const { return m_wstrType; }
88 :
89 : virtual OGRErr CreateField( OGRFieldDefn *poField, int bApproxOK );
90 : virtual OGRErr CreateFeature( OGRFeature *poFeature );
91 : virtual OGRErr GetExtent( OGREnvelope *psExtent, int bForce );
92 : virtual int GetFeatureCount( int bForce );
93 : virtual OGRErr SetAttributeFilter( const char *pszQuery );
94 : virtual void SetSpatialFilterRect (double dfMinX, double dfMinY, double dfMaxX, double dfMaxY);
95 : virtual void SetSpatialFilter( OGRGeometry * );
96 :
97 : // virtual OGRErr StartTransaction( );
98 : // virtual OGRErr CommitTransaction( );
99 : // virtual OGRErr RollbackTransaction( );
100 :
101 715 : OGRFeatureDefn * GetLayerDefn() { return m_pFeatureDefn; }
102 :
103 25 : virtual OGRSpatialReference *GetSpatialRef() { return m_pSRS; }
104 :
105 : virtual int TestCapability( const char * );
106 :
107 : // Access the XML directly. The 2 following methods are not currently used by the driver, but
108 : // can be used by external code for specific purposes.
109 : OGRErr GetLayerXML ( char **poXml );
110 : OGRErr GetLayerMetadataXML ( char **poXmlMeta );
111 :
112 : protected:
113 :
114 : bool GDBToOGRFields(CPLXMLNode* psFields);
115 : bool ParseGeometryDef(CPLXMLNode* psGeometryDef);
116 : bool ParseSpatialReference(CPLXMLNode* psSpatialRefNode, std::string* pOutWkt, std::string* pOutWKID);
117 :
118 : bool OGRFeatureFromGdbRow(Row* pRow, OGRFeature** ppFeature);
119 :
120 : FGdbDataSource* m_pDS;
121 : Table* m_pTable;
122 : OGRFeatureDefn* m_pFeatureDefn;
123 : OGRSpatialReference* m_pSRS;
124 :
125 : std::string m_strName; //contains underlying FGDB table name (not catalog name)
126 :
127 : std::string m_strOIDFieldName;
128 : std::string m_strShapeFieldName;
129 :
130 : std::wstring m_wstrTablePath;
131 : std::wstring m_wstrType; // the type: "Table" or "Feature Class"
132 :
133 : std::wstring m_wstrSubfields;
134 : std::wstring m_wstrWhereClause;
135 : OGRGeometry* m_pOGRFilterGeometry;
136 : EnumRows* m_pEnumRows;
137 :
138 : bool m_bFilterDirty; //optimization to avoid multiple calls to search until necessary
139 :
140 :
141 : std::vector<std::wstring> m_vOGRFieldToESRIField; //OGR Field Index to ESRI Field Name Mapping
142 : std::vector<std::string> m_vOGRFieldToESRIFieldType; //OGR Field Index to ESRI Field Type Mapping
143 :
144 : //buffers are used for avoiding constant reallocation of temp memory
145 : //unsigned char* m_pBuffer;
146 : //long m_bufferSize; //in bytes
147 :
148 : bool m_supressColumnMappingError;
149 : bool m_forceMulti;
150 :
151 : };
152 :
153 : /************************************************************************/
154 : /* FGdbDataSource */
155 : /************************************************************************/
156 : class FGdbDataSource : public OGRDataSource
157 : {
158 :
159 : public:
160 : FGdbDataSource();
161 : virtual ~FGdbDataSource();
162 :
163 : int Open(Geodatabase* pGeodatabase, const char *, int );
164 :
165 8 : const char* GetName() { return m_pszName; }
166 389 : int GetLayerCount() { return static_cast<int>(m_layers.size()); }
167 :
168 : OGRLayer* GetLayer( int );
169 :
170 : virtual OGRLayer* CreateLayer( const char *, OGRSpatialReference* = NULL, OGRwkbGeometryType = wkbUnknown, char** = NULL );
171 :
172 : virtual OGRErr DeleteLayer( int );
173 :
174 : int TestCapability( const char * );
175 :
176 101 : Geodatabase* GetGDB() { return m_pGeodatabase; }
177 :
178 : /*
179 : protected:
180 :
181 : void EnumerateSpatialTables();
182 : void OpenSpatialTable( const char* pszTableName );
183 : */
184 : protected:
185 : bool LoadLayers(const std::wstring & parent);
186 : bool OpenFGDBTables(const std::wstring &type,
187 : const std::vector<std::wstring> &layers);
188 :
189 : char* m_pszName;
190 : std::vector <FGdbLayer*> m_layers;
191 : Geodatabase* m_pGeodatabase;
192 :
193 : };
194 :
195 : /************************************************************************/
196 : /* FGdbDriver */
197 : /************************************************************************/
198 :
199 : class FGdbDriver : public OGRSFDriver
200 : {
201 :
202 : public:
203 : FGdbDriver();
204 : virtual ~FGdbDriver();
205 :
206 : virtual const char *GetName();
207 : virtual OGRDataSource *Open( const char *, int );
208 : virtual int TestCapability( const char * );
209 : virtual OGRDataSource *CreateDataSource( const char *pszName, char ** = NULL);
210 : virtual OGRErr DeleteDataSource( const char *pszDataSource );
211 :
212 : void OpenGeodatabase(std::string, Geodatabase** ppGeodatabase);
213 :
214 : private:
215 :
216 : };
217 :
218 : CPL_C_START
219 : void CPL_DLL RegisterOGRFileGDB();
220 : CPL_C_END
221 :
222 : #endif /* ndef _OGR_PG_H_INCLUDED */
223 :
224 :
|