GDAL
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
OGRFeature Class Reference

A simple feature, including geometry and attributes. More...

#include <ogr_feature.h>

Classes

class  ConstFieldIterator
 Field value iterator class. More...
 
class  FieldNotFoundException
 Exception raised by operator[](const char*) when a field is not found. More...
 
class  FieldValue
 Field value. More...
 

Public Member Functions

 OGRFeature (OGRFeatureDefn *)
 Constructor. More...
 
ConstFieldIterator begin () const
 Return begin of field value iterator. More...
 
ConstFieldIterator end () const
 Return end of field value iterator.
 
const FieldValue operator[] (int iField) const
 Return a field value. More...
 
FieldValue operator[] (int iField)
 Return a field value. More...
 
const FieldValue operator[] (const char *pszFieldName) const
 Return a field value. More...
 
FieldValue operator[] (const char *pszFieldName)
 Return a field value. More...
 
OGRFeatureDefnGetDefnRef ()
 Fetch feature definition. More...
 
const OGRFeatureDefnGetDefnRef () const
 Fetch feature definition. More...
 
OGRErr SetGeometryDirectly (OGRGeometry *)
 Set feature geometry. More...
 
OGRErr SetGeometry (const OGRGeometry *)
 Set feature geometry. More...
 
OGRGeometryGetGeometryRef ()
 Fetch pointer to feature geometry. More...
 
const OGRGeometryGetGeometryRef () const
 Fetch pointer to feature geometry. More...
 
OGRGeometryStealGeometry ()
 Take away ownership of geometry. More...
 
int GetGeomFieldCount () const
 Fetch number of geometry fields on this feature. More...
 
OGRGeomFieldDefnGetGeomFieldDefnRef (int iField)
 Fetch definition for this geometry field. More...
 
const OGRGeomFieldDefnGetGeomFieldDefnRef (int iField) const
 Fetch definition for this geometry field. More...
 
int GetGeomFieldIndex (const char *pszName) const
 Fetch the geometry field index given geometry field name. More...
 
OGRGeometryGetGeomFieldRef (int iField)
 Fetch pointer to feature geometry. More...
 
const OGRGeometryGetGeomFieldRef (int iField) const
 Fetch pointer to feature geometry. More...
 
OGRGeometryStealGeometry (int iField)
 Take away ownership of geometry. More...
 
OGRGeometryGetGeomFieldRef (const char *pszFName)
 Fetch pointer to feature geometry. More...
 
const OGRGeometryGetGeomFieldRef (const char *pszFName) const
 Fetch pointer to feature geometry. More...
 
OGRErr SetGeomFieldDirectly (int iField, OGRGeometry *)
 Set feature geometry of a specified geometry field. More...
 
OGRErr SetGeomField (int iField, const OGRGeometry *)
 Set feature geometry of a specified geometry field. More...
 
void Reset ()
 Reset the state of a OGRFeature to its state after construction. More...
 
OGRFeatureClone () const
 Duplicate feature. More...
 
virtual OGRBoolean Equal (const OGRFeature *poFeature) const
 Test if two features are the same. More...
 
int GetFieldCount () const
 Fetch number of fields on this feature. More...
 
const OGRFieldDefnGetFieldDefnRef (int iField) const
 Fetch definition for this field. More...
 
OGRFieldDefnGetFieldDefnRef (int iField)
 Fetch definition for this field. More...
 
int GetFieldIndex (const char *pszName) const
 Fetch the field index given field name. More...
 
int IsFieldSet (int iField) const
 Test if a field has ever been assigned a value or not. More...
 
void UnsetField (int iField)
 Clear a field, marking it as unset. More...
 
bool IsFieldNull (int iField) const
 Test if a field is null. More...
 
void SetFieldNull (int iField)
 Clear a field, marking it as null. More...
 
bool IsFieldSetAndNotNull (int iField) const
 Test if a field is set and not null. More...
 
OGRFieldGetRawFieldRef (int i)
 Fetch a pointer to the internal field value given the index. More...
 
const OGRFieldGetRawFieldRef (int i) const
 Fetch a pointer to the internal field value given the index. More...
 
int GetFieldAsInteger (int i) const
 Fetch field value as integer. More...
 
GIntBig GetFieldAsInteger64 (int i) const
 Fetch field value as integer 64 bit. More...
 
double GetFieldAsDouble (int i) const
 Fetch field value as a double. More...
 
const char * GetFieldAsString (int i) const
 Fetch field value as a string. More...
 
const char * GetFieldAsISO8601DateTime (int i, CSLConstList papszOptions) const
 Fetch OFTDateTime field value as a ISO8601 representation. More...
 
const int * GetFieldAsIntegerList (int i, int *pnCount) const
 Fetch field value as a list of integers. More...
 
const GIntBigGetFieldAsInteger64List (int i, int *pnCount) const
 Fetch field value as a list of 64 bit integers. More...
 
const double * GetFieldAsDoubleList (int i, int *pnCount) const
 Fetch field value as a list of doubles. More...
 
char ** GetFieldAsStringList (int i) const
 Fetch field value as a list of strings. More...
 
GByteGetFieldAsBinary (int i, int *pnCount) const
 Fetch field value as binary data. More...
 
int GetFieldAsDateTime (int i, int *pnYear, int *pnMonth, int *pnDay, int *pnHour, int *pnMinute, int *pnSecond, int *pnTZFlag) const
 Fetch field value as date and time. More...
 
int GetFieldAsDateTime (int i, int *pnYear, int *pnMonth, int *pnDay, int *pnHour, int *pnMinute, float *pfSecond, int *pnTZFlag) const
 Fetch field value as date and time. More...
 
char * GetFieldAsSerializedJSon (int i) const
 Fetch field value as a serialized JSon object. More...
 
int GetFieldAsInteger (const char *pszFName) const
 Fetch field value as integer. More...
 
GIntBig GetFieldAsInteger64 (const char *pszFName) const
 Fetch field value as integer 64 bit. More...
 
double GetFieldAsDouble (const char *pszFName) const
 Fetch field value as a double. More...
 
const char * GetFieldAsString (const char *pszFName) const
 Fetch field value as a string. More...
 
const char * GetFieldAsISO8601DateTime (const char *pszFName, CSLConstList papszOptions) const
 Fetch OFTDateTime field value as a ISO8601 representation. More...
 
const int * GetFieldAsIntegerList (const char *pszFName, int *pnCount) const
 Fetch field value as a list of integers. More...
 
const GIntBigGetFieldAsInteger64List (const char *pszFName, int *pnCount) const
 Fetch field value as a list of 64 bit integers. More...
 
const double * GetFieldAsDoubleList (const char *pszFName, int *pnCount) const
 Fetch field value as a list of doubles. More...
 
char ** GetFieldAsStringList (const char *pszFName) const
 Fetch field value as a list of strings. More...
 
void SetField (int i, int nValue)
 Set field to integer value. More...
 
void SetField (int i, GIntBig nValue)
 Set field to 64 bit integer value. More...
 
void SetField (int i, double dfValue)
 Set field to double value. More...
 
void SetField (int i, const char *pszValue)
 Set field to string value. More...
 
void SetField (int i, int nCount, const int *panValues)
 Set field to list of integers value. More...
 
void SetField (int i, int nCount, const GIntBig *panValues)
 Set field to list of 64 bit integers value. More...
 
void SetField (int i, int nCount, const double *padfValues)
 Set field to list of doubles value. More...
 
void SetField (int i, const char *const *papszValues)
 Set field to list of strings value. More...
 
void SetField (int i, const OGRField *puValue)
 Set field. More...
 
