GDAL
ogr_feature.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: ogr_feature.h 4fb0702109acae09624f7ff9436ddcd456cb09e3 2020-07-01 19:14:52 +1000 Nyall Dawson $
3  *
4  * Project: OpenGIS Simple Features Reference Implementation
5  * Purpose: Class for representing a whole feature, and layer schemas.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 1999, Les Technologies SoftMap Inc.
10  * Copyright (c) 2008-2013, 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 OGR_FEATURE_H_INCLUDED
32 #define OGR_FEATURE_H_INCLUDED
33 
34 #include "cpl_atomic_ops.h"
35 #include "ogr_featurestyle.h"
36 #include "ogr_geometry.h"
37 
38 #include <exception>
39 #include <memory>
40 #include <string>
41 #include <vector>
42 
49 #ifndef DEFINE_OGRFeatureH
50 
51 #define DEFINE_OGRFeatureH
52 
53 #ifdef DEBUG
54 typedef struct OGRFieldDefnHS *OGRFieldDefnH;
55 typedef struct OGRFeatureDefnHS *OGRFeatureDefnH;
56 typedef struct OGRFeatureHS *OGRFeatureH;
57 typedef struct OGRStyleTableHS *OGRStyleTableH;
58 #else
59 
60 typedef void *OGRFieldDefnH;
62 typedef void *OGRFeatureDefnH;
64 typedef void *OGRFeatureH;
66 typedef void *OGRStyleTableH;
67 #endif
68 
69 typedef struct OGRGeomFieldDefnHS *OGRGeomFieldDefnH;
70 #endif /* DEFINE_OGRFeatureH */
71 
72 class OGRStyleTable;
73 
74 /************************************************************************/
75 /* OGRFieldDefn */
76 /************************************************************************/
77 
94 class CPL_DLL OGRFieldDefn
95 {
96  private:
97  char *pszName;
98  char *pszAlternativeName;
99  OGRFieldType eType;
100  OGRJustification eJustify;
101  int nWidth; // Zero is variable.
102  int nPrecision;
103  char *pszDefault;
104 
105  int bIgnore;
106  OGRFieldSubType eSubType;
107 
108  int bNullable;
109  int bUnique;
110 
111  public:
112  OGRFieldDefn( const char *, OGRFieldType );
113  explicit OGRFieldDefn( const OGRFieldDefn * );
114  ~OGRFieldDefn();
115 
116  void SetName( const char * );
117  const char *GetNameRef() const { return pszName; }
118 
119  void SetAlternativeName( const char * );
120  const char *GetAlternativeNameRef() const { return pszAlternativeName; }
121 
122  OGRFieldType GetType() const { return eType; }
123  void SetType( OGRFieldType eTypeIn );
124  static const char *GetFieldTypeName( OGRFieldType );
125 
126  OGRFieldSubType GetSubType() const { return eSubType; }
127  void SetSubType( OGRFieldSubType eSubTypeIn );
128  static const char *GetFieldSubTypeName( OGRFieldSubType );
129 
130  OGRJustification GetJustify() const { return eJustify; }
131  void SetJustify( OGRJustification eJustifyIn )
132  { eJustify = eJustifyIn; }
133 
134  int GetWidth() const { return nWidth; }
135  void SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
136 
137  int GetPrecision() const { return nPrecision; }
138  void SetPrecision( int nPrecisionIn )
139  { nPrecision = nPrecisionIn; }
140 
141  void Set( const char *, OGRFieldType, int = 0, int = 0,
142  OGRJustification = OJUndefined );
143 
144  void SetDefault( const char* );
145  const char *GetDefault() const;
146  int IsDefaultDriverSpecific() const;
147 
148  int IsIgnored() const { return bIgnore; }
149  void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
150 
151  int IsNullable() const { return bNullable; }
152  void SetNullable( int bNullableIn ) { bNullable = bNullableIn; }
153 
154  int IsUnique() const { return bUnique; }
155  void SetUnique( int bUniqueIn ) { bUnique = bUniqueIn; }
156 
157  int IsSame( const OGRFieldDefn * ) const;
158 
162  static inline OGRFieldDefnH ToHandle(OGRFieldDefn* poFieldDefn)
163  { return reinterpret_cast<OGRFieldDefnH>(poFieldDefn); }
164 
168  static inline OGRFieldDefn* FromHandle(OGRFieldDefnH hFieldDefn)
169  { return reinterpret_cast<OGRFieldDefn*>(hFieldDefn); }
170  private:
172 };
173 
174 /************************************************************************/
175 /* OGRGeomFieldDefn */
176 /************************************************************************/
177 
192 class CPL_DLL OGRGeomFieldDefn
193 {
194 protected:
196  char *pszName = nullptr;
197  OGRwkbGeometryType eGeomType = wkbUnknown; /* all values possible except wkbNone */
198  mutable OGRSpatialReference* poSRS = nullptr;
199 
200  int bIgnore = false;
201  mutable int bNullable = true;
202 
203  void Initialize( const char *, OGRwkbGeometryType );
205 
206 public:
207  OGRGeomFieldDefn( const char *pszNameIn,
208  OGRwkbGeometryType eGeomTypeIn );
209  explicit OGRGeomFieldDefn( const OGRGeomFieldDefn * );
210  virtual ~OGRGeomFieldDefn();
211 
212  void SetName( const char * );
213  const char *GetNameRef() const { return pszName; }
214 
215  OGRwkbGeometryType GetType() const { return eGeomType; }
216  void SetType( OGRwkbGeometryType eTypeIn );
217 
218  virtual OGRSpatialReference* GetSpatialRef() const;
219  void SetSpatialRef( OGRSpatialReference* poSRSIn );
220 
221  int IsIgnored() const { return bIgnore; }
222  void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
223 
224  int IsNullable() const { return bNullable; }
225  void SetNullable( int bNullableIn )
226  { bNullable = bNullableIn; }
227 
228  int IsSame( const OGRGeomFieldDefn * ) const;
229 
233  static inline OGRGeomFieldDefnH ToHandle(OGRGeomFieldDefn* poGeomFieldDefn)
234  { return reinterpret_cast<OGRGeomFieldDefnH>(poGeomFieldDefn); }
235 
239  static inline OGRGeomFieldDefn* FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)
240  { return reinterpret_cast<OGRGeomFieldDefn*>(hGeomFieldDefn); }
241  private:
243 };
244 
245 /************************************************************************/
246 /* OGRFeatureDefn */
247 /************************************************************************/
248 
269 class CPL_DLL OGRFeatureDefn
270 {
271  protected:
273  volatile int nRefCount;
274 
275  mutable int nFieldCount;
276  mutable OGRFieldDefn **papoFieldDefn;
277 
278  mutable int nGeomFieldCount;
279  mutable OGRGeomFieldDefn **papoGeomFieldDefn;
280 
281  char *pszFeatureClassName;
282 
283  int bIgnoreStyle;
285 
286  public:
287  explicit OGRFeatureDefn( const char * pszName = nullptr );
288  virtual ~OGRFeatureDefn();
289 
290  void SetName( const char* pszName );
291  virtual const char *GetName() const;
292 
293  virtual int GetFieldCount() const;
294  virtual OGRFieldDefn *GetFieldDefn( int i );
295  virtual const OGRFieldDefn *GetFieldDefn( int i ) const;
296  virtual int GetFieldIndex( const char * ) const;
297  int GetFieldIndexCaseSensitive( const char * ) const;
298 
299  virtual void AddFieldDefn( OGRFieldDefn * );
300  virtual OGRErr DeleteFieldDefn( int iField );
301  virtual OGRErr ReorderFieldDefns( int* panMap );
302 
303  virtual int GetGeomFieldCount() const;
304  virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
305  virtual const OGRGeomFieldDefn *GetGeomFieldDefn( int i ) const;
306  virtual int GetGeomFieldIndex( const char * ) const;
307 
308  virtual void AddGeomFieldDefn( OGRGeomFieldDefn *,
309  int bCopy = TRUE );
310  virtual OGRErr DeleteGeomFieldDefn( int iGeomField );
311 
312  virtual OGRwkbGeometryType GetGeomType() const;
313  virtual void SetGeomType( OGRwkbGeometryType );
314 
315  virtual OGRFeatureDefn *Clone() const;
316 
317  int Reference() { return CPLAtomicInc(&nRefCount); }
318  int Dereference() { return CPLAtomicDec(&nRefCount); }
319  int GetReferenceCount() const { return nRefCount; }
320  void Release();
321 
322  virtual int IsGeometryIgnored() const;
323  virtual void SetGeometryIgnored( int bIgnore );
324  virtual int IsStyleIgnored() const { return bIgnoreStyle; }
325  virtual void SetStyleIgnored( int bIgnore )
326  { bIgnoreStyle = bIgnore; }
327 
328  virtual int IsSame( const OGRFeatureDefn * poOtherFeatureDefn ) const;
329 
331  void ReserveSpaceForFields(int nFieldCountIn);
333 
334  std::vector<int> ComputeMapForSetFrom( const OGRFeatureDefn* poSrcFDefn,
335  bool bForgiving = true ) const;
336 
337  static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = nullptr );
338  static void DestroyFeatureDefn( OGRFeatureDefn * );
339 
343  static inline OGRFeatureDefnH ToHandle(OGRFeatureDefn* poFeatureDefn)
344  { return reinterpret_cast<OGRFeatureDefnH>(poFeatureDefn); }
345 
349  static inline OGRFeatureDefn* FromHandle(OGRFeatureDefnH hFeatureDefn)
350  { return reinterpret_cast<OGRFeatureDefn*>(hFeatureDefn); }
351 
352  private:
354 };
355 
356 /************************************************************************/
357 /* OGRFeature */
358 /************************************************************************/
359 
364 class CPL_DLL OGRFeature
365 {
366  private:
367 
368  GIntBig nFID;
369  OGRFeatureDefn *poDefn;
370  OGRGeometry **papoGeometries;
371  OGRField *pauFields;
372  char *m_pszNativeData;
373  char *m_pszNativeMediaType;
374 
375  bool SetFieldInternal( int i, OGRField * puValue );
376 
377  protected:
379  mutable char *m_pszStyleString;
380  mutable OGRStyleTable *m_poStyleTable;
381  mutable char *m_pszTmpFieldValue;
383 
384  bool CopySelfTo( OGRFeature *poNew ) const;
385 
386  public:
387  explicit OGRFeature( OGRFeatureDefn * );
388  virtual ~OGRFeature();
389 
391  class CPL_DLL FieldValue
392  {
393  friend class OGRFeature;
394  struct Private;
395  std::unique_ptr<Private> m_poPrivate;
396 
397  FieldValue(OGRFeature* poFeature, int iFieldIndex);
398  FieldValue(const OGRFeature* poFeature, int iFieldIndex);
399  FieldValue(const FieldValue& oOther) = delete;
400 
401  public:
403  ~FieldValue();
405 
407  FieldValue& operator= (const FieldValue& oOther);
409  FieldValue& operator= (int nVal);
411  FieldValue& operator= (GIntBig nVal);
413  FieldValue& operator= (double dfVal);
415  FieldValue& operator= (const char *pszVal);
417  FieldValue& operator= (const std::string& osVal);
419  FieldValue& operator= (const std::vector<int>& oArray);
421  FieldValue& operator= (const std::vector<GIntBig>& oArray);
423  FieldValue& operator= (const std::vector<double>& oArray);
425  FieldValue& operator= (const std::vector<std::string>& oArray);
427  FieldValue& operator= (CSLConstList papszValues);
429  void SetNull();
431  void clear();
433  void Unset() { clear(); }
435  void SetDateTime(int nYear, int nMonth, int nDay,
436  int nHour=0, int nMinute=0, float fSecond=0.f,
437  int nTZFlag = 0 );
438 
440  int GetIndex() const;
442  const OGRFieldDefn* GetDefn() const;
444  const char* GetName() const { return GetDefn()->GetNameRef(); }
446  OGRFieldType GetType() const { return GetDefn()->GetType(); }
448  OGRFieldSubType GetSubType() const { return GetDefn()->GetSubType(); }
449 
451  // cppcheck-suppress functionStatic
452  bool empty() const { return IsUnset(); }
453 
455  // cppcheck-suppress functionStatic
456  bool IsUnset() const;
457 
459  // cppcheck-suppress functionStatic
460  bool IsNull() const;
461 
463  const OGRField *GetRawValue() const;
464 
468  // cppcheck-suppress functionStatic
469  int GetInteger() const { return GetRawValue()->Integer; }
470 
474  // cppcheck-suppress functionStatic
475  GIntBig GetInteger64() const { return GetRawValue()->Integer64; }
476 
480  // cppcheck-suppress functionStatic
481  double GetDouble() const { return GetRawValue()->Real; }
482 
486  // cppcheck-suppress functionStatic
487  const char* GetString() const { return GetRawValue()->String; }
488 
490  bool GetDateTime( int *pnYear, int *pnMonth,
491  int *pnDay,
492  int *pnHour, int *pnMinute,
493  float *pfSecond,
494  int *pnTZFlag ) const;
495 
497  operator int () const { return GetAsInteger(); }
499  operator GIntBig() const { return GetAsInteger64(); }
501  operator double () const { return GetAsDouble(); }
503  operator const char*() const { return GetAsString(); }
505  operator const std::vector<int>& () const { return GetAsIntegerList(); }
507  operator const std::vector<GIntBig>& () const { return GetAsInteger64List(); }
509  operator const std::vector<double>& () const { return GetAsDoubleList(); }
511  operator const std::vector<std::string>& () const { return GetAsStringList(); }
513  operator CSLConstList () const;
514 
516  int GetAsInteger() const;
518  GIntBig GetAsInteger64() const;
520  double GetAsDouble() const;
522  const char* GetAsString() const;
524  const std::vector<int>& GetAsIntegerList() const;
526  const std::vector<GIntBig>& GetAsInteger64List() const;
528  const std::vector<double>& GetAsDoubleList() const;
530  const std::vector<std::string>& GetAsStringList() const;
531  };
532 
534  class CPL_DLL ConstFieldIterator
535  {
536  friend class OGRFeature;
537  struct Private;
538  std::unique_ptr<Private> m_poPrivate;
539 
540  ConstFieldIterator(const OGRFeature* poSelf, int nPos);
541 
542  public:
544  ConstFieldIterator(ConstFieldIterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
546  const FieldValue& operator*() const;
547  ConstFieldIterator& operator++();
548  bool operator!=(const ConstFieldIterator& it) const;
550  };
551 
568  ConstFieldIterator begin() const;
570  ConstFieldIterator end() const;
571 
572  const FieldValue operator[](int iField) const;
573  FieldValue operator[](int iField);
574 
576  class FieldNotFoundException: public std::exception {};
577 
578  const FieldValue operator[](const char* pszFieldName) const;
579  FieldValue operator[](const char* pszFieldName);
580 
581  OGRFeatureDefn *GetDefnRef() { return poDefn; }
582  const OGRFeatureDefn *GetDefnRef() const { return poDefn; }
583 
584  OGRErr SetGeometryDirectly( OGRGeometry * );
585  OGRErr SetGeometry( const OGRGeometry * );
586  OGRGeometry *GetGeometryRef();
587  const OGRGeometry *GetGeometryRef() const;
588  OGRGeometry *StealGeometry() CPL_WARN_UNUSED_RESULT;
589 
590  int GetGeomFieldCount() const
591  { return poDefn->GetGeomFieldCount(); }
593  { return poDefn->GetGeomFieldDefn(iField); }
594  const OGRGeomFieldDefn *GetGeomFieldDefnRef( int iField ) const
595  { return poDefn->GetGeomFieldDefn(iField); }
596  int GetGeomFieldIndex( const char * pszName ) const
597  { return poDefn->GetGeomFieldIndex(pszName); }
598 
599  OGRGeometry* GetGeomFieldRef( int iField );
600  const OGRGeometry* GetGeomFieldRef( int iField ) const;
601  OGRGeometry* StealGeometry( int iField );
602  OGRGeometry* GetGeomFieldRef( const char* pszFName );
603  const OGRGeometry* GetGeomFieldRef( const char* pszFName ) const;
604  OGRErr SetGeomFieldDirectly( int iField, OGRGeometry * );
605  OGRErr SetGeomField( int iField, const OGRGeometry * );
606 
607  OGRFeature *Clone() const CPL_WARN_UNUSED_RESULT;
608  virtual OGRBoolean Equal( const OGRFeature * poFeature ) const;
609 
610  int GetFieldCount() const
611  { return poDefn->GetFieldCount(); }
612  const OGRFieldDefn *GetFieldDefnRef( int iField ) const
613  { return poDefn->GetFieldDefn(iField); }
615  { return poDefn->GetFieldDefn(iField); }
616  int GetFieldIndex( const char * pszName ) const
617  { return poDefn->GetFieldIndex(pszName); }
618 
619  int IsFieldSet( int iField ) const;
620 
621  void UnsetField( int iField );
622 
623  bool IsFieldNull( int iField ) const;
624 
625  void SetFieldNull( int iField );
626 
627  bool IsFieldSetAndNotNull( int iField ) const;
628 
629  OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
630  const OGRField *GetRawFieldRef( int i ) const { return pauFields + i; }
631 
632  int GetFieldAsInteger( int i ) const;
633  GIntBig GetFieldAsInteger64( int i ) const;
634  double GetFieldAsDouble( int i ) const;
635  const char *GetFieldAsString( int i ) const;
636  const int *GetFieldAsIntegerList( int i, int *pnCount ) const;
637  const GIntBig *GetFieldAsInteger64List( int i, int *pnCount ) const;
638  const double *GetFieldAsDoubleList( int i, int *pnCount ) const;
639  char **GetFieldAsStringList( int i ) const;
640  GByte *GetFieldAsBinary( int i, int *pnCount ) const;
641  int GetFieldAsDateTime( int i,
642  int *pnYear, int *pnMonth,
643  int *pnDay,
644  int *pnHour, int *pnMinute,
645  int *pnSecond,
646  int *pnTZFlag ) const;
647  int GetFieldAsDateTime( int i,
648  int *pnYear, int *pnMonth,
649  int *pnDay,
650  int *pnHour, int *pnMinute,
651  float *pfSecond,
652  int *pnTZFlag ) const;
653  char *GetFieldAsSerializedJSon( int i ) const;
654 
655  int GetFieldAsInteger( const char *pszFName ) const
656  { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
657  GIntBig GetFieldAsInteger64( const char *pszFName ) const
658  { return GetFieldAsInteger64( GetFieldIndex(pszFName) ); }
659  double GetFieldAsDouble( const char *pszFName ) const
660  { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
661  const char *GetFieldAsString( const char *pszFName ) const
662  { return GetFieldAsString( GetFieldIndex(pszFName) ); }
663  const int *GetFieldAsIntegerList( const char *pszFName,
664  int *pnCount ) const
665  { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
666  pnCount ); }
667  const GIntBig *GetFieldAsInteger64List( const char *pszFName,
668  int *pnCount ) const
669  { return GetFieldAsInteger64List( GetFieldIndex(pszFName),
670  pnCount ); }
671  const double *GetFieldAsDoubleList( const char *pszFName,
672  int *pnCount ) const
673  { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
674  pnCount ); }
675  char **GetFieldAsStringList( const char *pszFName ) const
676  { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
677 
678  void SetField( int i, int nValue );
679  void SetField( int i, GIntBig nValue );
680  void SetField( int i, double dfValue );
681  void SetField( int i, const char * pszValue );
682  void SetField( int i, int nCount, const int * panValues );
683  void SetField( int i, int nCount,
684  const GIntBig * panValues );
685  void SetField( int i, int nCount, const double * padfValues );
686  void SetField( int i, const char * const * papszValues );
687  void SetField( int i, OGRField * puValue );
688  void SetField( int i, int nCount, const void * pabyBinary );
689  void SetField( int i, int nYear, int nMonth, int nDay,
690  int nHour=0, int nMinute=0, float fSecond=0.f,
691  int nTZFlag = 0 );
692 
693  void SetField( const char *pszFName, int nValue )
694  { SetField( GetFieldIndex(pszFName), nValue ); }
695  void SetField( const char *pszFName, GIntBig nValue )
696  { SetField( GetFieldIndex(pszFName), nValue ); }
697  void SetField( const char *pszFName, double dfValue )
698  { SetField( GetFieldIndex(pszFName), dfValue ); }
699  void SetField( const char *pszFName, const char * pszValue )
700  { SetField( GetFieldIndex(pszFName), pszValue ); }
701  void SetField( const char *pszFName, int nCount,
702  const int * panValues )
703  { SetField(GetFieldIndex(pszFName),nCount,panValues); }
704  void SetField( const char *pszFName, int nCount,
705  const GIntBig * panValues )
706  { SetField(GetFieldIndex(pszFName),nCount,panValues); }
707  void SetField( const char *pszFName, int nCount,
708  const double * padfValues )
709  {SetField(GetFieldIndex(pszFName),nCount,padfValues); }
710  void SetField( const char *pszFName, const char * const * papszValues )
711  { SetField( GetFieldIndex(pszFName), papszValues); }
712  void SetField( const char *pszFName, OGRField * puValue )
713  { SetField( GetFieldIndex(pszFName), puValue ); }
714  void SetField( const char *pszFName,
715  int nYear, int nMonth, int nDay,
716  int nHour=0, int nMinute=0, float fSecond=0.f,
717  int nTZFlag = 0 )
718  { SetField( GetFieldIndex(pszFName),
719  nYear, nMonth, nDay,
720  nHour, nMinute, fSecond, nTZFlag ); }
721 
722  GIntBig GetFID() const { return nFID; }
723  virtual OGRErr SetFID( GIntBig nFIDIn );
724 
725  void DumpReadable( FILE *, char** papszOptions = nullptr ) const;
726 
727  OGRErr SetFrom( const OGRFeature *, int = TRUE );
728  OGRErr SetFrom( const OGRFeature *, const int *, int = TRUE );
729  OGRErr SetFieldsFrom( const OGRFeature *, const int *, int = TRUE );
730 
732  OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
733  const int *panRemapSource );
734  void AppendField();
735  OGRErr RemapGeomFields( OGRFeatureDefn *poNewDefn,
736  const int *panRemapSource );
738 
739  int Validate( int nValidateFlags,
740  int bEmitError ) const;
741  void FillUnsetWithDefault( int bNotNullableOnly,
742  char** papszOptions );
743 
744  virtual const char *GetStyleString() const;
745  virtual void SetStyleString( const char * );
746  virtual void SetStyleStringDirectly( char * );
747 
751  virtual OGRStyleTable *GetStyleTable() const { return m_poStyleTable; } /* f.i.x.m.e: add a const qualifier for return type */
752  virtual void SetStyleTable( OGRStyleTable *poStyleTable );
753  virtual void SetStyleTableDirectly( OGRStyleTable *poStyleTable );
754 
755  const char *GetNativeData() const { return m_pszNativeData; }
756  const char *GetNativeMediaType() const
757  { return m_pszNativeMediaType; }
758  void SetNativeData( const char* pszNativeData );
759  void SetNativeMediaType( const char* pszNativeMediaType );
760 
761  static OGRFeature *CreateFeature( OGRFeatureDefn * );
762  static void DestroyFeature( OGRFeature * );
763 
767  static inline OGRFeatureH ToHandle(OGRFeature* poFeature)
768  { return reinterpret_cast<OGRFeatureH>(poFeature); }
769 
773  static inline OGRFeature* FromHandle(OGRFeatureH hFeature)
774  { return reinterpret_cast<OGRFeature*>(hFeature); }
775 
776  private:
778 };
779 
781 struct CPL_DLL OGRFeatureUniquePtrDeleter
782 {
783  void operator()(OGRFeature*) const;
784 };
786 
790 typedef std::unique_ptr<OGRFeature, OGRFeatureUniquePtrDeleter> OGRFeatureUniquePtr;
791 
793 
794 inline OGRFeature::ConstFieldIterator begin(const OGRFeature* poFeature) { return poFeature->begin(); }
796 inline OGRFeature::ConstFieldIterator end(const OGRFeature* poFeature) { return poFeature->end(); }
797 
799 inline OGRFeature::ConstFieldIterator begin(const OGRFeatureUniquePtr& poFeature) { return poFeature->begin(); }
801 inline OGRFeature::ConstFieldIterator end(const OGRFeatureUniquePtr& poFeature) { return poFeature->end(); }
802 
804 
805 /************************************************************************/
806 /* OGRFeatureQuery */
807 /************************************************************************/
808 
810 class OGRLayer;
811 class swq_expr_node;
812 class swq_custom_func_registrar;
813 
814 class CPL_DLL OGRFeatureQuery
815 {
816  private:
817  OGRFeatureDefn *poTargetDefn;
818  void *pSWQExpr;
819 
820  char **FieldCollector( void *, char ** );
821 
822  GIntBig *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *,
823  GIntBig& nFIDCount );
824 
825  int CanUseIndex( swq_expr_node*, OGRLayer * );
826 
827  OGRErr Compile( OGRLayer *, OGRFeatureDefn*, const char *,
828  int bCheck,
829  swq_custom_func_registrar* poCustomFuncRegistrar );
830 
831  CPL_DISALLOW_COPY_ASSIGN(OGRFeatureQuery)
832 
833  public:
834  OGRFeatureQuery();
835  ~OGRFeatureQuery();
836 
837  OGRErr Compile( OGRLayer *, const char *,
838  int bCheck = TRUE,
839  swq_custom_func_registrar*
840  poCustomFuncRegistrar = nullptr );
841  OGRErr Compile( OGRFeatureDefn *, const char *,
842  int bCheck = TRUE,
843  swq_custom_func_registrar*
844  poCustomFuncRegistrar = nullptr );
845  int Evaluate( OGRFeature * );
846 
847  GIntBig *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
848 
849  int CanUseIndex( OGRLayer * );
850 
851  char **GetUsedFields();
852 
853  void *GetSWQExpr() { return pSWQExpr; }
854 };
856 
857 #endif /* ndef OGR_FEATURE_H_INCLUDED */
MAX
#define MAX(a, b)
Macro to compute the maximum of 2 values.
Definition: cpl_port.h:414
OGRFeature::GetFieldAsDoubleList
const double * GetFieldAsDoubleList(const char *pszFName, int *pnCount) const
Fetch field value as a list of doubles.
Definition: ogr_feature.h:671
OGRFeature::FieldValue::GetString
const char * GetString() const
Return the string value.
Definition: ogr_feature.h:487
OGRFeatureDefn::FromHandle
static OGRFeatureDefn * FromHandle(OGRFeatureDefnH hFeatureDefn)
Convert a OGRFeatureDefnH to a OGRFeatureDefn*.
Definition: ogr_feature.h:349
OGRFeature::FieldValue::GetSubType
OGRFieldSubType GetSubType() const
Return field subtype.
Definition: ogr_feature.h:448
OGRFeatureDefn::IsStyleIgnored
virtual int IsStyleIgnored() const
Determine whether the style can be omitted when fetching features.
Definition: ogr_feature.h:324
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
OGRFieldDefnH
void * OGRFieldDefnH
Opaque type for a field definition (OGRFieldDefn)
Definition: ogr_feature.h:60
OGRFeature::FieldNotFoundException
Exception raised by operator[](const char*) when a field is not found.
Definition: ogr_feature.h:576
OGRFeature::SetField
void SetField(const char *pszFName, GIntBig nValue)
Set field to 64 bit integer value.
Definition: ogr_feature.h:695
OGRFeature::GetFieldAsStringList
char ** GetFieldAsStringList(const char *pszFName) const
Fetch field value as a list of strings.
Definition: ogr_feature.h:675
OGRFeature::ConstFieldIterator
Field value iterator class.
Definition: ogr_feature.h:535
OGRFeature::GetStyleTable
virtual OGRStyleTable * GetStyleTable() const
Return style table.
Definition: ogr_feature.h:751
OGRFieldDefn::SetJustify
void SetJustify(OGRJustification eJustifyIn)
Set the justification for this field.
Definition: ogr_feature.h:131
begin
OGRLayer::FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition: ogrsf_frmts.h:287
OGRFeature::FieldValue::GetType
OGRFieldType GetType() const
Return field type.
Definition: ogr_feature.h:446
OGRGeomFieldDefn::SetIgnored
void SetIgnored(int bIgnoreIn)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:222
OGRStyleTable
This class represents a style table.
Definition: ogr_featurestyle.h:85
OGRFieldDefn::SetIgnored
void SetIgnored(int bIgnoreIn)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:149
OGRFeature::ToHandle
static OGRFeatureH ToHandle(OGRFeature *poFeature)
Convert a OGRFeature* to a OGRFeatureH.
Definition: ogr_feature.h:767
OGRFeature::FieldValue::GetName
const char * GetName() const
Return field name.
Definition: ogr_feature.h:444
OGRFeatureDefn::GetGeomFieldIndex
virtual int GetGeomFieldIndex(const char *) const
Find geometry field by name.
Definition: ogrfeaturedefn.cpp:916
OGRFeature::GetFieldDefnRef
OGRFieldDefn * GetFieldDefnRef(int iField)
Fetch definition for this field.
Definition: ogr_feature.h:614
OGRFieldDefn::GetWidth
int GetWidth() const
Get the formatting width for this field.
Definition: ogr_feature.h:134
OGRSpatialReference
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:158
OGRGeomFieldDefnH
struct OGRGeomFieldDefnHS * OGRGeomFieldDefnH
Opaque type for a geometry field definition (OGRGeomFieldDefn)
Definition: ogr_feature.h:69
OGRStyleTableH
void * OGRStyleTableH
Opaque type for a style table (OGRStyleTable)
Definition: ogr_feature.h:66
OGRFeatureH
void * OGRFeatureH
Opaque type for a feature (OGRFeature)
Definition: ogr_feature.h:64
OGRFeature::GetFieldAsDouble
double GetFieldAsDouble(const char *pszFName) const
Fetch field value as a double.
Definition: ogr_feature.h:659
OGRGeometry
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:326
OGRFeature::GetGeomFieldDefnRef
OGRGeomFieldDefn * GetGeomFieldDefnRef(int iField)
Fetch definition for this geometry field.
Definition: ogr_feature.h:592
OGRLayer
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:71
OGRFeature::FieldValue::empty
bool empty() const
Return whether the field value is unset/empty.
Definition: ogr_feature.h:452
OGRGeomFieldDefn::ToHandle
static OGRGeomFieldDefnH ToHandle(OGRGeomFieldDefn *poGeomFieldDefn)
Convert a OGRGeomFieldDefn* to a OGRGeomFieldDefnH.
Definition: ogr_feature.h:233
OGRFieldDefn::GetPrecision
int GetPrecision() const
Get the formatting precision for this field.
Definition: ogr_feature.h:137
ogr_geometry.h
Simple feature geometry classes.
OGRGeomFieldDefn::GetNameRef
const char * GetNameRef() const
Fetch name of this field.
Definition: ogr_feature.h:213
OGRGeomFieldDefn::IsIgnored
int IsIgnored() const
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:221
OGRFeatureUniquePtr
std::unique_ptr< OGRFeature, OGRFeatureUniquePtrDeleter > OGRFeatureUniquePtr
Unique pointer type for OGRFeature.
Definition: ogr_feature.h:790
OGRFeatureH
void * OGRFeatureH
Opaque type for a feature (OGRFeature)
Definition: ogr_api.h:314
OGRFeature::GetGeomFieldIndex
int GetGeomFieldIndex(const char *pszName) const
Fetch the geometry field index given geometry field name.
Definition: ogr_feature.h:596
OGRFieldDefn::GetNameRef
const char * GetNameRef() const
Fetch name of this field.
Definition: ogr_feature.h:117
OGRBoolean
int OGRBoolean
Type for a OGR boolean.
Definition: ogr_core.h:334
OGRFeatureDefnH
void * OGRFeatureDefnH
Opaque type for a feature definition (OGRFeatureDefn)
Definition: ogr_api.h:312
OGRFieldDefn::SetPrecision
void SetPrecision(int nPrecisionIn)
Set the formatting precision for this field in characters.
Definition: ogr_feature.h:138
OGRFeatureDefn::GetFieldDefn
virtual OGRFieldDefn * GetFieldDefn(int i)
Fetch field definition.
Definition: ogrfeaturedefn.cpp:330
OGRFeature::FieldValue
Field value.
Definition: ogr_feature.h:392
OGRGeomFieldDefnH
struct OGRGeomFieldDefnHS * OGRGeomFieldDefnH
Opaque type for a geometry field definition (OGRGeomFieldDefn)
Definition: ogr_api.h:319
OGRFeature::begin
ConstFieldIterator begin() const
Return begin of field value iterator.
Definition: ogrfeature.cpp:7064
OGRFieldDefn::IsUnique
int IsUnique() const
Return whether this field has a unique constraint.
Definition: ogr_feature.h:154
OGRField
OGRFeature field attribute value union.
Definition: ogr_core.h:728
OGRFeatureDefn::GetGeomFieldDefn
virtual OGRGeomFieldDefn * GetGeomFieldDefn(int i)
Fetch geometry field definition.
Definition: ogrfeaturedefn.cpp:681
OGRFeature::SetField
void SetField(const char *pszFName, int nCount, const double *padfValues)
Set field to list of doubles value.
Definition: ogr_feature.h:707
OGRFeature::GetFieldIndex
int GetFieldIndex(const char *pszName) const
Fetch the field index given field name.
Definition: ogr_feature.h:616
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1216
OGRFeature::FieldValue::Unset
void Unset()
Unset the field.
Definition: ogr_feature.h:433
OGRFeatureDefn::GetFieldCount
virtual int GetFieldCount() const
Fetch number of fields on this feature.
Definition: ogrfeaturedefn.cpp:286
OGRFeature::SetField
void SetField(const char *pszFName, const char *pszValue)
Set field to string value.
Definition: ogr_feature.h:699
OGRFeature::SetField
void SetField(const char *pszFName, int nYear, int nMonth, int nDay, int nHour=0, int nMinute=0, float fSecond=0.f, int nTZFlag=0)
Set field to date.
Definition: ogr_feature.h:714
OGRFieldDefn::FromHandle
static OGRFieldDefn * FromHandle(OGRFieldDefnH hFieldDefn)
Convert a OGRFieldDefnH to a OGRFieldDefn*.
Definition: ogr_feature.h:168
OGRFeature::GetDefnRef
const OGRFeatureDefn * GetDefnRef() const
Fetch feature definition.
Definition: ogr_feature.h:582
OGRFieldDefn
Definition of an attribute of an OGRFeatureDefn.
Definition: ogr_feature.h:95
OGRGeomFieldDefn::IsNullable
int IsNullable() const
Return whether this geometry field can receive null values.
Definition: ogr_feature.h:224
ogr_featurestyle.h
Simple feature style classes.
OGRFeatureDefn::SetStyleIgnored
virtual void SetStyleIgnored(int bIgnore)
Set whether the style can be omitted when fetching features.
Definition: ogr_feature.h:325
OGRFieldDefn::SetUnique
void SetUnique(int bUniqueIn)
Set whether this field has a unique constraint.
Definition: ogr_feature.h:155
OGRFeature::SetField
void SetField(const char *pszFName, int nCount, const int *panValues)
Set field to list of integers value.
Definition: ogr_feature.h:701
OGRFeature::GetDefnRef
OGRFeatureDefn * GetDefnRef()
Fetch feature definition.
Definition: ogr_feature.h:581
OGRJustification
OGRJustification
Display justification for field values.
Definition: ogr_core.h:688
OGRFieldDefnH
void * OGRFieldDefnH
Opaque type for a field definition (OGRFieldDefn)
Definition: ogr_api.h:310
OGRGeomFieldDefn
Definition of a geometry field of an OGRFeatureDefn.
Definition: ogr_feature.h:193
OGRFeature::FieldValue::GetDouble
double GetDouble() const
Return the double value.
Definition: ogr_feature.h:481
OGRFeature::GetFieldAsInteger64List
const GIntBig * GetFieldAsInteger64List(const char *pszFName, int *pnCount) const
Fetch field value as a list of 64 bit integers.
Definition: ogr_feature.h:667
OGRFeature::FromHandle
static OGRFeature * FromHandle(OGRFeatureH hFeature)
Convert a OGRFeatureH to a OGRFeature*.
Definition: ogr_feature.h:773
OGRFeatureDefn::Dereference
int Dereference()
Decrements the reference count by one.
Definition: ogr_feature.h:318
end
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition: ogrsf_frmts.h:292
OGRFieldDefn::GetType
OGRFieldType GetType() const
Fetch type of this field.
Definition: ogr_feature.h:122
OGRFeatureDefn::GetFieldIndex
virtual int GetFieldIndex(const char *) const
Find field by name.
Definition: ogrfeaturedefn.cpp:1218
OGRFieldDefn::GetAlternativeNameRef
const char * GetAlternativeNameRef() const
Fetch the alternative name (or "alias") for this field.
Definition: ogr_feature.h:120
OGRErr
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:318
GIntBig
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:248
OGRFeature::GetFieldDefnRef
const OGRFieldDefn * GetFieldDefnRef(int iField) const
Fetch definition for this field.
Definition: ogr_feature.h:612
OGRFeature::FieldValue::GetInteger
int GetInteger() const
Return the integer value.
Definition: ogr_feature.h:469
OGRFeature::GetRawFieldRef
const OGRField * GetRawFieldRef(int i) const
Fetch a pointer to the internal field value given the index.
Definition: ogr_feature.h:630
OGRwkbGeometryType
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:346
OGRFieldDefn::IsIgnored
int IsIgnored() const
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:148
OGRFeature::SetField
void SetField(const char *pszFName, double dfValue)
Set field to double value.
Definition: ogr_feature.h:697
CPL_WARN_UNUSED_RESULT
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:946
OGRFeature::GetRawFieldRef
OGRField * GetRawFieldRef(int i)
Fetch a pointer to the internal field value given the index.
Definition: ogr_feature.h:629
OGRFeatureDefn::Reference
int Reference()
Increments the reference count by one.
Definition: ogr_feature.h:317
OGRFeature
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:365
OGRFeature::end
ConstFieldIterator end() const
Return end of field value iterator.
Definition: ogrfeature.cpp:7069
OGRFeature::GetGeomFieldDefnRef
const OGRGeomFieldDefn * GetGeomFieldDefnRef(int iField) const
Fetch definition for this geometry field.
Definition: ogr_feature.h:594
OGRGeomFieldDefn::GetType
OGRwkbGeometryType GetType() const
Fetch geometry type of this field.
Definition: ogr_feature.h:215
OGRFeature::GetNativeMediaType
const char * GetNativeMediaType() const
Returns the native media type for the feature.
Definition: ogr_feature.h:756
OGRFieldSubType
OGRFieldSubType
List of field subtypes.
Definition: ogr_core.h:668
OGRFieldDefn::SetNullable
void SetNullable(int bNullableIn)
Set whether this field can receive null values.
Definition: ogr_feature.h:152
OGRGeomFieldDefn::SetNullable
void SetNullable(int bNullableIn)
Set whether this geometry field can receive null values.
Definition: ogr_feature.h:225
OGRGeomFieldDefn::FromHandle
static OGRGeomFieldDefn * FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)
Convert a OGRGeomFieldDefnH to a OGRGeomFieldDefn*.
Definition: ogr_feature.h:239
OGRFeatureDefn::ToHandle
static OGRFeatureDefnH ToHandle(OGRFeatureDefn *poFeatureDefn)
Convert a OGRFeatureDefn* to a OGRFeatureDefnH.
Definition: ogr_feature.h:343
OGRFieldDefn::IsNullable
int IsNullable() const
Return whether this field can receive null values.
Definition: ogr_feature.h:151
OGRFieldType
OGRFieldType
List of feature field types.
Definition: ogr_core.h:640
OGRFeatureDefnH
void * OGRFeatureDefnH
Opaque type for a feature definition (OGRFeatureDefn)
Definition: ogr_feature.h:62
OGRFeatureDefn::GetGeomFieldCount
virtual int GetGeomFieldCount() const
Fetch number of geometry fields on this feature.
Definition: ogrfeaturedefn.cpp:632
OGRFeature::GetFieldAsInteger64
GIntBig GetFieldAsInteger64(const char *pszFName) const
Fetch field value as integer 64 bit.
Definition: ogr_feature.h:657
OGRFeature::GetFieldAsString
const char * GetFieldAsString(const char *pszFName) const
Fetch field value as a string.
Definition: ogr_feature.h:661
OGRFeature::FieldValue::GetInteger64
GIntBig GetInteger64() const
Return the 64-bit integer value.
Definition: ogr_feature.h:475
OGRFeature::SetField
void SetField(const char *pszFName, OGRField *puValue)
Set field.
Definition: ogr_feature.h:712
OGRFeature::SetField
void SetField(const char *pszFName, const char *const *papszValues)
Set field to list of strings value.
Definition: ogr_feature.h:710
OGRFieldDefn::SetWidth
void SetWidth(int nWidthIn)
Set the formatting width for this field in characters.
Definition: ogr_feature.h:135
OGRFeatureDefn
Definition of a feature class or feature layer.
Definition: ogr_feature.h:270
OGRFeature::GetFieldAsInteger
int GetFieldAsInteger(const char *pszFName) const
Fetch field value as integer.
Definition: ogr_feature.h:655
OGRFeatureDefn::GetReferenceCount
int GetReferenceCount() const
Fetch current reference count.
Definition: ogr_feature.h:319
OGRFieldDefn::GetSubType
OGRFieldSubType GetSubType() const
Fetch subtype of this field.
Definition: ogr_feature.h:126
OGRFeature::SetField
void SetField(const char *pszFName, int nValue)
Set field to integer value.
Definition: ogr_feature.h:693
OGRFeature::GetFieldAsIntegerList
const int * GetFieldAsIntegerList(const char *pszFName, int *pnCount) const
Fetch field value as a list of integers.
Definition: ogr_feature.h:663
wkbUnknown
@ wkbUnknown
unknown type, non-standard
Definition: ogr_core.h:347
CPL_DISALLOW_COPY_ASSIGN
#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:1007
OGRFieldDefn::GetJustify
OGRJustification GetJustify() const
Get the justification for this field.
Definition: ogr_feature.h:130
OGRFeature::GetNativeData
const char * GetNativeData() const
Returns the native data for the feature.
Definition: ogr_feature.h:755
OGRFeature::GetFID
GIntBig GetFID() const
Get feature identifier.
Definition: ogr_feature.h:722
OGRFeature::SetField
void SetField(const char *pszFName, int nCount, const GIntBig *panValues)
Set field to list of 64 bit integers value.
Definition: ogr_feature.h:704
OGRFieldDefn::ToHandle
static OGRFieldDefnH ToHandle(OGRFieldDefn *poFieldDefn)
Convert a OGRFieldDefn* to a OGRFieldDefnH.
Definition: ogr_feature.h:162