1 : /******************************************************************************
2 : * $Id: ogr_fgdb.h 23860 2012-02-01 18:57: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 : /* 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 : /************************************************************************/
64 : /* FGdbLayer */
65 : /************************************************************************/
66 :
67 : class FGdbDataSource;
68 :
69 : class FGdbLayer : public OGRLayer
70 : {
71 : int m_bBulkLoadAllowed;
72 : int m_bBulkLoadInProgress;
73 :
74 : void StartBulkLoad();
75 : void EndBulkLoad();
76 :
77 : #ifdef EXTENT_WORKAROUND
78 : bool m_bLayerJustCreated;
79 : OGREnvelope sLayerEnvelope;
80 : bool m_bLayerEnvelopeValid;
81 : void WorkAroundExtentProblem();
82 : bool UpdateRowWithGeometry(Row& row, OGRGeometry* poGeom);
83 : #endif
84 :
85 : OGRErr PopulateRowWithFeature( Row& row, OGRFeature *poFeature );
86 : OGRErr GetRow( EnumRows& enumRows, Row& row, long nFID );
87 :
88 : char* CreateFieldDefn(OGRFieldDefn& oField,
89 : int bApproxOK,
90 : std::string& fieldname_clean,
91 : std::string& gdbFieldType);
92 :
93 : public:
94 :
95 : FGdbLayer();
96 : virtual ~FGdbLayer();
97 :
98 : // Internal used by FGDB driver */
99 : bool Initialize(FGdbDataSource* pParentDataSource, Table* pTable, std::wstring wstrTablePath, std::wstring wstrType);
100 : bool Create(FGdbDataSource* pParentDataSource, const char * pszLayerName, OGRSpatialReference *poSRS, OGRwkbGeometryType eType, char ** papszOptions);
101 : bool CreateFeatureDataset(FGdbDataSource* pParentDataSource, std::string feature_dataset_name, OGRSpatialReference* poSRS, char** papszOptions );
102 :
103 : // virtual const char *GetName();
104 130 : virtual const char* GetFIDColumn() { return m_strOIDFieldName.c_str(); }
105 0 : virtual const char* GetGeometryColumn() { return m_strShapeFieldName.c_str(); }
106 :
107 : virtual void ResetReading();
108 : virtual OGRFeature* GetNextFeature();
109 : virtual OGRFeature* GetFeature( long nFeatureId );
110 :
111 4 : Table* GetTable() { return m_pTable; }
112 :
113 4 : std::wstring GetTablePath() const { return m_wstrTablePath; }
114 4 : std::wstring GetType() const { return m_wstrType; }
115 :
116 : virtual OGRErr CreateField( OGRFieldDefn *poField, int bApproxOK );
117 : virtual OGRErr DeleteField( int iFieldToDelete );
118 : #ifdef AlterFieldDefn_implemented_but_not_working
119 : virtual OGRErr AlterFieldDefn( int iFieldToAlter, OGRFieldDefn* poNewFieldDefn, int nFlags );
120 : #endif
121 :
122 : virtual OGRErr CreateFeature( OGRFeature *poFeature );
123 : virtual OGRErr SetFeature( OGRFeature *poFeature );
124 : virtual OGRErr DeleteFeature( long nFID );
125 :
126 : virtual OGRErr GetExtent( OGREnvelope *psExtent, int bForce );
127 : virtual int GetFeatureCount( int bForce );
128 : virtual OGRErr SetAttributeFilter( const char *pszQuery );
129 : virtual void SetSpatialFilterRect (double dfMinX, double dfMinY, double dfMaxX, double dfMaxY);
130 : virtual void SetSpatialFilter( OGRGeometry * );
131 :
132 : // virtual OGRErr StartTransaction( );
133 : // virtual OGRErr CommitTransaction( );
134 : // virtual OGRErr RollbackTransaction( );
135 :
136 5230 : OGRFeatureDefn * GetLayerDefn() { return m_pFeatureDefn; }
137 :
138 52 : virtual OGRSpatialReference *GetSpatialRef() { return m_pSRS; }
139 :
140 : virtual int TestCapability( const char * );
141 :
142 : // Access the XML directly. The 2 following methods are not currently used by the driver, but
143 : // can be used by external code for specific purposes.
144 : OGRErr GetLayerXML ( char **poXml );
145 : OGRErr GetLayerMetadataXML ( char **poXmlMeta );
146 :
147 : protected:
148 :
149 : bool GDBToOGRFields(CPLXMLNode* psFields);
150 : bool ParseGeometryDef(CPLXMLNode* psGeometryDef);
151 : bool ParseSpatialReference(CPLXMLNode* psSpatialRefNode, std::string* pOutWkt, std::string* pOutWKID);
152 :
153 : bool OGRFeatureFromGdbRow(Row* pRow, OGRFeature** ppFeature);
154 :
155 : FGdbDataSource* m_pDS;
156 : Table* m_pTable;
157 : OGRFeatureDefn* m_pFeatureDefn;
158 : OGRSpatialReference* m_pSRS;
159 :
160 : std::string m_strName; //contains underlying FGDB table name (not catalog name)
161 :
162 : std::string m_strOIDFieldName;
163 : std::string m_strShapeFieldName;
164 :
165 : std::wstring m_wstrTablePath;
166 : std::wstring m_wstrType; // the type: "Table" or "Feature Class"
167 :
168 : std::wstring m_wstrSubfields;
169 : std::wstring m_wstrWhereClause;
170 : OGRGeometry* m_pOGRFilterGeometry;
171 : EnumRows* m_pEnumRows;
172 :
173 : bool m_bFilterDirty; //optimization to avoid multiple calls to search until necessary
174 :
175 :
176 : std::vector<std::wstring> m_vOGRFieldToESRIField; //OGR Field Index to ESRI Field Name Mapping
177 : std::vector<std::string> m_vOGRFieldToESRIFieldType; //OGR Field Index to ESRI Field Type Mapping
178 :
179 : //buffers are used for avoiding constant reallocation of temp memory
180 : //unsigned char* m_pBuffer;
181 : //long m_bufferSize; //in bytes
182 :
183 : bool m_supressColumnMappingError;
184 : bool m_forceMulti;
185 : bool m_bLaunderReservedKeywords;
186 :
187 : };
188 :
189 : /************************************************************************/
190 : /* FGdbDataSource */
191 : /************************************************************************/
192 : class FGdbDataSource : public OGRDataSource
193 : {
194 :
195 : public:
196 : FGdbDataSource();
197 : virtual ~FGdbDataSource();
198 :
199 : int Open(Geodatabase* pGeodatabase, const char *, int );
200 :
201 28 : const char* GetName() { return m_pszName; }
202 2514 : int GetLayerCount() { return static_cast<int>(m_layers.size()); }
203 :
204 : OGRLayer* GetLayer( int );
205 :
206 : virtual OGRLayer* CreateLayer( const char *, OGRSpatialReference* = NULL, OGRwkbGeometryType = wkbUnknown, char** = NULL );
207 :
208 : virtual OGRErr DeleteLayer( int );
209 :
210 : virtual OGRLayer * ExecuteSQL( const char *pszSQLCommand,
211 : OGRGeometry *poSpatialFilter,
212 : const char *pszDialect );
213 :
214 : int TestCapability( const char * );
215 :
216 358 : Geodatabase* GetGDB() { return m_pGeodatabase; }
217 :
218 : /*
219 : protected:
220 :
221 : void EnumerateSpatialTables();
222 : void OpenSpatialTable( const char* pszTableName );
223 : */
224 : protected:
225 : bool LoadLayers(const std::wstring & parent);
226 : bool OpenFGDBTables(const std::wstring &type,
227 : const std::vector<std::wstring> &layers);
228 :
229 : char* m_pszName;
230 : std::vector <FGdbLayer*> m_layers;
231 : Geodatabase* m_pGeodatabase;
232 :
233 : };
234 :
235 : /************************************************************************/
236 : /* FGdbDriver */
237 : /************************************************************************/
238 :
239 : class FGdbDriver : public OGRSFDriver
240 : {
241 :
242 : public:
243 : FGdbDriver();
244 : virtual ~FGdbDriver();
245 :
246 : virtual const char *GetName();
247 : virtual OGRDataSource *Open( const char *, int );
248 : virtual int TestCapability( const char * );
249 : virtual OGRDataSource *CreateDataSource( const char *pszName, char ** = NULL);
250 : virtual OGRErr DeleteDataSource( const char *pszDataSource );
251 :
252 : void OpenGeodatabase(std::string, Geodatabase** ppGeodatabase);
253 :
254 : private:
255 :
256 : };
257 :
258 : CPL_C_START
259 : void CPL_DLL RegisterOGRFileGDB();
260 : CPL_C_END
261 :
262 : #endif /* ndef _OGR_PG_H_INCLUDED */
263 :
264 :
|