void SetField (int i, int nCount, const void *pabyBinary)
 Set field to binary data. More...
 
void SetField (int i, int nYear, int nMonth, int nDay, int nHour=0, int nMinute=0, float fSecond=0.f, int nTZFlag=0)
 Set field to date. More...
 
void SetField (const char *pszFName, int nValue)
 Set field to integer value. More...
 
void SetField (const char *pszFName, GIntBig nValue)
 Set field to 64 bit integer value. More...
 
void SetField (const char *pszFName, double dfValue)
 Set field to double value. More...
 
void SetField (const char *pszFName, const char *pszValue)
 Set field to string value. More...
 
void SetField (const char *pszFName, int nCount, const int *panValues)
 This method currently on has an effect of OFTIntegerList, OFTInteger64List and OFTRealList fields. More...
 
void SetField (const char *pszFName, int nCount, const GIntBig *panValues)
 Set field to list of 64 bit integers value. More...
 
void SetField (const char *pszFName, int nCount, const double *padfValues)
 This method currently on has an effect of OFTIntegerList, OFTInteger64List, OFTRealList fields. More...
 
void SetField (const char *pszFName, const char *const *papszValues)
 This method currently on has an effect of OFTStringList fields. More...
 
void SetField (const char *pszFName, const OGRField *puValue)
 Set field. More...
 
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. More...
 
GIntBig GetFID () const
 Get feature identifier. More...
 
virtual OGRErr SetFID (GIntBig nFIDIn)
 Set the feature identifier. More...
 
void DumpReadable (FILE *, CSLConstList papszOptions=nullptr) const
 Dump this feature in a human readable form. More...
 
std::string DumpReadableAsString (CSLConstList papszOptions=nullptr) const
 Dump this feature in a human readable form. More...
 
OGRErr SetFrom (const OGRFeature *, int bForgiving=TRUE)
 Set one feature from another. More...
 
OGRErr SetFrom (const OGRFeature *, const int *panMap, int bForgiving=TRUE, bool bUseISO8601ForDateTimeAsString=false)
 Set one feature from another. More...
 
OGRErr SetFieldsFrom (const OGRFeature *, const int *panMap, int bForgiving=TRUE, bool bUseISO8601ForDateTimeAsString=false)
 Set fields from another feature. More...
 
int Validate (int nValidateFlags, int bEmitError) const
 Validate that a feature meets constraints of its schema. More...
 
void FillUnsetWithDefault (int bNotNullableOnly, char **papszOptions)
 Fill unset fields with default values that might be defined. More...
 
bool SerializeToBinary (std::vector< GByte > &abyBuffer) const
 Serialize the feature to a binary encoding. More...
 
bool DeserializeFromBinary (const GByte *pabyBuffer, size_t nSize)
 Instantiate a feature from a binary encoding produces by SerializeToBinary() More...
 
virtual const char * GetStyleString () const
 Fetch style string for this feature. More...
 
virtual void SetStyleString (const char *)
 Set feature style string. More...
 
virtual void SetStyleStringDirectly (char *)
 Set feature style string. More...
 
virtual OGRStyleTableGetStyleTable () const
 Return style table. More...
 
virtual void SetStyleTable (OGRStyleTable *poStyleTable)
 Set style table. More...
 
virtual void SetStyleTableDirectly (OGRStyleTable *poStyleTable)
 Set style table. More...
 
const char * GetNativeData () const
 Returns the native data for the feature. More...
 
const char * GetNativeMediaType () const
 Returns the native media type for the feature. More...
 
void SetNativeData (const char *pszNativeData)
 Sets the native data for the feature. More...
 
void SetNativeMediaType (const char *pszNativeMediaType)
 Sets the native media type for the feature. More...
 

Static Public Member Functions

static OGRFeatureCreateFeature (OGRFeatureDefn *)
 Feature factory. More...
 
static void DestroyFeature (OGRFeature *)
 Destroy feature. More...
 
static OGRFeatureH ToHandle (OGRFeature *poFeature)
 Convert a OGRFeature* to a OGRFeatureH. More...
 
static OGRFeatureFromHandle (OGRFeatureH hFeature)
 Convert a OGRFeatureH to a OGRFeature*. More...
 

Protected Member Functions

bool CopySelfTo (OGRFeature *poNew) const
 Copies the innards of this OGRFeature into the supplied object. More...
 

Detailed Description

A simple feature, including geometry and attributes.

Constructor & Destructor Documentation

◆ OGRFeature()

OGRFeature::OGRFeature ( OGRFeatureDefn poDefnIn)
explicit

Constructor.

Note that the OGRFeature will increment the reference count of its defining OGRFeatureDefn. Destruction of the OGRFeatureDefn before destruction of all OGRFeatures that depend on it is likely to result in a crash.

This method is the same as the C function OGR_F_Create().

Parameters
poDefnInfeature class (layer) definition to which the feature will adhere.

Member Function Documentation

◆ begin()

OGRFeature::ConstFieldIterator OGRFeature::begin ( ) const

Return begin of field value iterator.

Using this iterator for standard range-based loops is safe, but due to implementation limitations, you shouldn't try to access (dereference) more than one iterator step at a time, since you will get a reference to the same object (FieldValue) at each iteration step.

for( auto&& oField: poFeature )
{
     std::cout << oField.GetIndex() << "," << oField.GetName()<< ": " <<
oField.GetAsString() << std::endl;
}
Since
GDAL 2.3

◆ Clone()

OGRFeature * OGRFeature::Clone ( ) const

Duplicate feature.

The newly created feature is owned by the caller, and will have its own reference to the OGRFeatureDefn.

This method is the same as the C function OGR_F_Clone().

Returns
new feature, exactly matching this feature. Or, starting with GDAL 2.1, NULL in case of out of memory situation.

◆ CopySelfTo()

bool OGRFeature::CopySelfTo ( OGRFeature poNew) const
protected

Copies the innards of this OGRFeature into the supplied object.

This is mainly intended to allow derived classes to implement their own Clone functions.

Parameters
poNewThe object into which to copy the data of this object.
Returns
True if successful, false if the copy failed.

◆ CreateFeature()

OGRFeature * OGRFeature::CreateFeature ( OGRFeatureDefn poDefn)
static

Feature factory.

This is essentially a feature factory, useful for applications creating features but wanting to ensure they are created out of the OGR/GDAL heap.

This method is the same as the C function OGR_F_Create().

Parameters
poDefnFeature definition defining schema.
Returns
new feature object with null fields and no geometry, or, starting with GDAL 2.1, NULL in case of out of memory situation. May be deleted with DestroyFeature().

◆ DeserializeFromBinary()

bool OGRFeature::DeserializeFromBinary ( const GByte pabyBuffer,
size_t  nSize 
)

Instantiate a feature from a binary encoding produces by SerializeToBinary()

This sets the feature ID, attribute fields content and geometry fields content.

DeserializeFromBinary() should be called on a feature whose feature definition is exactly the same as the one on which SerializeToBinary() was called. (but there is no security issue if not doing that, or if feeding a "random" buffer to that method).

The format of that encoding may vary across GDAL versions.

Since
3.9

◆ DestroyFeature()

void OGRFeature::DestroyFeature ( OGRFeature poFeature)
static

Destroy feature.

The feature is deleted, but within the context of the GDAL/OGR heap. This is necessary when higher level applications use GDAL/OGR from a DLL and they want to delete a feature created within the DLL. If the delete is done in the calling application the memory will be freed onto the application heap which is inappropriate.

This method is the same as the C function OGR_F_Destroy().

Parameters
poFeaturethe feature to delete.

