Go to the documentation of this file.
31 #ifndef OGR_FEATURE_H_INCLUDED
32 #define OGR_FEATURE_H_INCLUDED
34 #include "cpl_atomic_ops.h"
49 #ifndef DEFINE_OGRFeatureH
51 #define DEFINE_OGRFeatureH
98 char *pszAlternativeName;
116 void SetName(
const char * );
119 void SetAlternativeName(
const char * );
132 { eJustify = eJustifyIn; }
139 { nPrecision = nPrecisionIn; }
144 void SetDefault(
const char* );
145 const char *GetDefault()
const;
146 int IsDefaultDriverSpecific()
const;
155 void SetUnique(
int bUniqueIn ) { bUnique = bUniqueIn; }
196 char *pszName =
nullptr;
201 mutable int bNullable =
true;
212 void SetName(
const char * );
226 { bNullable = bNullableIn; }
273 volatile int nRefCount;
275 mutable int nFieldCount;
278 mutable int nGeomFieldCount;
281 char *pszFeatureClassName;
290 void SetName(
const char* pszName );
291 virtual const char *GetName()
const;
293 virtual int GetFieldCount()
const;
295 virtual const OGRFieldDefn *GetFieldDefn(
int i )
const;
296 virtual int GetFieldIndex(
const char * )
const;
297 int GetFieldIndexCaseSensitive(
const char * )
const;
300 virtual OGRErr DeleteFieldDefn(
int iField );
301 virtual OGRErr ReorderFieldDefns(
int* panMap );
303 virtual int GetGeomFieldCount()
const;
306 virtual int GetGeomFieldIndex(
const char * )
const;
310 virtual OGRErr DeleteGeomFieldDefn(
int iGeomField );
322 virtual int IsGeometryIgnored()
const;
323 virtual void SetGeometryIgnored(
int bIgnore );
326 { bIgnoreStyle = bIgnore; }
328 virtual int IsSame(
const OGRFeatureDefn * poOtherFeatureDefn )
const;
331 void ReserveSpaceForFields(
int nFieldCountIn);
334 std::vector<int> ComputeMapForSetFrom(
const OGRFeatureDefn* poSrcFDefn,
335 bool bForgiving =
true )
const;
337 static OGRFeatureDefn *CreateFeatureDefn(
const char *pszName =
nullptr );
372 char *m_pszNativeData;
373 char *m_pszNativeMediaType;
375 bool SetFieldInternal(
int i,
OGRField * puValue );
379 mutable char *m_pszStyleString;
381 mutable char *m_pszTmpFieldValue;
395 std::unique_ptr<Private> m_poPrivate;
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);
435 void SetDateTime(
int nYear,
int nMonth,
int nDay,
436 int nHour=0,
int nMinute=0,
float fSecond=0.f,
440 int GetIndex()
const;
444 const char*
GetName()
const {
return GetDefn()->GetNameRef(); }
452 bool empty()
const {
return IsUnset(); }
456 bool IsUnset()
const;
463 const OGRField *GetRawValue()
const;
481 double GetDouble()
const {
return GetRawValue()->Real; }
487 const char*
GetString()
const {
return GetRawValue()->String; }
490 bool GetDateTime(
int *pnYear,
int *pnMonth,
492 int *pnHour,
int *pnMinute,
494 int *pnTZFlag )
const;
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(); }
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;
538 std::unique_ptr<Private> m_poPrivate;
572 const FieldValue operator[](
int iField)
const;
578 const FieldValue operator[](
const char* pszFieldName)
const;
579 FieldValue operator[](
const char* pszFieldName);
590 int GetGeomFieldCount()
const
600 const OGRGeometry* GetGeomFieldRef(
int iField )
const;
602 OGRGeometry* GetGeomFieldRef(
const char* pszFName );
603 const OGRGeometry* GetGeomFieldRef(
const char* pszFName )
const;
610 int GetFieldCount()
const
619 int IsFieldSet(
int iField )
const;
621 void UnsetField(
int iField );
623 bool IsFieldNull(
int iField )
const;
625 void SetFieldNull(
int iField );
627 bool IsFieldSetAndNotNull(
int iField )
const;
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,
644 int *pnHour,
int *pnMinute,
646 int *pnTZFlag )
const;
647 int GetFieldAsDateTime(
int i,
648 int *pnYear,
int *pnMonth,
650 int *pnHour,
int *pnMinute,
652 int *pnTZFlag )
const;
653 char *GetFieldAsSerializedJSon(
int i )
const;
656 {
return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
658 {
return GetFieldAsInteger64( GetFieldIndex(pszFName) ); }
660 {
return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
662 {
return GetFieldAsString( GetFieldIndex(pszFName) ); }
665 {
return GetFieldAsIntegerList( GetFieldIndex(pszFName),
669 {
return GetFieldAsInteger64List( GetFieldIndex(pszFName),
673 {
return GetFieldAsDoubleList( GetFieldIndex(pszFName),
676 {
return GetFieldAsStringList(GetFieldIndex(pszFName)); }
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,
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,
694 { SetField( GetFieldIndex(pszFName), 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 ); }
702 const int * panValues )
703 { SetField(GetFieldIndex(pszFName),nCount,panValues); }
706 { SetField(GetFieldIndex(pszFName),nCount,panValues); }
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); }
713 { SetField( GetFieldIndex(pszFName), puValue ); }
715 int nYear,
int nMonth,
int nDay,
716 int nHour=0,
int nMinute=0,
float fSecond=0.f,
718 { SetField( GetFieldIndex(pszFName),
720 nHour, nMinute, fSecond, nTZFlag ); }
725 void DumpReadable( FILE *,
char** papszOptions =
nullptr )
const;
733 const int *panRemapSource );
736 const int *panRemapSource );
739 int Validate(
int nValidateFlags,
740 int bEmitError )
const;
741 void FillUnsetWithDefault(
int bNotNullableOnly,
742 char** papszOptions );
744 virtual const char *GetStyleString()
const;
745 virtual void SetStyleString(
const char * );
746 virtual void SetStyleStringDirectly(
char * );
753 virtual void SetStyleTableDirectly(
OGRStyleTable *poStyleTable );
757 {
return m_pszNativeMediaType; }
758 void SetNativeData(
const char* pszNativeData );
759 void SetNativeMediaType(
const char* pszNativeMediaType );
768 {
return reinterpret_cast<OGRFeatureH>(poFeature); }
774 {
return reinterpret_cast<OGRFeature*
>(hFeature); }
781 struct CPL_DLL OGRFeatureUniquePtrDeleter
812 class swq_custom_func_registrar;
814 class CPL_DLL OGRFeatureQuery
820 char **FieldCollector(
void *,
char ** );
825 int CanUseIndex( swq_expr_node*,
OGRLayer * );
829 swq_custom_func_registrar* poCustomFuncRegistrar );
839 swq_custom_func_registrar*
840 poCustomFuncRegistrar =
nullptr );
843 swq_custom_func_registrar*
844 poCustomFuncRegistrar =
nullptr );
851 char **GetUsedFields();
853 void *GetSWQExpr() {
return pSWQExpr; }
#define MAX(a, b)
Macro to compute the maximum of 2 values.
Definition: cpl_port.h:414
const double * GetFieldAsDoubleList(const char *pszFName, int *pnCount) const
Fetch field value as a list of doubles.
Definition: ogr_feature.h:671
const char * GetString() const
Return the string value.
Definition: ogr_feature.h:487
static OGRFeatureDefn * FromHandle(OGRFeatureDefnH hFeatureDefn)
Convert a OGRFeatureDefnH to a OGRFeatureDefn*.
Definition: ogr_feature.h:349
OGRFieldSubType GetSubType() const
Return field subtype.
Definition: ogr_feature.h:448
virtual int IsStyleIgnored() const
Determine whether the style can be omitted when fetching features.
Definition: ogr_feature.h:324
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
void * OGRFieldDefnH
Opaque type for a field definition (OGRFieldDefn)
Definition: ogr_feature.h:60
Exception raised by operator[](const char*) when a field is not found.
Definition: ogr_feature.h:576
void SetField(const char *pszFName, GIntBig nValue)
Set field to 64 bit integer value.
Definition: ogr_feature.h:695
char ** GetFieldAsStringList(const char *pszFName) const
Fetch field value as a list of strings.
Definition: ogr_feature.h:675
Field value iterator class.
Definition: ogr_feature.h:535
virtual OGRStyleTable * GetStyleTable() const
Return style table.
Definition: ogr_feature.h:751
void SetJustify(OGRJustification eJustifyIn)
Set the justification for this field.
Definition: ogr_feature.h:131
OGRLayer::FeatureIterator begin(OGRLayer *poLayer)
Return begin of feature iterator.
Definition: ogrsf_frmts.h:287
OGRFieldType GetType() const
Return field type.
Definition: ogr_feature.h:446
void SetIgnored(int bIgnoreIn)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:222
This class represents a style table.
Definition: ogr_featurestyle.h:85
void SetIgnored(int bIgnoreIn)
Set whether this field should be omitted when fetching features.
Definition: ogr_feature.h:149
static OGRFeatureH ToHandle(OGRFeature *poFeature)
Convert a OGRFeature* to a OGRFeatureH.
Definition: ogr_feature.h:767
const char * GetName() const
Return field name.
Definition: ogr_feature.h:444
virtual int GetGeomFieldIndex(const char *) const
Find geometry field by name.
Definition: ogrfeaturedefn.cpp:916
OGRFieldDefn * GetFieldDefnRef(int iField)
Fetch definition for this field.
Definition: ogr_feature.h:614
int GetWidth() const
Get the formatting width for this field.
Definition: ogr_feature.h:134
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:158
struct OGRGeomFieldDefnHS * OGRGeomFieldDefnH
Opaque type for a geometry field definition (OGRGeomFieldDefn)
Definition: ogr_feature.h:69
void * OGRStyleTableH
Opaque type for a style table (OGRStyleTable)
Definition: ogr_feature.h:66
void * OGRFeatureH
Opaque type for a feature (OGRFeature)
Definition: ogr_feature.h:64
double GetFieldAsDouble(const char *pszFName) const
Fetch field value as a double.
Definition: ogr_feature.h:659
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:326
OGRGeomFieldDefn * GetGeomFieldDefnRef(int iField)
Fetch definition for this geometry field.
Definition: ogr_feature.h:592
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:71
bool empty() const
Return whether the field value is unset/empty.
Definition: ogr_feature.h:452
static OGRGeomFieldDefnH ToHandle(OGRGeomFieldDefn *poGeomFieldDefn)
Convert a OGRGeomFieldDefn* to a OGRGeomFieldDefnH.
Definition: ogr_feature.h:233
int GetPrecision() const
Get the formatting precision for this field.
Definition: ogr_feature.h:137
Simple feature geometry classes.
const char * GetNameRef() const
Fetch name of this field.
Definition: ogr_feature.h:213
int IsIgnored() const
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:221
std::unique_ptr< OGRFeature, OGRFeatureUniquePtrDeleter > OGRFeatureUniquePtr
Unique pointer type for OGRFeature.
Definition: ogr_feature.h:790
void * OGRFeatureH
Opaque type for a feature (OGRFeature)
Definition: ogr_api.h:314
int GetGeomFieldIndex(const char *pszName) const
Fetch the geometry field index given geometry field name.
Definition: ogr_feature.h:596
const char * GetNameRef() const
Fetch name of this field.
Definition: ogr_feature.h:117
int OGRBoolean
Type for a OGR boolean.
Definition: ogr_core.h:334
void * OGRFeatureDefnH
Opaque type for a feature definition (OGRFeatureDefn)
Definition: ogr_api.h:312
void SetPrecision(int nPrecisionIn)
Set the formatting precision for this field in characters.
Definition: ogr_feature.h:138
virtual OGRFieldDefn * GetFieldDefn(int i)
Fetch field definition.
Definition: ogrfeaturedefn.cpp:330
Field value.
Definition: ogr_feature.h:392
struct OGRGeomFieldDefnHS * OGRGeomFieldDefnH
Opaque type for a geometry field definition (OGRGeomFieldDefn)
Definition: ogr_api.h:319
ConstFieldIterator begin() const
Return begin of field value iterator.
Definition: ogrfeature.cpp:7040
int IsUnique() const
Return whether this field has a unique constraint.
Definition: ogr_feature.h:154
OGRFeature field attribute value union.
Definition: ogr_core.h:728
virtual OGRGeomFieldDefn * GetGeomFieldDefn(int i)
Fetch geometry field definition.
Definition: ogrfeaturedefn.cpp:681
void SetField(const char *pszFName, int nCount, const double *padfValues)
Set field to list of doubles value.
Definition: ogr_feature.h:707
int GetFieldIndex(const char *pszName) const
Fetch the field index given field name.
Definition: ogr_feature.h:616
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1216
void Unset()
Unset the field.
Definition: ogr_feature.h:433
virtual int GetFieldCount() const
Fetch number of fields on this feature.
Definition: ogrfeaturedefn.cpp:286
void SetField(const char *pszFName, const char *pszValue)
Set field to string value.
Definition: ogr_feature.h:699
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
static OGRFieldDefn * FromHandle(OGRFieldDefnH hFieldDefn)
Convert a OGRFieldDefnH to a OGRFieldDefn*.
Definition: ogr_feature.h:168
const OGRFeatureDefn * GetDefnRef() const
Fetch feature definition.
Definition: ogr_feature.h:582
Definition of an attribute of an OGRFeatureDefn.
Definition: ogr_feature.h:95
int IsNullable() const
Return whether this geometry field can receive null values.
Definition: ogr_feature.h:224
Simple feature style classes.
virtual void SetStyleIgnored(int bIgnore)
Set whether the style can be omitted when fetching features.
Definition: ogr_feature.h:325
void SetUnique(int bUniqueIn)
Set whether this field has a unique constraint.
Definition: ogr_feature.h:155
void SetField(const char *pszFName, int nCount, const int *panValues)
Set field to list of integers value.
Definition: ogr_feature.h:701
OGRFeatureDefn * GetDefnRef()
Fetch feature definition.
Definition: ogr_feature.h:581
OGRJustification
Display justification for field values.
Definition: ogr_core.h:688
void * OGRFieldDefnH
Opaque type for a field definition (OGRFieldDefn)
Definition: ogr_api.h:310
Definition of a geometry field of an OGRFeatureDefn.
Definition: ogr_feature.h:193
double GetDouble() const
Return the double value.
Definition: ogr_feature.h:481
const GIntBig * GetFieldAsInteger64List(const char *pszFName, int *pnCount) const
Fetch field value as a list of 64 bit integers.
Definition: ogr_feature.h:667
static OGRFeature * FromHandle(OGRFeatureH hFeature)
Convert a OGRFeatureH to a OGRFeature*.
Definition: ogr_feature.h:773
int Dereference()
Decrements the reference count by one.
Definition: ogr_feature.h:318
OGRLayer::FeatureIterator end(OGRLayer *poLayer)
Return end of feature iterator.
Definition: ogrsf_frmts.h:292
OGRFieldType GetType() const
Fetch type of this field.
Definition: ogr_feature.h:122
virtual int GetFieldIndex(const char *) const
Find field by name.
Definition: ogrfeaturedefn.cpp:1218
const char * GetAlternativeNameRef() const
Fetch the alternative name (or "alias") for this field.
Definition: ogr_feature.h:120
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:318
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:248
const OGRFieldDefn * GetFieldDefnRef(int iField) const
Fetch definition for this field.
Definition: ogr_feature.h:612
int GetInteger() const
Return the integer value.
Definition: ogr_feature.h:469
const OGRField * GetRawFieldRef(int i) const
Fetch a pointer to the internal field value given the index.
Definition: ogr_feature.h:630
OGRwkbGeometryType
List of well known binary geometry types.
Definition: ogr_core.h:346
int IsIgnored() const
Return whether this field should be omitted when fetching features.
Definition: ogr_feature.h:148
void SetField(const char *pszFName, double dfValue)
Set field to double value.
Definition: ogr_feature.h:697
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:946
OGRField * GetRawFieldRef(int i)
Fetch a pointer to the internal field value given the index.
Definition: ogr_feature.h:629
int Reference()
Increments the reference count by one.
Definition: ogr_feature.h:317
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:365
ConstFieldIterator end() const
Return end of field value iterator.
Definition: ogrfeature.cpp:7045
const OGRGeomFieldDefn * GetGeomFieldDefnRef(int iField) const
Fetch definition for this geometry field.
Definition: ogr_feature.h:594
OGRwkbGeometryType GetType() const
Fetch geometry type of this field.
Definition: ogr_feature.h:215
const char * GetNativeMediaType() const
Returns the native media type for the feature.
Definition: ogr_feature.h:756
OGRFieldSubType
List of field subtypes.
Definition: ogr_core.h:668
void SetNullable(int bNullableIn)
Set whether this field can receive null values.
Definition: ogr_feature.h:152
void SetNullable(int bNullableIn)
Set whether this geometry field can receive null values.
Definition: ogr_feature.h:225
static OGRGeomFieldDefn * FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)
Convert a OGRGeomFieldDefnH to a OGRGeomFieldDefn*.
Definition: ogr_feature.h:239
static OGRFeatureDefnH ToHandle(OGRFeatureDefn *poFeatureDefn)
Convert a OGRFeatureDefn* to a OGRFeatureDefnH.
Definition: ogr_feature.h:343
int IsNullable() const
Return whether this field can receive null values.
Definition: ogr_feature.h:151
OGRFieldType
List of feature field types.
Definition: ogr_core.h:640
void * OGRFeatureDefnH
Opaque type for a feature definition (OGRFeatureDefn)
Definition: ogr_feature.h:62
virtual int GetGeomFieldCount() const
Fetch number of geometry fields on this feature.
Definition: ogrfeaturedefn.cpp:632
GIntBig GetFieldAsInteger64(const char *pszFName) const
Fetch field value as integer 64 bit.
Definition: ogr_feature.h:657
const char * GetFieldAsString(const char *pszFName) const
Fetch field value as a string.
Definition: ogr_feature.h:661
GIntBig GetInteger64() const
Return the 64-bit integer value.
Definition: ogr_feature.h:475
void SetField(const char *pszFName, OGRField *puValue)
Set field.
Definition: ogr_feature.h:712
void SetField(const char *pszFName, const char *const *papszValues)
Set field to list of strings value.
Definition: ogr_feature.h:710
void SetWidth(int nWidthIn)
Set the formatting width for this field in characters.
Definition: ogr_feature.h:135
Definition of a feature class or feature layer.
Definition: ogr_feature.h:270
int GetFieldAsInteger(const char *pszFName) const
Fetch field value as integer.
Definition: ogr_feature.h:655
int GetReferenceCount() const
Fetch current reference count.
Definition: ogr_feature.h:319
OGRFieldSubType GetSubType() const
Fetch subtype of this field.
Definition: ogr_feature.h:126
void SetField(const char *pszFName, int nValue)
Set field to integer value.
Definition: ogr_feature.h:693
const int * GetFieldAsIntegerList(const char *pszFName, int *pnCount) const
Fetch field value as a list of integers.
Definition: ogr_feature.h:663
@ wkbUnknown
unknown type, non-standard
Definition: ogr_core.h:347
#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
OGRJustification GetJustify() const
Get the justification for this field.
Definition: ogr_feature.h:130
const char * GetNativeData() const
Returns the native data for the feature.
Definition: ogr_feature.h:755
GIntBig GetFID() const
Get feature identifier.
Definition: ogr_feature.h:722
void SetField(const char *pszFName, int nCount, const GIntBig *panValues)
Set field to list of 64 bit integers value.
Definition: ogr_feature.h:704
static OGRFieldDefnH ToHandle(OGRFieldDefn *poFieldDefn)
Convert a OGRFieldDefn* to a OGRFieldDefnH.
Definition: ogr_feature.h:162