GDAL
ogrsf_frmts.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id$
3  *
4  * Project: OpenGIS Simple Features Reference Implementation
5  * Purpose: Classes related to format registration, and file opening.
6  * Author: Frank Warmerdam, warmerda@home.com
7  *
8  ******************************************************************************
9  * Copyright (c) 1999, Les Technologies SoftMap Inc.
10  * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef OGRSF_FRMTS_H_INCLUDED
32 #define OGRSF_FRMTS_H_INCLUDED
33 
34 #include "cpl_progress.h"
35 #include "ogr_feature.h"
36 #include "ogr_featurestyle.h"
37 #include "gdal_priv.h"
38 
39 #include <memory>
40 
48 #if !defined(GDAL_COMPILATION) && !defined(SUPPRESS_DEPRECATION_WARNINGS)
49 #define OGR_DEPRECATED(x) CPL_WARN_DEPRECATED(x)
50 #else
51 #define OGR_DEPRECATED(x)
52 #endif
54 
55 class OGRLayerAttrIndex;
56 class OGRSFDriver;
57 
58 /************************************************************************/
59 /* OGRLayer */
60 /************************************************************************/
61 
67 /* Note: any virtual method added to this class must also be added in the */
68 /* OGRLayerDecorator and OGRMutexedLayer classes. */
69 
70 class CPL_DLL OGRLayer : public GDALMajorObject
71 {
72  private:
73  struct Private;
74  std::unique_ptr<Private> m_poPrivate;
75 
76  void ConvertGeomsIfNecessary( OGRFeature *poFeature );
77 
78  class CPL_DLL FeatureIterator
79  {
80  struct Private;
81  std::unique_ptr<Private> m_poPrivate;
82  public:
83  FeatureIterator(OGRLayer* poLayer, bool bStart);
84  FeatureIterator(FeatureIterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
85  ~FeatureIterator();
86  OGRFeatureUniquePtr& operator*();
87  FeatureIterator& operator++();
88  bool operator!=(const FeatureIterator& it) const;
89  };
90 
91  friend inline FeatureIterator begin(OGRLayer* poLayer);
92  friend inline FeatureIterator end(OGRLayer* poLayer);
93 
95 
96  protected:
98  int m_bFilterIsEnvelope;
99  OGRGeometry *m_poFilterGeom;
100  OGRPreparedGeometry *m_pPreparedFilterGeom; /* m_poFilterGeom compiled as a prepared geometry */
101  OGREnvelope m_sFilterEnvelope;
102  int m_iGeomFieldFilter; // specify the index on which the spatial
103  // filter is active.
104 
105  int FilterGeometry( OGRGeometry * );
106  //int FilterGeometry( OGRGeometry *, OGREnvelope* psGeometryEnvelope);
107  int InstallFilter( OGRGeometry * );
108 
109  OGRErr GetExtentInternal(int iGeomField, OGREnvelope *psExtent, int bForce );
111 
112  virtual OGRErr ISetFeature( OGRFeature *poFeature ) CPL_WARN_UNUSED_RESULT;
113  virtual OGRErr ICreateFeature( OGRFeature *poFeature ) CPL_WARN_UNUSED_RESULT;
114 
115  public:
116  OGRLayer();
117  virtual ~OGRLayer();
118 
129  FeatureIterator begin();
130 
132  FeatureIterator end();
133 
134  virtual OGRGeometry *GetSpatialFilter();
135  virtual void SetSpatialFilter( OGRGeometry * );
136  virtual void SetSpatialFilterRect( double dfMinX, double dfMinY,
137  double dfMaxX, double dfMaxY );
138 
139  virtual void SetSpatialFilter( int iGeomField, OGRGeometry * );
140  virtual void SetSpatialFilterRect( int iGeomField,
141  double dfMinX, double dfMinY,
142  double dfMaxX, double dfMaxY );
143 
144  virtual OGRErr SetAttributeFilter( const char * );
145 
146  virtual void ResetReading() = 0;
148  virtual OGRErr SetNextByIndex( GIntBig nIndex );
149  virtual OGRFeature *GetFeature( GIntBig nFID ) CPL_WARN_UNUSED_RESULT;
150 
151  OGRErr SetFeature( OGRFeature *poFeature ) CPL_WARN_UNUSED_RESULT;
152  OGRErr CreateFeature( OGRFeature *poFeature ) CPL_WARN_UNUSED_RESULT;
153 
154  virtual OGRErr DeleteFeature( GIntBig nFID ) CPL_WARN_UNUSED_RESULT;
155 
156  virtual const char *GetName();
157  virtual OGRwkbGeometryType GetGeomType();
158  virtual OGRFeatureDefn *GetLayerDefn() = 0;
159  virtual int FindFieldIndex( const char *pszFieldName, int bExactMatch );
160 
161  virtual OGRSpatialReference *GetSpatialRef();
162 
163  virtual GIntBig GetFeatureCount( int bForce = TRUE );
164  virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) CPL_WARN_UNUSED_RESULT;
165  virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
166  int bForce = TRUE) CPL_WARN_UNUSED_RESULT;
167 
168  virtual int TestCapability( const char * ) = 0;
169 
170  virtual OGRErr Rename( const char* pszNewName ) CPL_WARN_UNUSED_RESULT;
171 
172  virtual OGRErr CreateField( OGRFieldDefn *poField,
173  int bApproxOK = TRUE );
174  virtual OGRErr DeleteField( int iField );
175  virtual OGRErr ReorderFields( int* panMap );
176  virtual OGRErr AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlagsIn );
177 
178  virtual OGRErr CreateGeomField( OGRGeomFieldDefn *poField,
179  int bApproxOK = TRUE );
180 
181  virtual OGRErr SyncToDisk();
182 
183  virtual OGRStyleTable *GetStyleTable();
184  virtual void SetStyleTableDirectly( OGRStyleTable *poStyleTable );
185 
186  virtual void SetStyleTable(OGRStyleTable *poStyleTable);
187 
188  virtual OGRErr StartTransaction() CPL_WARN_UNUSED_RESULT;
189  virtual OGRErr CommitTransaction() CPL_WARN_UNUSED_RESULT;
190  virtual OGRErr RollbackTransaction();
191 
192  virtual const char *GetFIDColumn();
193  virtual const char *GetGeometryColumn();
194 
195  virtual OGRErr SetIgnoredFields( const char **papszFields );
196 
197  OGRErr Intersection( OGRLayer *pLayerMethod,
198  OGRLayer *pLayerResult,
199  char** papszOptions = nullptr,
200  GDALProgressFunc pfnProgress = nullptr,
201  void * pProgressArg = nullptr );
202  OGRErr Union( OGRLayer *pLayerMethod,
203  OGRLayer *pLayerResult,
204  char** papszOptions = nullptr,
205  GDALProgressFunc pfnProgress = nullptr,
206  void * pProgressArg = nullptr );
207  OGRErr SymDifference( OGRLayer *pLayerMethod,
208  OGRLayer *pLayerResult,
209  char** papszOptions,
210  GDALProgressFunc pfnProgress,
211  void * pProgressArg );
212  OGRErr Identity( OGRLayer *pLayerMethod,
213  OGRLayer *pLayerResult,
214  char** papszOptions = nullptr,
215  GDALProgressFunc pfnProgress = nullptr,
216  void * pProgressArg = nullptr );
217  OGRErr Update( OGRLayer *pLayerMethod,
218  OGRLayer *pLayerResult,
219  char** papszOptions = nullptr,
220  GDALProgressFunc pfnProgress = nullptr,
221  void * pProgressArg = nullptr );
222  OGRErr Clip( OGRLayer *pLayerMethod,
223  OGRLayer *pLayerResult,
224  char** papszOptions = nullptr,
225  GDALProgressFunc pfnProgress = nullptr,
226  void * pProgressArg = nullptr );
227  OGRErr Erase( OGRLayer *pLayerMethod,
228  OGRLayer *pLayerResult,
229  char** papszOptions = nullptr,
230  GDALProgressFunc pfnProgress = nullptr,
231  void * pProgressArg = nullptr );
232 
233  int Reference();
234  int Dereference();
235  int GetRefCount() const;
237  GIntBig GetFeaturesRead();
239 
240  /* non virtual : convenience wrapper for ReorderFields() */
241  OGRErr ReorderField( int iOldFieldPos, int iNewFieldPos );
242 
244  int AttributeFilterEvaluationNeedsGeometry();
245 
246  /* consider these private */
247  OGRErr InitializeIndexSupport( const char * );
248  OGRLayerAttrIndex *GetIndex() { return m_poAttrIndex; }
249  int GetGeomFieldFilter() const { return m_iGeomFieldFilter; }
250  const char *GetAttrQueryString() const { return m_pszAttrQueryString; }
252 
256  static inline OGRLayerH ToHandle(OGRLayer* poLayer)
257  { return reinterpret_cast<OGRLayerH>(poLayer); }
258 
262  static inline OGRLayer* FromHandle(OGRLayerH hLayer)
263  { return reinterpret_cast<OGRLayer*>(hLayer); }
264 
265  protected:
267  OGRStyleTable *m_poStyleTable;
268  OGRFeatureQuery *m_poAttrQuery;
269  char *m_pszAttrQueryString;
270  OGRLayerAttrIndex *m_poAttrIndex;
271 
272  int m_nRefCount;
273 
274  GIntBig m_nFeaturesRead;
276 };
277 
289 inline OGRLayer::FeatureIterator begin(OGRLayer* poLayer) { return poLayer->begin(); }
290 
294 inline OGRLayer::FeatureIterator end(OGRLayer* poLayer) { return poLayer->end(); }
295 
299 using OGRLayerUniquePtr = std::unique_ptr<OGRLayer>;
300 
301 /************************************************************************/
302 /* OGRGetNextFeatureThroughRaw */
303 /************************************************************************/
304 
310 template<class BaseLayer> class OGRGetNextFeatureThroughRaw
311 {
312 protected:
313  ~OGRGetNextFeatureThroughRaw() = default;
314 
315 public:
316 
319  {
320  const auto poThis = static_cast<BaseLayer*>(this);
321  while( true )
322  {
323  OGRFeature *poFeature = poThis->GetNextRawFeature();
324  if (poFeature == nullptr)
325  return nullptr;
326 
327  if((poThis->m_poFilterGeom == nullptr
328  || poThis->FilterGeometry( poFeature->GetGeometryRef() ) )
329  && (poThis->m_poAttrQuery == nullptr
330  || poThis->m_poAttrQuery->Evaluate( poFeature )) )
331  {
332  return poFeature;
333  }
334  else
335  delete poFeature;
336  }
337  }
338 };
339 
341 #define DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(BaseLayer) \
342  private: \
343  friend class OGRGetNextFeatureThroughRaw<BaseLayer>; \
344  public: \
345  OGRFeature* GetNextFeature() override { return OGRGetNextFeatureThroughRaw<BaseLayer>::GetNextFeature(); }
346 
347 
348 /************************************************************************/
349 /* OGRDataSource */
350 /************************************************************************/
351 
371 class CPL_DLL OGRDataSource : public GDALDataset
372 {
373 public:
374  OGRDataSource();
376  virtual const char *GetName() OGR_DEPRECATED("Use GDALDataset class instead") = 0;
377 
378  static void DestroyDataSource( OGRDataSource * ) OGR_DEPRECATED("Use GDALDataset class instead");
380 };
381 
382 /************************************************************************/
383 /* OGRSFDriver */
384 /************************************************************************/
385 
404 class CPL_DLL OGRSFDriver : public GDALDriver
405 {
406  public:
408  virtual ~OGRSFDriver();
409 
410  virtual const char *GetName() OGR_DEPRECATED("Use GDALDriver class instead") = 0;
411 
412  virtual OGRDataSource *Open( const char *pszName, int bUpdate=FALSE ) OGR_DEPRECATED("Use GDALDriver class instead") = 0;
413 
414  virtual int TestCapability( const char *pszCap ) OGR_DEPRECATED("Use GDALDriver class instead") = 0;
415 
416  virtual OGRDataSource *CreateDataSource( const char *pszName,
417  char ** = nullptr ) OGR_DEPRECATED("Use GDALDriver class instead");
418  virtual OGRErr DeleteDataSource( const char *pszName ) OGR_DEPRECATED("Use GDALDriver class instead");
420 };
421 
422 /************************************************************************/
423 /* OGRSFDriverRegistrar */
424 /************************************************************************/
425 
439 class CPL_DLL OGRSFDriverRegistrar
440 {
441 
444 
445  static GDALDataset* OpenWithDriverArg(GDALDriver* poDriver,
446  GDALOpenInfo* poOpenInfo);
447  static GDALDataset* CreateVectorOnly( GDALDriver* poDriver,
448  const char * pszName,
449  char ** papszOptions );
450  static CPLErr DeleteDataSource( GDALDriver* poDriver,
451  const char * pszName );
452 
453  public:
455  static OGRSFDriverRegistrar *GetRegistrar() OGR_DEPRECATED("Use GDALDriverManager class instead");
456 
457  // cppcheck-suppress functionStatic
458  void RegisterDriver( OGRSFDriver * poDriver ) OGR_DEPRECATED("Use GDALDriverManager class instead");
459 
460  // cppcheck-suppress functionStatic
461  int GetDriverCount( void ) OGR_DEPRECATED("Use GDALDriverManager class instead");
462  // cppcheck-suppress functionStatic
463  GDALDriver *GetDriver( int iDriver ) OGR_DEPRECATED("Use GDALDriverManager class instead");
464  // cppcheck-suppress functionStatic
465  GDALDriver *GetDriverByName( const char * ) OGR_DEPRECATED("Use GDALDriverManager class instead");
466 
467  // cppcheck-suppress functionStatic
468  int GetOpenDSCount() OGR_DEPRECATED("Use GDALDriverManager class instead");
469  // cppcheck-suppress functionStatic
470  OGRDataSource *GetOpenDS( int ) OGR_DEPRECATED("Use GDALDriverManager class instead");
472 };
473 
474 /* -------------------------------------------------------------------- */
475 /* Various available registration methods. */
476 /* -------------------------------------------------------------------- */
478 
480 void OGRRegisterAllInternal();
481 
482 void CPL_DLL RegisterOGRFileGDB();
483 void CPL_DLL RegisterOGRShape();
484 void CPL_DLL RegisterOGRNTF();
485 void CPL_DLL RegisterOGRSDTS();
486 void CPL_DLL RegisterOGRTiger();
487 void CPL_DLL RegisterOGRS57();
488 void CPL_DLL RegisterOGRTAB();
489 void CPL_DLL RegisterOGRMIF();
490 void CPL_DLL RegisterOGROGDI();
491 void CPL_DLL RegisterOGRODBC();
492 void CPL_DLL RegisterOGRWAsP();
493 void CPL_DLL RegisterOGRPG();
494 void CPL_DLL RegisterOGRMSSQLSpatial();
495 void CPL_DLL RegisterOGRMySQL();
496 void CPL_DLL RegisterOGROCI();
497 void CPL_DLL RegisterOGRDGN();
498 void CPL_DLL RegisterOGRGML();
499 void CPL_DLL RegisterOGRLIBKML();
500 void CPL_DLL RegisterOGRKML();
501 void CPL_DLL RegisterOGRFlatGeobuf();
502 void CPL_DLL RegisterOGRGeoJSON();
503 void CPL_DLL RegisterOGRGeoJSONSeq();
504 void CPL_DLL RegisterOGRESRIJSON();
505 void CPL_DLL RegisterOGRTopoJSON();
506 void CPL_DLL RegisterOGRAVCBin();
507 void CPL_DLL RegisterOGRAVCE00();
508 void CPL_DLL RegisterOGRMEM();
509 void CPL_DLL RegisterOGRVRT();
510 void CPL_DLL RegisterOGRDODS();
511 void CPL_DLL RegisterOGRSQLite();
512 void CPL_DLL RegisterOGRCSV();
513 void CPL_DLL RegisterOGRILI1();
514 void CPL_DLL RegisterOGRILI2();
515 void CPL_DLL RegisterOGRGRASS();
516 void CPL_DLL RegisterOGRPGeo();
517 void CPL_DLL RegisterOGRDXF();
518 void CPL_DLL RegisterOGRCAD();
519 void CPL_DLL RegisterOGRDWG();
520 void CPL_DLL RegisterOGRDGNV8();
521 void CPL_DLL RegisterOGRIDB();
522 void CPL_DLL RegisterOGRGMT();
523 void CPL_DLL RegisterOGRGPX();
524 void CPL_DLL RegisterOGRGeoconcept();
525 void CPL_DLL RegisterOGRNAS();
526 void CPL_DLL RegisterOGRGeoRSS();
527 void CPL_DLL RegisterOGRVFK();
528 void CPL_DLL RegisterOGRPGDump();
529 void CPL_DLL RegisterOGROSM();
530 void CPL_DLL RegisterOGRGPSBabel();
531 void CPL_DLL RegisterOGRPDS();
532 void CPL_DLL RegisterOGRWFS();
533 void CPL_DLL RegisterOGROAPIF();
534 void CPL_DLL RegisterOGRSOSI();
535 void CPL_DLL RegisterOGREDIGEO();
536 void CPL_DLL RegisterOGRSVG();
537 void CPL_DLL RegisterOGRIdrisi();
538 void CPL_DLL RegisterOGRXLS();
539 void CPL_DLL RegisterOGRODS();
540 void CPL_DLL RegisterOGRXLSX();
541 void CPL_DLL RegisterOGRElastic();
542 void CPL_DLL RegisterOGRGeoPackage();
543 void CPL_DLL RegisterOGRCarto();
544 void CPL_DLL RegisterOGRAmigoCloud();
545 void CPL_DLL RegisterOGRSXF();
546 void CPL_DLL RegisterOGROpenFileGDB();
547 void CPL_DLL RegisterOGRSelafin();
548 void CPL_DLL RegisterOGRJML();
549 void CPL_DLL RegisterOGRPLSCENES();
550 void CPL_DLL RegisterOGRCSW();
551 void CPL_DLL RegisterOGRMongoDBv3();
552 void CPL_DLL RegisterOGRVDV();
553 void CPL_DLL RegisterOGRGMLAS();
554 void CPL_DLL RegisterOGRMVT();
555 void CPL_DLL RegisterOGRNGW();
556 void CPL_DLL RegisterOGRMapML();
557 void CPL_DLL RegisterOGRLVBAG();
558 void CPL_DLL RegisterOGRHANA();
559 void CPL_DLL RegisterOGRParquet();
560 void CPL_DLL RegisterOGRArrow();
561 // @endcond
562 
563 CPL_C_END
564 
565 #endif /* ndef OGRSF_FRMTS_H_INCLUDED */
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:340
Format specific driver.
Definition: gdal_priv.h:1525
Object with metadata.
Definition: gdal_priv.h:136
Class for dataset open functions.
Definition: gdal_priv.h:269
LEGACY class.
Definition: ogrsf_frmts.h:372
Simple container for a bounding region (rectangle)
Definition: ogr_core.h:58
Definition of a feature class or feature layer.
Definition: ogr_feature.h:279
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:380
OGRGeometry * GetGeometryRef()
Fetch pointer to feature geometry.
Definition: ogrfeature.cpp:719
Definition of an attribute of an OGRFeatureDefn.
Definition: ogr_feature.h:99
Definition of a geometry field of an OGRFeatureDefn.
Definition: ogr_feature.h:202
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:327
Template class offering a GetNextFeature() implementation relying on GetNextRawFeature()
Definition: ogrsf_frmts.h:311
OGRFeature * GetNextFeature()
Implement OGRLayer::GetNextFeature(), relying on BaseLayer::GetNextRawFeature()
Definition: ogrsf_frmts.h:318
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:71
friend FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition: ogrsf_frmts.h:289
virtual OGRFeature * GetNextFeature()=0
Fetch the next available feature from this layer.
static OGRLayer * FromHandle(OGRLayerH hLayer)
Convert a OGRLayerH to a OGRLayer*.
Definition: ogrsf_frmts.h:262
static OGRLayerH ToHandle(OGRLayer *poLayer)
Convert a OGRLayer* to a OGRLayerH.
Definition: ogrsf_frmts.h:256
friend FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition: ogrsf_frmts.h:294
virtual void ResetReading()=0
Reset feature reading to start on the first feature.
LEGACY class.
Definition: ogrsf_frmts.h:440
LEGACY class.
Definition: ogrsf_frmts.h:405
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:158
This class represents a style table.
Definition: ogr_featurestyle.h:85
CPLErr
Error category.
Definition: cpl_error.h:53
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:303
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:301
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:927
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:866
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:230
C++ GDAL entry points.
void * OGRLayerH
Opaque type for a layer (OGRLayer)
Definition: ogr_api.h:590
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:369
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:341
Simple feature classes.
std::unique_ptr< OGRFeature, OGRFeatureUniquePtrDeleter > OGRFeatureUniquePtr
Unique pointer type for OGRFeature.
Definition: ogr_feature.h:837
Simple feature style classes.
std::unique_ptr< OGRLayer > OGRLayerUniquePtr
Unique pointer type for OGRLayer.
Definition: ogrsf_frmts.h:299
OGRLayer::FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition: ogrsf_frmts.h:289
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition: ogrsf_frmts.h:294