◆ DumpReadable()

void OGRFeature::DumpReadable ( FILE *  fpOut,
CSLConstList  papszOptions = nullptr 
) const

Dump this feature in a human readable form.

This dumps the attributes, and geometry; however, it doesn't definition information (other than field types and names), nor does it report the geometry spatial reference system.

A few options can be defined to change the default dump :

  • DISPLAY_FIELDS=NO : to hide the dump of the attributes
  • DISPLAY_STYLE=NO : to hide the dump of the style string
  • DISPLAY_GEOMETRY=NO : to hide the dump of the geometry
  • DISPLAY_GEOMETRY=SUMMARY : to get only a summary of the geometry

This method is the same as the C function OGR_F_DumpReadable().

Parameters
fpOutthe stream to write to, such as stdout. If NULL stdout will be used.
papszOptionsNULL terminated list of options (may be NULL)

◆ DumpReadableAsString()

std::string OGRFeature::DumpReadableAsString ( CSLConstList  papszOptions = nullptr) const

Dump this feature in a human readable form.

This dumps the attributes, and geometry; however, it doesn't definition information (other than field types and names), nor does it report the geometry spatial reference system.

A few options can be defined to change the default dump :

  • DISPLAY_FIELDS=NO : to hide the dump of the attributes
  • DISPLAY_STYLE=NO : to hide the dump of the style string
  • DISPLAY_GEOMETRY=NO : to hide the dump of the geometry
  • DISPLAY_GEOMETRY=SUMMARY : to get only a summary of the geometry
Parameters
papszOptionsNULL terminated list of options (may be NULL)
Returns
a string with the feature representation.
Since
GDAL 3.7

◆ Equal()

OGRBoolean OGRFeature::Equal ( const OGRFeature poFeature) const
virtual

Test if two features are the same.

Two features are considered equal if the share them (pointer equality) same OGRFeatureDefn, have the same field values, and the same geometry (as tested by OGRGeometry::Equal()) as well as the same feature id.

This method is the same as the C function OGR_F_Equal().

Parameters
poFeaturethe other feature to test this one against.
Returns
TRUE if they are equal, otherwise FALSE.

◆ FillUnsetWithDefault()

void OGRFeature::FillUnsetWithDefault ( int  bNotNullableOnly,
char **  papszOptions 
)

Fill unset fields with default values that might be defined.

This method is the same as the C function OGR_F_FillUnsetWithDefault().

Parameters
bNotNullableOnlyif we should fill only unset fields with a not-null constraint.
papszOptionsunused currently. Must be set to NULL.
Since
GDAL 2.0

◆ FromHandle()

static OGRFeature * OGRFeature::FromHandle ( OGRFeatureH  hFeature)
inlinestatic

Convert a OGRFeatureH to a OGRFeature*.

Since
GDAL 2.3

◆ GetDefnRef() [1/2]

OGRFeatureDefn * OGRFeature::GetDefnRef ( )
inline

Fetch feature definition.

This method is the same as the C function OGR_F_GetDefnRef().

Returns
a reference to the feature definition object.

◆ GetDefnRef() [2/2]

const OGRFeatureDefn * OGRFeature::GetDefnRef ( ) const
inline

Fetch feature definition.

This method is the same as the C function OGR_F_GetDefnRef().

Returns
a reference to the feature definition object.
Since
GDAL 2.3

◆ GetFID()

GIntBig OGRFeature::GetFID ( ) const
inline

Get feature identifier.

This method is the same as the C function OGR_F_GetFID(). Note: since GDAL 2.0, this method returns a GIntBig (previously a long)

Returns
feature id or OGRNullFID if none has been assigned.

◆ GetFieldAsBinary()

GByte * OGRFeature::GetFieldAsBinary ( int  iField,
int *  pnBytes 
) const

Fetch field value as binary data.

This method only works for OFTBinary and OFTString fields.

This method is the same as the C function OGR_F_GetFieldAsBinary().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
pnByteslocation to put the number of bytes returned.
Returns
the field value. This data is internal, and should not be modified, or freed. Its lifetime may be very brief.

◆ GetFieldAsDateTime() [1/2]

int OGRFeature::GetFieldAsDateTime ( int  iField,
int *  pnYear,
int *  pnMonth,
int *  pnDay,
int *  pnHour,
int *  pnMinute,
float *  pfSecond,
int *  pnTZFlag 
) const

Fetch field value as date and time.

Currently this method only works for OFTDate, OFTTime and OFTDateTime fields.

This method is the same as the C function OGR_F_GetFieldAsDateTime().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
pnYear(including century)
pnMonth(1-12)
pnDay(1-31)
pnHour(0-23)
pnMinute(0-59)
pfSecond(0-59 with millisecond accuracy)
pnTZFlag(0=unknown, 1=localtime, 100=GMT, see data model for details)
Returns
TRUE on success or FALSE on failure.

◆ GetFieldAsDateTime() [2/2]

int OGRFeature::GetFieldAsDateTime ( int  iField,
int *  pnYear,
int *  pnMonth,
int *  pnDay,
int *  pnHour,
int *  pnMinute,
int *  pnSecond,
int *  pnTZFlag 
) const

Fetch field value as date and time.

Currently this method only works for OFTDate, OFTTime and OFTDateTime fields.

This method is the same as the C function OGR_F_GetFieldAsDateTime().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
pnYear(including century)
pnMonth(1-12)
pnDay(1-31)
pnHour(0-23)
pnMinute(0-59)
pnSecond(0-59)
pnTZFlag(0=unknown, 1=localtime, 100=GMT, see data model for details)
Returns
TRUE on success or FALSE on failure.

◆ GetFieldAsDouble() [1/2]

OGRFeature::GetFieldAsDouble ( const char *  pszFName) const
inline

Fetch field value as a double.

OFTString features will be translated using CPLAtof(). OFTInteger and OFTInteger64 fields will be cast to double. Other field types, or errors will result in a return value of zero.

Parameters
pszFNamethe name of the field to fetch.
Returns
the field value.

◆ GetFieldAsDouble() [2/2]

double OGRFeature::GetFieldAsDouble ( int  iField) const

Fetch field value as a double.

OFTString features will be translated using CPLAtof(). OFTInteger and OFTInteger64 fields will be cast to double. Other field types, or errors will result in a return value of zero.

This method is the same as the C function OGR_F_GetFieldAsDouble().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the field value.

◆ GetFieldAsDoubleList() [1/2]

OGRFeature::GetFieldAsDoubleList ( const char *  pszFName,
int *  pnCount 
) const
inline

Fetch field value as a list of doubles.

Currently this method only works for OFTRealList fields.

Parameters
pszFNamethe name of the field to fetch.
pnCountan integer to put the list count (number of doubles) into.
Returns
the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL.

◆ GetFieldAsDoubleList() [2/2]

const double * OGRFeature::GetFieldAsDoubleList ( int  iField,
int *  pnCount 
) const

Fetch field value as a list of doubles.

Currently this method only works for OFTRealList fields.

This method is the same as the C function OGR_F_GetFieldAsDoubleList().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
pnCountan integer to put the list count (number of doubles) into.
Returns
the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL.

◆ GetFieldAsInteger() [1/2]

OGRFeature::GetFieldAsInteger ( const char *  pszFName) const
inline

Fetch field value as integer.

OFTString features will be translated using atoi(). OFTReal fields will be cast to integer. OFTInteger64 are demoted to 32 bit, with clamping if out-of-range. Other field types, or errors will result in a return value of zero.

Parameters
pszFNamethe name of the field to fetch.
Returns
the field value.

◆ GetFieldAsInteger() [2/2]

int OGRFeature::GetFieldAsInteger ( int  iField) const

Fetch field value as integer.

OFTString features will be translated using atoi(). OFTReal fields will be cast to integer. OFTInteger64 are demoted to 32 bit, with clamping if out-of-range. Other field types, or errors will result in a return value of zero.

This method is the same as the C function OGR_F_GetFieldAsInteger().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the field value.

◆ GetFieldAsInteger64() [1/2]

OGRFeature::GetFieldAsInteger64 ( const char *  pszFName) const
inline

Fetch field value as integer 64 bit.

OFTInteger are promoted to 64 bit. OFTString features will be translated using CPLAtoGIntBig(). OFTReal fields will be cast to integer. Other field types, or errors will result in a return value of zero.

Parameters
pszFNamethe name of the field to fetch.
Returns
the field value.

◆ GetFieldAsInteger64() [2/2]

GIntBig OGRFeature::GetFieldAsInteger64 ( int  iField) const

Fetch field value as integer 64 bit.

OFTInteger are promoted to 64 bit. OFTString features will be translated using CPLAtoGIntBig(). OFTReal fields will be cast to integer. Other field types, or errors will result in a return value of zero.

This method is the same as the C function OGR_F_GetFieldAsInteger64().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the field value.
Since
GDAL 2.0

◆ GetFieldAsInteger64List() [1/2]

OGRFeature::GetFieldAsInteger64List ( const char *  pszFName,
int *  pnCount 
) const
inline

Fetch field value as a list of 64 bit integers.

Currently this method only works for OFTInteger64List fields.

Parameters
pszFNamethe name of the field to fetch.
pnCountan integer to put the list count (number of integers) into.
Returns
the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL.
Since
GDAL 2.0

◆ GetFieldAsInteger64List() [2/2]

const GIntBig * OGRFeature::GetFieldAsInteger64List ( int  iField,
int *  pnCount 
) const

Fetch field value as a list of 64 bit integers.

Currently this method only works for OFTInteger64List fields.

This method is the same as the C function OGR_F_GetFieldAsInteger64List().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
pnCountan integer to put the list count (number of integers) into.
Returns
the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL.
Since
GDAL 2.0

◆ GetFieldAsIntegerList() [1/2]

OGRFeature::GetFieldAsIntegerList ( const char *  pszFName,
int *  pnCount 
) const
inline

Fetch field value as a list of integers.

Currently this method only works for OFTIntegerList fields.

Parameters
pszFNamethe name of the field to fetch.
pnCountan integer to put the list count (number of integers) into.
Returns
the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL. OFTReal and OFTInteger fields will be translated to string using sprintf(), but not necessarily using the established formatting rules. Other field types, or errors will result in a return value of zero.

◆ GetFieldAsIntegerList() [2/2]

const int * OGRFeature::GetFieldAsIntegerList ( int  iField,
int *  pnCount 
) const

Fetch field value as a list of integers.

Currently this method only works for OFTIntegerList fields.

This method is the same as the C function OGR_F_GetFieldAsIntegerList().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
pnCountan integer to put the list count (number of integers) into.
Returns
the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief. If *pnCount is zero on return the returned pointer may be NULL or non-NULL.

◆ GetFieldAsISO8601DateTime() [1/2]

OGRFeature::GetFieldAsISO8601DateTime ( const char *  pszFName,
CSLConstList  papszOptions 
) const
inline

Fetch OFTDateTime field value as a ISO8601 representation.

Return a string like "YYYY-MM-DDTHH:MM:SS(.sss)?(Z|([+|-]HH:MM))?" Milliseconds are omitted if equal to zero. Other field types, or errors will result in a return of an empty string.

Parameters
pszFNamethe name of the field to fetch.
papszOptionsNULL terminated list of strings, or NULL. No options are defined currently.
Returns
the field value. This string is internal, and should not be modified, or freed. Its lifetime may be very brief.
Since
GDAL 3.7

◆ GetFieldAsISO8601DateTime() [2/2]

const char * OGRFeature::GetFieldAsISO8601DateTime ( int  iField,
CSLConstList  papszOptions 
) const

Fetch OFTDateTime field value as a ISO8601 representation.

Return a string like "YYYY-MM-DDTHH:MM:SS(.sss)?(Z|([+|-]HH:MM))?" Milliseconds are omitted if equal to zero. Other field types, or errors will result in a return of an empty string.

This method is the same as the C function OGR_F_GetFieldAsISO8601DateTime().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
papszOptionsNULL terminated list of strings, or NULL. No options are defined currently.
Returns
the field value. This string is internal, and should not be modified, or freed. Its lifetime may be very brief.
Since
GDAL 3.7

◆ GetFieldAsSerializedJSon()

char * OGRFeature::GetFieldAsSerializedJSon ( int  iField) const

Fetch field value as a serialized JSon object.

Currently this method only works for OFTString with OFSTJSON subtype, OFTStringList, OFTIntegerList, OFTInteger64List and OFTRealList

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
a string that must be de-allocate with CPLFree()
Since
GDAL 2.2

◆ GetFieldAsString() [1/2]

OGRFeature::GetFieldAsString ( const char *  pszFName) const
inline

Fetch field value as a string.

OFTReal, OFTInteger, OFTInteger64 fields will be translated to string using sprintf(), but not necessarily using the established formatting rules. OFTDateTime fields are formatted with "YYYY/MM/DD HH:MM:SS[.sss]+ZZ" (note this is not a ISO-8601 compliant string. Use GetFieldAsISO8601DateTime()) OFTDate fields are formatted as "YYYY/MM/DD" OFTTime fields are formatted as "HH:MM:SS[.sss]" OFTRealList, OFTIntegerList, OFTInteger64List, OFTStringList fields are formatted as "(number_of_values:val1,val2,...,valN)" OFTBinary fields are formatted as an hexadecimal representation. Other field types, or errors will result in a return of an empty string.

Parameters
pszFNamethe name of the field to fetch.
Returns
the field value. This string is internal, and should not be modified, or freed. Its lifetime may be very brief.

◆ GetFieldAsString() [2/2]

const char * OGRFeature::GetFieldAsString ( int  iField) const

Fetch field value as a string.

OFTReal, OFTInteger, OFTInteger64 fields will be translated to string using sprintf(), but not necessarily using the established formatting rules. OFTDateTime fields are formatted with "YYYY/MM/DD HH:MM:SS[.sss]+ZZ" (note this is not a ISO-8601 compliant string. Use GetFieldAsISO8601DateTime()) OFTDate fields are formatted as "YYYY/MM/DD" OFTTime fields are formatted as "HH:MM:SS[.sss]" OFTRealList, OFTIntegerList, OFTInteger64List, OFTStringList fields are formatted as "(number_of_values:val1,val2,...,valN)" OFTBinary fields are formatted as an hexadecimal representation. Other field types, or errors will result in a return of an empty string.

This method is the same as the C function OGR_F_GetFieldAsString().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the field value. This string is internal, and should not be modified, or freed. Its lifetime may be very brief.

◆ GetFieldAsStringList() [1/2]

OGRFeature::GetFieldAsStringList ( const char *  pszFName) const
inline

Fetch field value as a list of strings.

Currently this method only works for OFTStringList fields.

The returned list is terminated by a NULL pointer. The number of elements can also be calculated using CSLCount().

Parameters
pszFNamethe name of the field to fetch.
Returns
the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief.

◆ GetFieldAsStringList() [2/2]

char ** OGRFeature::GetFieldAsStringList ( int  iField) const

Fetch field value as a list of strings.

Currently this method only works for OFTStringList fields.

The returned list is terminated by a NULL pointer. The number of elements can also be calculated using CSLCount().

This method is the same as the C function OGR_F_GetFieldAsStringList().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief.

◆ GetFieldCount()

int OGRFeature::GetFieldCount ( ) const
inline

Fetch number of fields on this feature.

This will always be the same as the field count for the OGRFeatureDefn.

This method is the same as the C function OGR_F_GetFieldCount().

Returns
count of fields.

◆ GetFieldDefnRef() [1/2]

OGRFieldDefn * OGRFeature::GetFieldDefnRef ( int  iField)
inline

Fetch definition for this field.

This method is the same as the C function OGR_F_GetFieldDefnRef().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified.

◆ GetFieldDefnRef() [2/2]

const OGRFieldDefn * OGRFeature::GetFieldDefnRef ( int  iField) const
inline

Fetch definition for this field.

This method is the same as the C function OGR_F_GetFieldDefnRef().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified.
Since
GDAL 2.3

◆ GetFieldIndex()

int OGRFeature::GetFieldIndex ( const char *  pszName) const
inline

Fetch the field index given field name.

This is a cover for the OGRFeatureDefn::GetFieldIndex() method.

This method is the same as the C function OGR_F_GetFieldIndex().

Parameters
pszNamethe name of the field to search for.
Returns
the field index, or -1 if no matching field is found.

◆ GetGeometryRef() [1/2]

OGRGeometry * OGRFeature::GetGeometryRef ( )

Fetch pointer to feature geometry.

This method is essentially the same as the C function OGR_F_GetGeometryRef(). (the only difference is that the C function honours OGRGetNonLinearGeometriesEnabledFlag())

Starting with GDAL 1.11, this is equivalent to calling OGRFeature::GetGeomFieldRef(0).

Returns
pointer to internal feature geometry. This object should not be modified.

◆ GetGeometryRef() [2/2]

const OGRGeometry * OGRFeature::GetGeometryRef ( ) const

Fetch pointer to feature geometry.

This method is essentially the same as the C function OGR_F_GetGeometryRef(). (the only difference is that the C function honours OGRGetNonLinearGeometriesEnabledFlag())

Returns
pointer to internal feature geometry. This object should not be modified.
Since
GDAL 2.3

◆ GetGeomFieldCount()

int OGRFeature::GetGeomFieldCount ( ) const
inline

Fetch number of geometry fields on this feature.

This will always be the same as the geometry field count for the OGRFeatureDefn.

This method is the same as the C function OGR_F_GetGeomFieldCount().

Returns
count of geometry fields.
Since
GDAL 1.11

◆ GetGeomFieldDefnRef() [1/2]

OGRGeomFieldDefn * OGRFeature::GetGeomFieldDefnRef ( int  iGeomField)
inline

Fetch definition for this geometry field.

This method is the same as the C function OGR_F_GetGeomFieldDefnRef().

Parameters
iGeomFieldthe field to fetch, from 0 to GetGeomFieldCount()-1.
Returns
the field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified.
Since
GDAL 1.11

◆ GetGeomFieldDefnRef() [2/2]

const OGRGeomFieldDefn * OGRFeature::GetGeomFieldDefnRef ( int  iGeomField) const
inline

Fetch definition for this geometry field.

This method is the same as the C function OGR_F_GetGeomFieldDefnRef().

Parameters
iGeomFieldthe field to fetch, from 0 to GetGeomFieldCount()-1.
Returns
the field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified.
Since
GDAL 2.3

◆ GetGeomFieldIndex()

int OGRFeature::GetGeomFieldIndex ( const char *  pszName) const
inline

Fetch the geometry field index given geometry field name.

This is a cover for the OGRFeatureDefn::GetGeomFieldIndex() method.

This method is the same as the C function OGR_F_GetGeomFieldIndex().

Parameters
pszNamethe name of the geometry field to search for.
Returns
the geometry field index, or -1 if no matching geometry field is found.
Since
GDAL 1.11

◆ GetGeomFieldRef() [1/4]

OGRGeometry * OGRFeature::GetGeomFieldRef ( const char *  pszFName)

Fetch pointer to feature geometry.

Parameters
pszFNamename of geometry field to get.
Returns
pointer to internal feature geometry. This object should not be modified.
Since
GDAL 1.11

◆ GetGeomFieldRef() [2/4]

const OGRGeometry * OGRFeature::GetGeomFieldRef ( const char *  pszFName) const

Fetch pointer to feature geometry.

Parameters
pszFNamename of geometry field to get.
Returns
pointer to internal feature geometry. This object should not be modified.
Since
GDAL 2.3

◆ GetGeomFieldRef() [3/4]

OGRGeometry * OGRFeature::GetGeomFieldRef ( int  iField)

Fetch pointer to feature geometry.

This method is the same as the C function OGR_F_GetGeomFieldRef().

Parameters
iFieldgeometry field to get.
Returns
pointer to internal feature geometry. This object should not be modified.
Since
GDAL 1.11

◆ GetGeomFieldRef() [4/4]

const OGRGeometry * OGRFeature::GetGeomFieldRef ( int  iField) const

Fetch pointer to feature geometry.

This method is the same as the C function OGR_F_GetGeomFieldRef().

Parameters
iFieldgeometry field to get.
Returns
pointer to internal feature geometry. This object should not be modified.
Since
GDAL 2.3

◆ GetNativeData()

const char * OGRFeature::GetNativeData ( ) const
inline

Returns the native data for the feature.

The native data is the representation in a "natural" form that comes from the driver that created this feature, or that is aimed at an output driver. The native data may be in different format, which is indicated by GetNativeMediaType().

Note that most drivers do not support storing the native data in the feature object, and if they do, generally the NATIVE_DATA open option must be passed at dataset opening.

The "native data" does not imply it is something more performant or powerful than what can be obtained with the rest of the API, but it may be useful in round-tripping scenarios where some characteristics of the underlying format are not captured otherwise by the OGR abstraction.

This function is the same as the C function OGR_F_GetNativeData().

Returns
a string with the native data, or NULL if there is none.
Since
GDAL 2.1
See also
https://trac.osgeo.org/gdal/wiki/rfc60_improved_roundtripping_in_ogr

◆ GetNativeMediaType()

const char * OGRFeature::GetNativeMediaType ( ) const
inline

Returns the native media type for the feature.

The native media type is the identifier for the format of the native data. It follows the IANA RFC 2045 (see https://en.wikipedia.org/wiki/Media_type), e.g. "application/vnd.geo+json" for JSon.

This function is the same as the C function OGR_F_GetNativeMediaType().

Returns
a string with the native media type, or NULL if there is none.
Since
GDAL 2.1
See also
https://trac.osgeo.org/gdal/wiki/rfc60_improved_roundtripping_in_ogr

◆ GetRawFieldRef() [1/2]

OGRField * OGRFeature::GetRawFieldRef ( int  iField)
inline

Fetch a pointer to the internal field value given the index.

This method is the same as the C function OGR_F_GetRawFieldRef().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the returned pointer is to an internal data structure, and should not be freed, or modified.

◆ GetRawFieldRef() [2/2]

const OGRField * OGRFeature::GetRawFieldRef ( int  iField) const
inline

Fetch a pointer to the internal field value given the index.

This method is the same as the C function OGR_F_GetRawFieldRef().

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
Returns
the returned pointer is to an internal data structure, and should not be freed, or modified.
Since
GDAL 2.3

◆ GetStyleString()

const char * OGRFeature::GetStyleString ( ) const
virtual

Fetch style string for this feature.

Set the OGR Feature Style Specification for details on the format of this string, and ogr_featurestyle.h for services available to parse it.

This method is the same as the C function OGR_F_GetStyleString().

Returns
a reference to a representation in string format, or NULL if there isn't one.

◆ GetStyleTable()

virtual OGRStyleTable * OGRFeature::GetStyleTable ( ) const
inlinevirtual

Return style table.

Returns
style table.

◆ IsFieldNull()

bool OGRFeature::IsFieldNull ( int  iField) const

Test if a field is null.

This method is the same as the C function OGR_F_IsFieldNull().

Parameters
iFieldthe field to test.
Returns
TRUE if the field is null, otherwise false.
Since
GDAL 2.2

◆ IsFieldSet()

int OGRFeature::IsFieldSet ( int  iField) const

Test if a field has ever been assigned a value or not.

This method is the same as the C function OGR_F_IsFieldSet().

Parameters
iFieldthe field to test.
Returns
TRUE if the field has been set, otherwise false.

◆ IsFieldSetAndNotNull()

bool OGRFeature::IsFieldSetAndNotNull ( int  iField) const

Test if a field is set and not null.

This method is the same as the C function OGR_F_IsFieldSetAndNotNull().

Parameters
iFieldthe field to test.
Returns
TRUE if the field is set and not null, otherwise false.
Since
GDAL 2.2

◆ operator[]() [1/4]

OGRFeature::FieldValue OGRFeature::operator[] ( const char *  pszFieldName)

Return a field value.

Parameters
pszFieldNamefield name
Returns
the field value, or throw a FieldNotFoundException if not found.
Since
GDAL 2.3

◆ operator[]() [2/4]

const OGRFeature::FieldValue OGRFeature::operator[] ( const char *  pszFieldName) const

Return a field value.

Parameters
pszFieldNamefield name
Returns
the field value, or throw a FieldNotFoundException if not found.
Since
GDAL 2.3

◆ operator[]() [3/4]

OGRFeature::FieldValue OGRFeature::operator[] ( int  iField)

Return a field value.

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1. This is not checked by the method !
Returns
the field value.
Since
GDAL 2.3

◆ operator[]() [4/4]

const OGRFeature::FieldValue OGRFeature::operator[] ( int  iField) const

Return a field value.

Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1. This is not checked by the method !
Returns
the field value.
Since
GDAL 2.3

◆ Reset()

void OGRFeature::Reset ( )

Reset the state of a OGRFeature to its state after construction.

This enables recycling existing OGRFeature instances.

Since
GDAL 3.5

◆ SerializeToBinary()

bool OGRFeature::SerializeToBinary ( std::vector< GByte > &  abyBuffer) const

Serialize the feature to a binary encoding.

This saves the feature ID, attribute fields content and geometry fields content.

This method is aimed at being paired with DeserializeFromBinary().

The format of that encoding may vary across GDAL versions.

Note that abyBuffer is cleared at the beginning of this function.

Since
3.9

◆ SetFID()

OGRErr OGRFeature::SetFID ( GIntBig  nFIDIn)
virtual

Set the feature identifier.

For specific types of features this operation may fail on illegal features ids. Generally it always succeeds. Feature ids should be greater than or equal to zero, with the exception of OGRNullFID (-1) indicating that the feature id is unknown.

This method is the same as the C function OGR_F_SetFID().

Parameters
nFIDInthe new feature identifier value to assign.
Returns
On success OGRERR_NONE, or on failure some other value.

◆ SetField() [1/21]

OGRFeature::SetField ( const char *  pszFName,
const char *const *  papszValues 
)
inline

This method currently on has an effect of OFTStringList fields.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
papszValuesthe values to assign. List of NUL-terminated string, ending with a NULL pointer.

◆ SetField() [2/21]

OGRFeature::SetField ( const char *  pszFName,
const char *  pszValue 
)
inline

Set field to string value.

OFTInteger fields will be set based on an atoi() conversion of the string. OFTInteger64 fields will be set based on an CPLAtoGIntBig() conversion of the string. OFTReal fields will be set based on an CPLAtof() conversion of the string. Other field types may be unaffected.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
pszValuethe value to assign.

◆ SetField() [3/21]

OGRFeature::SetField ( const char *  pszFName,
const OGRField puValue 
)
inline

Set field.

The passed value OGRField must be of exactly the same type as the target field, or an application crash may occur. The passed value is copied, and will not be affected. It remains the responsibility of the caller.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
puValuethe value to assign.

◆ SetField() [4/21]

OGRFeature::SetField ( const char *  pszFName,
double  dfValue 
)
inline

Set field to double value.

OFTInteger, OFTInteger64 and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
dfValuethe value to assign.

◆ SetField() [5/21]

OGRFeature::SetField ( const char *  pszFName,
GIntBig  nValue 
)
inline

Set field to 64 bit integer value.

OFTInteger, OFTInteger64 and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
nValuethe value to assign.

◆ SetField() [6/21]

OGRFeature::SetField ( const char *  pszFName,
int  nCount,
const double *  padfValues 
)
inline

This method currently on has an effect of OFTIntegerList, OFTInteger64List, OFTRealList fields.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
nCountthe number of values in the list being assigned.
padfValuesthe values to assign.

◆ SetField() [7/21]

OGRFeature::SetField ( const char *  pszFName,
int  nCount,
const GIntBig panValues 
)
inline

Set field to list of 64 bit integers value.

This method currently on has an effect of OFTIntegerList, OFTInteger64List and OFTRealList fields.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
nCountthe number of values in the list being assigned.
panValuesthe values to assign.

◆ SetField() [8/21]

OGRFeature::SetField ( const char *  pszFName,
int  nCount,
const int *  panValues 
)
inline

This method currently on has an effect of OFTIntegerList, OFTInteger64List and OFTRealList fields.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
nCountthe number of values in the list being assigned.
panValuesthe values to assign.

◆ SetField() [9/21]

OGRFeature::SetField ( const char *  pszFName,
int  nValue 
)
inline

Set field to integer value.

OFTInteger, OFTInteger64 and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
nValuethe value to assign.

◆ SetField() [10/21]

OGRFeature::SetField ( const char *  pszFName,
int  nYear,
int  nMonth,
int  nDay,
int  nHour = 0,
int  nMinute = 0,
float  fSecond = 0.f,
int  nTZFlag = 0 
)
inline

Set field to date.

This method currently only has an effect for OFTDate, OFTTime and OFTDateTime fields.

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
pszFNamethe name of the field to set.
nYear(including century)
nMonth(1-12)
nDay(1-31)
nHour(0-23)
nMinute(0-59)
fSecond(0-59, with millisecond accuracy)
nTZFlag(0=unknown, 1=localtime, 100=GMT, see data model for details)

◆ SetField() [11/21]

void OGRFeature::SetField ( int  iField,
const char *const *  papszValues 
)

Set field to list of strings value.

This method currently on has an effect of OFTStringList fields.

This method is the same as the C function OGR_F_SetFieldStringList().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to set, from 0 to GetFieldCount()-1.
papszValuesthe values to assign. List of NUL-terminated string, ending with a NULL pointer.

◆ SetField() [12/21]

void OGRFeature::SetField ( int  iField,
const char *  pszValue 
)

Set field to string value.

OFTInteger fields will be set based on an atoi() conversion of the string. OFTInteger64 fields will be set based on an CPLAtoGIntBig() conversion of the string. OFTReal fields will be set based on an CPLAtof() conversion of the string. Other field types may be unaffected.

This method is the same as the C function OGR_F_SetFieldString().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
pszValuethe value to assign.

◆ SetField() [13/21]

void OGRFeature::SetField ( int  iField,
const OGRField puValue 
)

Set field.

The passed value OGRField must be of exactly the same type as the target field, or an application crash may occur. The passed value is copied, and will not be affected. It remains the responsibility of the caller.

This method is the same as the C function OGR_F_SetFieldRaw().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
puValuethe value to assign.

◆ SetField() [14/21]

void OGRFeature::SetField ( int  iField,
double  dfValue 
)

Set field to double value.

OFTInteger, OFTInteger64 and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

This method is the same as the C function OGR_F_SetFieldDouble().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
dfValuethe value to assign.

◆ SetField() [15/21]

void OGRFeature::SetField ( int  iField,
GIntBig  nValue 
)

Set field to 64 bit integer value.

OFTInteger, OFTInteger64 and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

This method is the same as the C function OGR_F_SetFieldInteger64().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
nValuethe value to assign.
Since
GDAL 2.0

◆ SetField() [16/21]

void OGRFeature::SetField ( int  iField,
int  nCount,
const double *  padfValues 
)

Set field to list of doubles value.

This method currently on has an effect of OFTIntegerList, OFTInteger64List, OFTRealList fields.

This method is the same as the C function OGR_F_SetFieldDoubleList().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to set, from 0 to GetFieldCount()-1.
nCountthe number of values in the list being assigned.
padfValuesthe values to assign.

◆ SetField() [17/21]

void OGRFeature::SetField ( int  iField,
int  nCount,
const GIntBig panValues 
)

Set field to list of 64 bit integers value.

This method currently on has an effect of OFTIntegerList, OFTInteger64List and OFTRealList fields.

This method is the same as the C function OGR_F_SetFieldInteger64List().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to set, from 0 to GetFieldCount()-1.
nCountthe number of values in the list being assigned.
panValuesthe values to assign.
Since
GDAL 2.0

◆ SetField() [18/21]

void OGRFeature::SetField ( int  iField,
int  nCount,
const int *  panValues 
)

Set field to list of integers value.

This method currently on has an effect of OFTIntegerList, OFTInteger64List and OFTRealList fields.

This method is the same as the C function OGR_F_SetFieldIntegerList().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to set, from 0 to GetFieldCount()-1.
nCountthe number of values in the list being assigned.
panValuesthe values to assign.

◆ SetField() [19/21]

void OGRFeature::SetField ( int  iField,
int  nBytes,
const void *  pabyData 
)

Set field to binary data.

This method currently on has an effect of OFTBinary fields.

This method is the same as the C function OGR_F_SetFieldBinary().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to set, from 0 to GetFieldCount()-1.
nBytesbytes of data being set.
pabyDatathe raw data being applied.

◆ SetField() [20/21]

void OGRFeature::SetField ( int  iField,
int  nValue 
)

Set field to integer value.

OFTInteger, OFTInteger64 and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

This method is the same as the C function OGR_F_SetFieldInteger().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to fetch, from 0 to GetFieldCount()-1.
nValuethe value to assign.

◆ SetField() [21/21]

void OGRFeature::SetField ( int  iField,
int  nYear,
int  nMonth,
int  nDay,
int  nHour = 0,
int  nMinute = 0,
float  fSecond = 0.f,
int  nTZFlag = 0 
)

Set field to date.

This method currently only has an effect for OFTDate, OFTTime and OFTDateTime fields.

This method is the same as the C function OGR_F_SetFieldDateTime().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
iFieldthe field to set, from 0 to GetFieldCount()-1.
nYear(including century)
nMonth(1-12)
nDay(1-31)
nHour(0-23)
nMinute(0-59)
fSecond(0-59, with millisecond accuracy)
nTZFlag(0=unknown, 1=localtime, 100=GMT, see data model for details)

◆ SetFieldNull()

void OGRFeature::SetFieldNull ( int  iField)

Clear a field, marking it as null.

This method is the same as the C function OGR_F_SetFieldNull().

Parameters
iFieldthe field to set to null.
Since
GDAL 2.2

◆ SetFieldsFrom()

OGRErr OGRFeature::SetFieldsFrom ( const OGRFeature poSrcFeature,
const int *  panMap,
int  bForgiving = TRUE,
bool  bUseISO8601ForDateTimeAsString = false 
)

Set fields from another feature.

Overwrite the fields of this feature from the attributes of another. The FID and the style string are not set. The poSrcFeature does not need to have the same OGRFeatureDefn. Field values are copied according to the provided indices map. Field types do not have to exactly match. SetField() method conversion rules will be applied as needed. This is more efficient than OGR_F_SetFrom() in that this doesn't lookup the fields by their names. Particularly useful when the field names don't match.

Parameters
poSrcFeaturethe feature from which geometry, and field values will be copied.
panMapArray of the indices of the feature's fields stored at the corresponding index of the source feature's fields. A value of -1 should be used to ignore the source's field. The array should not be NULL and be as long as the number of fields in the source feature.
bForgivingTRUE if the operation should continue despite lacking output fields matching some of the source fields.
bUseISO8601ForDateTimeAsStringtrue if datetime fields converted to string should use ISO8601 formatting rather than OGR own format.
Returns
OGRERR_NONE if the operation succeeds, even if some values are not transferred, otherwise an error code.

◆ SetFrom() [1/2]

OGRErr OGRFeature::SetFrom ( const OGRFeature poSrcFeature,
const int *  panMap,
int  bForgiving = TRUE,
bool  bUseISO8601ForDateTimeAsString = false 
)

Set one feature from another.

Overwrite the contents of this feature from the geometry and attributes of another. The poSrcFeature does not need to have the same OGRFeatureDefn. Field values are copied according to the provided indices map. Field types do not have to exactly match. SetField() method conversion rules will be applied as needed. This is more efficient than OGR_F_SetFrom() in that this doesn't lookup the fields by their names. Particularly useful when the field names don't match.

This method is the same as the C function OGR_F_SetFromWithMap().

Parameters
poSrcFeaturethe feature from which geometry, and field values will be copied.
panMapArray of the indices of the feature's fields stored at the corresponding index of the source feature's fields. A value of -1 should be used to ignore the source's field. The array should not be NULL and be as long as the number of fields in the source feature.
bForgivingTRUE if the operation should continue despite lacking output fields matching some of the source fields.
bUseISO8601ForDateTimeAsStringtrue if datetime fields converted to string should use ISO8601 formatting rather than OGR own format.
Returns
OGRERR_NONE if the operation succeeds, even if some values are not transferred, otherwise an error code.

◆ SetFrom() [2/2]

OGRErr OGRFeature::SetFrom ( const OGRFeature poSrcFeature,
int  bForgiving = TRUE 
)

Set one feature from another.

Overwrite the contents of this feature from the geometry and attributes of another. The poSrcFeature does not need to have the same OGRFeatureDefn. Field values are copied by corresponding field names. Field types do not have to exactly match. SetField() method conversion rules will be applied as needed.

This method is the same as the C function OGR_F_SetFrom().

Parameters
poSrcFeaturethe feature from which geometry, and field values will be copied.
bForgivingTRUE if the operation should continue despite lacking output fields matching some of the source fields.
Returns
OGRERR_NONE if the operation succeeds, even if some values are not transferred, otherwise an error code.

◆ SetGeometry()

OGRErr OGRFeature::SetGeometry ( const OGRGeometry poGeomIn)

Set feature geometry.

This method updates the features geometry, and operate exactly as SetGeometryDirectly(), except that this method does not assume ownership of the passed geometry, but instead makes a copy of it.

This method is the same as the C function OGR_F_SetGeometry().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
poGeomInnew geometry to apply to feature. Passing NULL value here is correct and it will result in deallocation of currently assigned geometry without assigning new one.
Returns
OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if the geometry type is illegal for the OGRFeatureDefn (checking not yet implemented).

◆ SetGeometryDirectly()

OGRErr OGRFeature::SetGeometryDirectly ( OGRGeometry poGeomIn)

Set feature geometry.

This method updates the features geometry, and operate exactly as SetGeometry(), except that this method assumes ownership of the passed geometry (even in case of failure of that function).

This method is the same as the C function OGR_F_SetGeometryDirectly().

Note
This method has only an effect on the in-memory feature object. If this object comes from a layer and the modifications must be serialized back to the datasource, OGR_L_SetFeature() must be used afterwards. Or if this is a new feature, OGR_L_CreateFeature() must be used afterwards.
Parameters
poGeomInnew geometry to apply to feature. Passing NULL value here is correct and it will result in deallocation of currently assigned geometry without assigning new one.
Returns
OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if the geometry type is illegal for the OGRFeatureDefn (checking not yet implemented).

◆ SetGeomField()

OGRErr OGRFeature::SetGeomField ( int  iField,
const OGRGeometry poGeomIn 
)

Set feature geometry of a specified geometry field.

This method updates the features geometry, and operate exactly as SetGeomFieldDirectly(), except that this method does not assume ownership of the passed geometry, but instead makes a copy of it.

This method is the same as the C function OGR_F_SetGeomField().

Parameters
iFieldgeometry field to set.
poGeomInnew geometry to apply to feature. Passing NULL value here is correct and it will result in deallocation of currently assigned geometry without assigning new one.
Returns
OGRERR_NONE if successful, or OGRERR_FAILURE if the index is invalid, or OGR_UNSUPPORTED_GEOMETRY_TYPE if the geometry type is illegal for the OGRFeatureDefn (checking not yet implemented).
Since
GDAL 1.11

◆ SetGeomFieldDirectly()

OGRErr OGRFeature::SetGeomFieldDirectly ( int  iField,
OGRGeometry poGeomIn 
)

Set feature geometry of a specified geometry field.

This method updates the features geometry, and operate exactly as SetGeomField(), except that this method assumes ownership of the passed geometry (even in case of failure of that function).

This method is the same as the C function OGR_F_SetGeomFieldDirectly().

Parameters
iFieldgeometry field to set.
poGeomInnew geometry to apply to feature. Passing NULL value here is correct and it will result in deallocation of currently assigned geometry without assigning new one.
Returns
OGRERR_NONE if successful, or OGRERR_FAILURE if the index is invalid, or OGRERR_UNSUPPORTED_GEOMETRY_TYPE if the geometry type is illegal for the OGRFeatureDefn (checking not yet implemented).
Since
GDAL 1.11

◆ SetNativeData()

void OGRFeature::SetNativeData ( const char *  pszNativeData)

Sets the native data for the feature.

The native data is the representation in a "natural" form that comes from the driver that created this feature, or that is aimed at an output driver. The native data may be in different format, which is indicated by GetNativeMediaType().

This function is the same as the C function OGR_F_SetNativeData().

Parameters
pszNativeDataa string with the native data, or NULL if there is none.
Since
GDAL 2.1
See also
https://trac.osgeo.org/gdal/wiki/rfc60_improved_roundtripping_in_ogr

◆ SetNativeMediaType()

void OGRFeature::SetNativeMediaType ( const char *  pszNativeMediaType)

Sets the native media type for the feature.

The native media type is the identifier for the format of the native data. It follows the IANA RFC 2045 (see https://en.wikipedia.org/wiki/Media_type), e.g. "application/vnd.geo+json" for JSon.

This function is the same as the C function OGR_F_SetNativeMediaType().

Parameters
pszNativeMediaTypea string with the native media type, or NULL if there is none.
Since
GDAL 2.1
See also
https://trac.osgeo.org/gdal/wiki/rfc60_improved_roundtripping_in_ogr

◆ SetStyleString()

void OGRFeature::SetStyleString ( const char *  pszString)
virtual

Set feature style string.

This method operate exactly as OGRFeature::SetStyleStringDirectly() except that it does not assume ownership of the passed string, but instead makes a copy of it.

This method is the same as the C function OGR_F_SetStyleString().

Parameters
pszStringthe style string to apply to this feature, cannot be NULL.

◆ SetStyleStringDirectly()

void OGRFeature::SetStyleStringDirectly ( char *  pszString)
virtual

Set feature style string.

This method operate exactly as OGRFeature::SetStyleString() except that it assumes ownership of the passed string.

This method is the same as the C function OGR_F_SetStyleStringDirectly().

Parameters
pszStringthe style string to apply to this feature, cannot be NULL.

◆ SetStyleTable()

void OGRFeature::SetStyleTable ( OGRStyleTable poStyleTable)
virtual

Set style table.

Parameters
poStyleTablenew style table (will be cloned)

◆ SetStyleTableDirectly()

void OGRFeature::SetStyleTableDirectly ( OGRStyleTable poStyleTable)
virtual

Set style table.

Parameters
poStyleTablenew style table (ownership transferred to the object)

◆ StealGeometry() [1/2]

OGRGeometry * OGRFeature::StealGeometry ( )

Take away ownership of geometry.

Fetch the geometry from this feature, and clear the reference to the geometry on the feature. This is a mechanism for the application to take over ownership of the geometry from the feature without copying. Sort of an inverse to SetGeometryDirectly().

After this call the OGRFeature will have a NULL geometry.

Returns
the pointer to the geometry.

◆ StealGeometry() [2/2]

OGRGeometry * OGRFeature::StealGeometry ( int  iGeomField)

Take away ownership of geometry.

Fetch the geometry from this feature, and clear the reference to the geometry on the feature. This is a mechanism for the application to take over ownership of the geometry from the feature without copying. Sort of an inverse to SetGeometryDirectly().

After this call the OGRFeature will have a NULL geometry.

Parameters
iGeomFieldindex of the geometry field.
Returns
the pointer to the geometry.

◆ ToHandle()

static OGRFeatureH OGRFeature::ToHandle ( OGRFeature poFeature)
inlinestatic

Convert a OGRFeature* to a OGRFeatureH.

Since
GDAL 2.3

◆ UnsetField()

void OGRFeature::UnsetField ( int  iField)

Clear a field, marking it as unset.

This method is the same as the C function OGR_F_UnsetField().

Parameters
iFieldthe field to unset.

◆ Validate()

int OGRFeature::Validate ( int  nValidateFlags,
int  bEmitError 
) const

Validate that a feature meets constraints of its schema.

The scope of test is specified with the nValidateFlags parameter.

Regarding OGR_F_VAL_WIDTH, the test is done assuming the string width must be interpreted as the number of UTF-8 characters. Some drivers might interpret the width as the number of bytes instead. So this test is rather conservative (if it fails, then it will fail for all interpretations).

This method is the same as the C function OGR_F_Validate().

Parameters
nValidateFlagsOGR_F_VAL_ALL or combination of OGR_F_VAL_NULL, OGR_F_VAL_GEOM_TYPE, OGR_F_VAL_WIDTH and OGR_F_VAL_ALLOW_NULL_WHEN_DEFAULT, OGR_F_VAL_ALLOW_DIFFERENT_GEOM_DIM with '|' operator
bEmitErrorTRUE if a CPLError() must be emitted when a check fails
Returns
TRUE if all enabled validation tests pass.
Since
GDAL 2.0

The documentation for this class was generated from the following files: