# OGRFeature C++ API¶

## OGRFeature class¶

class OGRFeature

A simple feature, including geometry and attributes.

Public Functions

OGRFeature(OGRFeatureDefn *poDefnIn)

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
• poDefnIn: feature class (layer) definition to which the feature will adhere.

OGRFeature::ConstFieldIterator 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.

Since

GDAL 2.3

OGRFeature::ConstFieldIterator end() const

Return end of field value iterator.

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

Return a field value.

Return

the field value.

Since

GDAL 2.3

Parameters
• iField: the field to fetch, from 0 to GetFieldCount()-1. This is not checked by the method !

OGRFeature::FieldValue operator[](int iField)

Return a field value.

Return

the field value.

Since

GDAL 2.3

Parameters
• iField: the field to fetch, from 0 to GetFieldCount()-1. This is not checked by the method !

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

Return a field value.

Return

Since

GDAL 2.3

Parameters
• pszFieldName: field name

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

Return a field value.

Return

Since

GDAL 2.3

Parameters
• pszFieldName: field name

OGRFeatureDefn *GetDefnRef()

Fetch feature definition.

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

Return

a reference to the feature definition object.

const OGRFeatureDefn *GetDefnRef() const

Fetch feature definition.

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

Return

a reference to the feature definition object.

Since

GDAL 2.3

OGRErr 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.

Return

OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if the geometry type is illegal for the OGRFeatureDefn (checking not yet implemented).

Parameters
• poGeomIn: new 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.

OGRErr 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.

Return

OGRERR_NONE if successful, or OGR_UNSUPPORTED_GEOMETRY_TYPE if the geometry type is illegal for the OGRFeatureDefn (checking not yet implemented).

Parameters
• poGeomIn: new 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.

OGRGeometry *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).

Return

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

const OGRGeometry *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())

Return

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

Since

GDAL 2.3

OGRGeometry *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.

Return

the pointer to the geometry.

int GetGeomFieldCount() const

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().

Return

count of geometry fields.

Since

GDAL 1.11

OGRGeomFieldDefn *GetGeomFieldDefnRef(int iField)

Fetch definition for this geometry field.

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

Return

the field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified.

Since

GDAL 1.11

Parameters

const OGRGeomFieldDefn *GetGeomFieldDefnRef(int iField) const

Fetch definition for this geometry field.

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

Return

the field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified.

Since

GDAL 2.3

Parameters

int GetGeomFieldIndex(const char *pszName) const

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().

Return

the geometry field index, or -1 if no matching geometry field is found.

Since

GDAL 1.11

Parameters
• pszName: the name of the geometry field to search for.

OGRGeometry *GetGeomFieldRef(int iField)

Fetch pointer to feature geometry.

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

Return

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

Since

GDAL 1.11

Parameters
• iField: geometry field to get.

const OGRGeometry *GetGeomFieldRef(int iField) const

Fetch pointer to feature geometry.

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

Return

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

Since

GDAL 2.3

Parameters
• iField: geometry field to get.

OGRGeometry *StealGeometry(int iField)

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.

Return

the pointer to the geometry.

Parameters
• iGeomField: index of the geometry field.

OGRGeometry *GetGeomFieldRef(const char *pszFName)

Fetch pointer to feature geometry.

Return

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

Since

GDAL 1.11

Parameters
• pszFName: name of geometry field to get.

const OGRGeometry *GetGeomFieldRef(const char *pszFName) const

Fetch pointer to feature geometry.

Return

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

Since

GDAL 2.3

Parameters
• pszFName: name of geometry field to get.

OGRErr 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().

Return

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

Parameters
• iField: geometry field to set.

• poGeomIn: new 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.

OGRErr 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().

Return

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

Parameters
• iField: geometry field to set.

• poGeomIn: new 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.

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().

Return

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

OGRBoolean Equal(const OGRFeature *poFeature) const

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().

Return

TRUE if they are equal, otherwise FALSE.

Parameters
• poFeature: the other feature to test this one against.

int GetFieldCount() const

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().

Return

count of fields.

const OGRFieldDefn *GetFieldDefnRef(int iField) const

Fetch definition for this field.

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

Return

the field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified.

Since

GDAL 2.3

Parameters

OGRFieldDefn *GetFieldDefnRef(int iField)

Fetch definition for this field.

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

Return

the field definition (from the OGRFeatureDefn). This is an internal reference, and should not be deleted or modified.

Parameters

int GetFieldIndex(const char *pszName) const

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().

Return

the field index, or -1 if no matching field is found.

Parameters
• pszName: the name of the field to search for.

int 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().

Return

TRUE if the field has been set, otherwise false.

Parameters
• iField: the field to test.

void UnsetField(int iField)

Clear a field, marking it as unset.

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

Parameters
• iField: the field to unset.

bool IsFieldNull(int iField) const

Test if a field is null.

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

Return

TRUE if the field is null, otherwise false.

Since

GDAL 2.2

Parameters
• iField: the field to test.

void SetFieldNull(int iField)

Clear a field, marking it as null.

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

Since

GDAL 2.2

Parameters
• iField: the field to set to null.

bool 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().

Return

TRUE if the field is set and not null, otherwise false.

Since

GDAL 2.2

Parameters
• iField: the field to test.

OGRField *GetRawFieldRef(int i)

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

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

Return

the returned pointer is to an internal data structure, and should not be freed, or modified.

Parameters

const OGRField *GetRawFieldRef(int i) const

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

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

Return

the returned pointer is to an internal data structure, and should not be freed, or modified.

Since

GDAL 2.3

Parameters

int GetFieldAsInteger(int i) 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().

Return

the field value.

Parameters

GIntBig GetFieldAsInteger64(int i) 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().

Return

the field value.

Since

GDAL 2.0

Parameters

double GetFieldAsDouble(int i) 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().

Return

the field value.

Parameters

const char *GetFieldAsString(int i) const

Fetch field value as a string.

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.

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

Return

the field value. This string is internal, and should not be modified, or freed. Its lifetime may be very brief.

Parameters

const int *GetFieldAsIntegerList(int i, 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().

Return

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.

Parameters
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• pnCount: an integer to put the list count (number of integers) into.

const GIntBig *GetFieldAsInteger64List(int i, 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().

Return

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

Parameters
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• pnCount: an integer to put the list count (number of integers) into.

const double *GetFieldAsDoubleList(int i, 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().

Return

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.

Parameters
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• pnCount: an integer to put the list count (number of doubles) into.

char **GetFieldAsStringList(int i) 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().

Return

the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief.

Parameters

GByte *GetFieldAsBinary(int i, int *pnCount) 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().

Return

the field value. This data is internal, and should not be modified, or freed. Its lifetime may be very brief.

Parameters
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• pnBytes: location to put the number of bytes returned.

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.

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

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

Return

TRUE on success or FALSE on failure.

Parameters
• iField: the 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)

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.

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

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

Return

TRUE on success or FALSE on failure.

Parameters
• iField: the 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)

char *GetFieldAsSerializedJSon(int i) const

Fetch field value as a serialized JSon object.

Currently this method only works for OFTStringList, OFTIntegerList, OFTInteger64List and OFTRealList

Return

a string that must be de-allocate with CPLFree()

Since

GDAL 2.2

Parameters

GetFieldAsInteger(const char *pszFName) 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.

Return

the field value.

Parameters
• pszFName: the name of the field to fetch.

GetFieldAsInteger64(const char *pszFName) 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.

Return

the field value.

Parameters
• pszFName: the name of the field to fetch.

GetFieldAsDouble(const char *pszFName) 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.

Return

the field value.

Parameters
• pszFName: the name of the field to fetch.

GetFieldAsString(const char *pszFName) const

Fetch field value as a string.

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.

Return

the field value. This string is internal, and should not be modified, or freed. Its lifetime may be very brief.

Parameters
• pszFName: the name of the field to fetch.

GetFieldAsIntegerList(const char *pszFName, int *pnCount) const

Fetch field value as a list of integers.

Currently this method only works for OFTIntegerList fields.

Return

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.

Parameters
• pszFName: the name of the field to fetch.

• pnCount: an integer to put the list count (number of integers) into.

GetFieldAsInteger64List(const char *pszFName, int *pnCount) const

Fetch field value as a list of 64 bit integers.

Currently this method only works for OFTInteger64List fields.

Return

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

Parameters
• pszFName: the name of the field to fetch.

• pnCount: an integer to put the list count (number of integers) into.

GetFieldAsDoubleList(const char *pszFName, int *pnCount) const

Fetch field value as a list of doubles.

Currently this method only works for OFTRealList fields.

Return

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.

Parameters
• pszFName: the name of the field to fetch.

• pnCount: an integer to put the list count (number of doubles) into.

GetFieldAsStringList(const char *pszFName) 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().

Return

the field value. This list is internal, and should not be modified, or freed. Its lifetime may be very brief.

Parameters
• pszFName: the name of the field to fetch.

void SetField(int i, 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
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• nValue: the value to assign.

void SetField(int i, 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.

Since

GDAL 2.0

Parameters
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• nValue: the value to assign.

void SetField(int i, 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
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• dfValue: the value to assign.

void SetField(int i, 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
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• pszValue: the value to assign.

void SetField(int i, 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
• iField: the field to set, from 0 to GetFieldCount()-1.

• nCount: the number of values in the list being assigned.

• panValues: the values to assign.

void SetField(int i, 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_SetFieldIntege64rList().

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.

Since

GDAL 2.0

Parameters
• iField: the field to set, from 0 to GetFieldCount()-1.

• nCount: the number of values in the list being assigned.

• panValues: the values to assign.

void SetField(int i, 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
• iField: the field to set, from 0 to GetFieldCount()-1.

• nCount: the number of values in the list being assigned.

• padfValues: the values to assign.

void SetField(int i, 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
• iField: the field to set, from 0 to GetFieldCount()-1.

• papszValues: the values to assign. List of NUL-terminated string, ending with a NULL pointer.

void SetField(int i, 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
• iField: the field to fetch, from 0 to GetFieldCount()-1.

• puValue: the value to assign.

void SetField(int i, int nCount, const void *pabyBinary)

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
• iField: the field to set, from 0 to GetFieldCount()-1.

• nBytes: bytes of data being set.

• pabyData: the raw data being applied.

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.

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
• iField: the 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)

SetField(const char *pszFName, 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.

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
• pszFName: the name of the field to set.

• nValue: the value to assign.

SetField(const char *pszFName, 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.

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
• pszFName: the name of the field to set.

• nValue: the value to assign.

SetField(const char *pszFName, 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.

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
• pszFName: the name of the field to set.

• dfValue: the value to assign.

SetField(const char *pszFName, 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.

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
• pszFName: the name of the field to set.

• pszValue: the value to assign.

SetField(const char *pszFName, 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.

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
• pszFName: the name of the field to set.

• nCount: the number of values in the list being assigned.

• panValues: the values to assign.

SetField(const char *pszFName, 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.

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
• pszFName: the name of the field to set.

• nCount: the number of values in the list being assigned.

• panValues: the values to assign.

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

Set field to list of doubles value.

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
• pszFName: the name of the field to set.

• nCount: the number of values in the list being assigned.

• padfValues: the values to assign.

SetField(const char *pszFName, const char *const *papszValues)

Set field to list of strings value.

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
• pszFName: the name of the field to set.

• papszValues: the values to assign. List of NUL-terminated string, ending with a NULL pointer.

SetField(const char *pszFName, 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.

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
• pszFName: the name of the field to set.

• puValue: the value to assign.

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.

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
• pszFName: the 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)

GIntBig GetFID() const

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)

Return

feature id or OGRNullFID if none has been assigned.

OGRErr SetFID(GIntBig nFIDIn)

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().

Return

On success OGRERR_NONE, or on failure some other value.

Parameters
• nFIDIn: the new feature identifier value to assign.

void DumpReadable(FILE *fpOut, char **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
• fpOut: the stream to write to, such as stdout. If NULL stdout will be used.

• papszOptions: NULL terminated list of options (may be NULL)

OGRErr 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().

Return

OGRERR_NONE if the operation succeeds, even if some values are not transferred, otherwise an error code.

Parameters
• poSrcFeature: the feature from which geometry, and field values will be copied.

• bForgiving: TRUE if the operation should continue despite lacking output fields matching some of the source fields.

OGRErr SetFrom(const OGRFeature *poSrcFeature, const int *panMap, 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 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().

Return

OGRERR_NONE if the operation succeeds, even if some values are not transferred, otherwise an error code.

Parameters
• poSrcFeature: the feature from which geometry, and field values will be copied.

• panMap: Array 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.

• bForgiving: TRUE if the operation should continue despite lacking output fields matching some of the source fields.

OGRErr SetFieldsFrom(const OGRFeature *poSrcFeature, const int *panMap, int bForgiving = TRUE)

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.

Return

OGRERR_NONE if the operation succeeds, even if some values are not transferred, otherwise an error code.

Parameters
• poSrcFeature: the feature from which geometry, and field values will be copied.

• panMap: Array 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.

• bForgiving: TRUE if the operation should continue despite lacking output fields matching some of the source fields.

int 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().

Return

TRUE if all enabled validation tests pass.

Since

GDAL 2.0

Parameters
• nValidateFlags: OGR_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

• bEmitError: TRUE if a CPLError() must be emitted when a check fails

void 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().

Since

GDAL 2.0

Parameters
• bNotNullableOnly: if we should fill only unset fields with a not-null constraint.

• papszOptions: unused currently. Must be set to NULL.

const char *GetStyleString() const

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().

Return

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

void SetStyleString(const char *pszString)

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
• pszString: the style string to apply to this feature, cannot be NULL.

void SetStyleStringDirectly(char *pszString)

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
• pszString: the style string to apply to this feature, cannot be NULL.

virtual OGRStyleTable *GetStyleTable() const

Return style table.

Return

style table.

void SetStyleTable(OGRStyleTable *poStyleTable)

Set style table.

Parameters
• poStyleTable: new style table (will be cloned)

void SetStyleTableDirectly(OGRStyleTable *poStyleTable)

Set style table.

Parameters
• poStyleTable: new style table (ownership transferred to the object)

const char *GetNativeData() const

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().

Return

a string with the native data, or NULL if there is none.

Since

GDAL 2.1

See

const char *GetNativeMediaType() const

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().

Return

a string with the native media type, or NULL if there is none.

Since

GDAL 2.1

See

void 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().

Since

GDAL 2.1

See
Parameters
• pszNativeData: a string with the native data, or NULL if there is none.

void 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().

Since

GDAL 2.1

See
Parameters
• pszNativeMediaType: a string with the native media type, or NULL if there is none.

Public Static Functions

OGRFeature *CreateFeature(OGRFeatureDefn *poDefn)

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().

Return

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().

Parameters
• poDefn: Feature definition defining schema.

void DestroyFeature(OGRFeature *poFeature)

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
• poFeature: the feature to delete.

static OGRFeatureH ToHandle(OGRFeature *poFeature)

Convert a OGRFeature* to a OGRFeatureH.

Since

GDAL 2.3

static OGRFeature *FromHandle(OGRFeatureH hFeature)

Convert a OGRFeatureH to a OGRFeature*.

Since

GDAL 2.3

class ConstFieldIterator

Field value iterator class.

class FieldNotFoundException : public exception

class FieldValue

Field value.

Public Functions

OGRFeature::FieldValue &operator=(const FieldValue &oOther)

Set a field value from another one.

OGRFeature::FieldValue &operator=(int nVal)

Set an integer value to the field.

OGRFeature::FieldValue &operator=(GIntBig nVal)

Set an integer value to the field.

OGRFeature::FieldValue &operator=(double dfVal)

Set a real value to the field.

OGRFeature::FieldValue &operator=(const char *pszVal)

Set a string value to the field.

OGRFeature::FieldValue &operator=(const std::string &osVal)

Set a string value to the field.

OGRFeature::FieldValue &operator=(const std::vector<int> &oArray)

Set an array of integer to the field.

OGRFeature::FieldValue &operator=(const std::vector<GIntBig> &oArray)

Set an array of big integer to the field.

OGRFeature::FieldValue &operator=(const std::vector<double> &oArray)

Set an array of double to the field.

OGRFeature::FieldValue &operator=(const std::vector<std::string> &oArray)

Set an array of strings to the field.

OGRFeature::FieldValue &operator=(CSLConstList papszValues)

Set an array of strings to the field.

void SetNull()

Set a null value to the field.

void clear()

Unset the field.

void Unset()

Unset the field.

void SetDateTime(int nYear, int nMonth, int nDay, int nHour = 0, int nMinute = 0, float fSecond = 0.f, int nTZFlag = 0)

Set date time value/.

int GetIndex() const

Return field index.

const OGRFieldDefn *GetDefn() const

Return field definition.

const char *GetName() const

Return field name.

OGRFieldType GetType() const

Return field type.

OGRFieldSubType GetSubType() const

Return field subtype.

bool empty() const

Return whether the field value is unset/empty.

bool IsUnset() const

Return whether the field value is unset/empty.

bool IsNull() const

Return whether the field value is null.

const OGRField *GetRawValue() const

Return the raw field value.

int GetInteger() const

Return the integer value.

Only use that method if and only if GetType() == OFTInteger.

GIntBig GetInteger64() const

Return the 64-bit integer value.

Only use that method if and only if GetType() == OFTInteger64.

double GetDouble() const

Return the double value.

Only use that method if and only if GetType() == OFTReal.

const char *GetString() const

Return the string value.

Only use that method if and only if GetType() == OFTString.

bool GetDateTime(int *pnYear, int *pnMonth, int *pnDay, int *pnHour, int *pnMinute, float *pfSecond, int *pnTZFlag) const

Return the date/time/datetime value.

operator int() const

Return the field value as integer, with potential conversion.

operator GIntBig() const

Return the field value as 64-bit integer, with potential conversion.

operator double() const

Return the field value as double, with potential conversion.

operator const char *() const

Return the field value as string, with potential conversion.

operator const std::vector<int>&() const

Return the field value as integer list, with potential conversion.

operator const std::vector<GIntBig>&() const

Return the field value as 64-bit integer list, with potential conversion.

operator const std::vector<double>&() const

Return the field value as double list, with potential conversion.

operator const std::vector<std::string>&() const

Return the field value as string list, with potential conversion.

operator CSLConstList() const

Return the field value as string list, with potential conversion.

int GetAsInteger() const

Return the field value as integer, with potential conversion.

GIntBig GetAsInteger64() const

Return the field value as 64-bit integer, with potential conversion.

double GetAsDouble() const

Return the field value as double, with potential conversion.

const char *GetAsString() const

Return the field value as string, with potential conversion.

const std::vector<int> &GetAsIntegerList() const

Return the field value as integer list, with potential conversion.

const std::vector<GIntBig> &GetAsInteger64List() const

Return the field value as 64-bit integer list, with potential conversion.

const std::vector<double> &GetAsDoubleList() const

Return the field value as double list, with potential conversion.

const std::vector<std::string> &GetAsStringList() const

Return the field value as string list, with potential conversion.

## OGRFeatureDefn class¶

class OGRFeatureDefn

Definition of a feature class or feature layer.

This object contains schema information for a set of OGRFeatures. In table based systems, an OGRFeatureDefn is essentially a layer. In more object oriented approaches (such as SF CORBA) this can represent a class of features but doesn’t necessarily relate to all of a layer, or just one layer.

This object also can contain some other information such as a name and potentially other metadata.

It is essentially a collection of field descriptions (OGRFieldDefn class). Starting with GDAL 1.11, in addition to attribute fields, it can also contain multiple geometry fields (OGRGeomFieldDefn class).

It is reasonable for different translators to derive classes from OGRFeatureDefn with additional translator specific information.

Public Functions

OGRFeatureDefn(const char *pszName = nullptr)

Constructor.

The OGRFeatureDefn maintains a reference count, but this starts at zero. It is mainly intended to represent a count of OGRFeature’s based on this definition.

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

Parameters
• pszName: the name to be assigned to this layer/class. It does not need to be unique.

void SetName(const char *pszName)

Change name of this OGRFeatureDefn.

Since

GDAL 2.3

Parameters
• pszName: feature definition name

const char *GetName() const

Get name of this OGRFeatureDefn.

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

Return

the name. This name is internal and should not be modified, or freed.

int GetFieldCount() const

Fetch number of fields on this feature.

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

Return

count of fields.

OGRFieldDefn *GetFieldDefn(int i)

Fetch field definition.

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

Return

a pointer to an internal field definition object or NULL if invalid index. This object should not be modified or freed by the application.

Parameters
• iField: the field to fetch, between 0 and GetFieldCount() - 1.

const OGRFieldDefn *GetFieldDefn(int i) const

Fetch field definition.

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

Return

a pointer to an internal field definition object or NULL if invalid index. This object should not be modified or freed by the application.

Since

GDAL 2.3

Parameters
• iField: the field to fetch, between 0 and GetFieldCount() - 1.

int GetFieldIndex(const char *pszFieldName) const

Find field by name.

The field index of the first field matching the passed field name (case insensitively) is returned.

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

Return

the field index, or -1 if no match found.

Parameters
• pszFieldName: the field name to search for.

int GetFieldIndexCaseSensitive(const char *pszFieldName) const

Find field by name, in a case sensitive way.

The field index of the first field matching the passed field name is returned.

Return

the field index, or -1 if no match found.

Parameters
• pszFieldName: the field name to search for.

void AddFieldDefn(OGRFieldDefn *poNewDefn)

To add a new field definition to a layer definition, do not use this function directly, but use OGRLayer::CreateField() instead.

This method should only be called while there are no OGRFeature objects in existence based on this OGRFeatureDefn. The OGRFieldDefn passed in is copied, and remains the responsibility of the caller.

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

Parameters
• poNewDefn: the definition of the new field.

OGRErr DeleteFieldDefn(int iField)

Delete an existing field definition.

To delete an existing field definition from a layer definition, do not use this function directly, but use OGRLayer::DeleteField() instead.

This method should only be called while there are no OGRFeature objects in existence based on this OGRFeatureDefn.

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

Return

OGRERR_NONE in case of success.

Since

OGR 1.9.0

Parameters
• iField: the index of the field definition.

OGRErr ReorderFieldDefns(int *panMap)

Reorder the field definitions in the array of the feature definition.

To reorder the field definitions in a layer definition, do not use this function directly, but use OGR_L_ReorderFields() instead.

This method should only be called while there are no OGRFeature objects in existence based on this OGRFeatureDefn.

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

Return

OGRERR_NONE in case of success.

Since

OGR 1.9.0

Parameters
• panMap: an array of GetFieldCount() elements which is a permutation of [0, GetFieldCount()-1]. panMap is such that, for each field definition at position i after reordering, its position before reordering was panMap[i].

int GetGeomFieldCount() const

Fetch number of geometry fields on this feature.

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

Return

count of geometry fields.

Since

GDAL 1.11

OGRGeomFieldDefn *GetGeomFieldDefn(int i)

Fetch geometry field definition.

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

Return

a pointer to an internal field definition object or NULL if invalid index. This object should not be modified or freed by the application.

Since

GDAL 1.11

Parameters
• iGeomField: the geometry field to fetch, between 0 and GetGeomFieldCount() - 1.

const OGRGeomFieldDefn *GetGeomFieldDefn(int i) const

Fetch geometry field definition.

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

Return

a pointer to an internal field definition object or NULL if invalid index. This object should not be modified or freed by the application.

Since

GDAL 2.3

Parameters
• iGeomField: the geometry field to fetch, between 0 and GetGeomFieldCount() - 1.

int GetGeomFieldIndex(const char *pszGeomFieldName) const

Find geometry field by name.

The geometry field index of the first geometry field matching the passed field name (case insensitively) is returned.

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

Return

the geometry field index, or -1 if no match found.

Parameters
• pszGeomFieldName: the geometry field name to search for.

void AddGeomFieldDefn(OGRGeomFieldDefn *poNewDefn, int bCopy = TRUE)

Add a new geometry field definition.

To add a new geometry field definition to a layer definition, do not use this function directly, but use OGRLayer::CreateGeomField() instead.

This method does an internal copy of the passed geometry field definition, unless bCopy is set to FALSE (in which case it takes ownership of the field definition.

This method should only be called while there are no OGRFeature objects in existence based on this OGRFeatureDefn. The OGRGeomFieldDefn passed in is copied, and remains the responsibility of the caller.

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

Since

GDAL 1.11

Parameters
• poNewDefn: the definition of the new geometry field.

• bCopy: whether poNewDefn should be copied.

OGRErr DeleteGeomFieldDefn(int iGeomField)

Delete an existing geometry field definition.

To delete an existing field definition from a layer definition, do not use this function directly, but use OGRLayer::DeleteGeomField() instead.

This method should only be called while there are no OGRFeature objects in existence based on this OGRFeatureDefn.

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

Return

OGRERR_NONE in case of success.

Since

GDAL 1.11

Parameters
• iGeomField: the index of the geometry field definition.

OGRwkbGeometryType GetGeomType() const

Fetch the geometry base type.

Note that some drivers are unable to determine a specific geometry type for a layer, in which case wkbUnknown is returned. A value of wkbNone indicates no geometry is available for the layer at all. Many drivers do not properly mark the geometry type as 25D even if some or all geometries are in fact 25D. A few (broken) drivers return wkbPolygon for layers that also include wkbMultiPolygon.

Starting with GDAL 1.11, this method returns GetGeomFieldDefn(0)->GetType().

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

Return

the base type for all geometry related to this definition.

void SetGeomType(OGRwkbGeometryType eNewType)

Assign the base geometry type for this layer.

All geometry objects using this type must be of the defined type or a derived type. The default upon creation is wkbUnknown which allows for any geometry type. The geometry type should generally not be changed after any OGRFeatures have been created against this definition.

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

Starting with GDAL 1.11, this method calls GetGeomFieldDefn(0)->SetType().

Parameters
• eNewType: the new type to assign.

OGRFeatureDefn *Clone() const

Create a copy of this feature definition.

Creates a deep copy of the feature definition.

Return

the copy.

int Reference()

Increments the reference count by one.

The reference count is used keep track of the number of OGRFeature objects referencing this definition.

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

Return

the updated reference count.

int Dereference()

Decrements the reference count by one.

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

Return

the updated reference count.

int GetReferenceCount() const

Fetch current reference count.

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

Return

the current reference count.

void Release()

Drop a reference to this object, and destroy if no longer referenced.

int IsGeometryIgnored() const

Determine whether the geometry can be omitted when fetching features.

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

Starting with GDAL 1.11, this method returns GetGeomFieldDefn(0)->IsIgnored().

Return

ignore state

void SetGeometryIgnored(int bIgnore)

Set whether the geometry can be omitted when fetching features.

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

Starting with GDAL 1.11, this method calls GetGeomFieldDefn(0)->SetIgnored().

Parameters
• bIgnore: ignore state

int IsStyleIgnored() const

Determine whether the style can be omitted when fetching features.

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

Return

ignore state

void SetStyleIgnored(int bIgnore)

Set whether the style can be omitted when fetching features.

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

Parameters
• bIgnore: ignore state

int IsSame(const OGRFeatureDefn *poOtherFeatureDefn) const

Test if the feature definition is identical to the other one.

Return

TRUE if the feature definition is identical to the other one.

Parameters
• poOtherFeatureDefn: the other feature definition to compare to.

std::vector<int> ComputeMapForSetFrom(const OGRFeatureDefn *poSrcFDefn, bool bForgiving = true) const

Compute the map from source to target field that can be passed to SetFrom().

Return

an array of size poSrcFDefn->GetFieldCount() if everything succeeds, or empty in case a source field definition was not found in the target layer and bForgiving == true.

Since

GDAL 2.3

Parameters
• poSrcFDefn: the feature definition of source features later passed to SetFrom()

• bForgiving: true if the operation should continue despite lacking output fields matching some of the source fields.

Public Static Functions

OGRFeatureDefn *CreateFeatureDefn(const char *pszName = nullptr)

Create a new feature definition object.

Return

new feature definition object.

Parameters
• pszName: name

void DestroyFeatureDefn(OGRFeatureDefn *poDefn)

Destroy a feature definition.

Parameters
• poDefn: feature definition.

static OGRFeatureDefnH ToHandle(OGRFeatureDefn *poFeatureDefn)

Convert a OGRFeatureDefn* to a OGRFeatureDefnH.

Since

GDAL 2.3

static OGRFeatureDefn *FromHandle(OGRFeatureDefnH hFeatureDefn)

Convert a OGRFeatureDefnH to a OGRFeatureDefn*.

Since

GDAL 2.3

## OGRFieldDefn class¶

class OGRFieldDefn

Definition of an attribute of an OGRFeatureDefn.

A field is described by :

Public Functions

OGRFieldDefn(const char *pszNameIn, OGRFieldType eTypeIn)

Constructor.

By default, fields have no width, precision, are nullable and not ignored.

Parameters
• pszNameIn: the name of the new field.

• eTypeIn: the type of the new field.

OGRFieldDefn(const OGRFieldDefn *poPrototype)

Constructor.

Create by cloning an existing field definition.

Parameters
• poPrototype: the field definition to clone.

void SetName(const char *pszNameIn)

Reset the name of this field.

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

Parameters
• pszNameIn: the new name to apply.

const char *GetNameRef() const

Fetch name of this field.

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

Return

pointer to an internal name string that should not be freed or modified.

OGRFieldType GetType() const

Fetch type of this field.

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

Return

field type.

void SetType(OGRFieldType eTypeIn)

Set the type of this field.

This should never be done to an OGRFieldDefn that is already part of an OGRFeatureDefn.

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

Parameters
• eTypeIn: the new field type.

OGRFieldSubType GetSubType() const

Fetch subtype of this field.

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

Return

field subtype.

Since

GDAL 2.0

void SetSubType(OGRFieldSubType eSubTypeIn)

Set the subtype of this field.

This should never be done to an OGRFieldDefn that is already part of an OGRFeatureDefn.

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

Since

GDAL 2.0

Parameters
• eSubTypeIn: the new field subtype.

OGRJustification GetJustify() const

Get the justification for this field.

Note: no driver is know to use the concept of field justification.

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

Return

the justification.

void SetJustify(OGRJustification eJustifyIn)

Set the justification for this field.

Note: no driver is know to use the concept of field justification.

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

Parameters
• eJustify: the new justification.

int GetWidth() const

Get the formatting width for this field.

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

Return

the width, zero means no specified width.

void SetWidth(int nWidthIn)

Set the formatting width for this field in characters.

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

Parameters
• nWidth: the new width.

int GetPrecision() const

Get the formatting precision for this field.

This should normally be zero for fields of types other than OFTReal.

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

Return

the precision.

void SetPrecision(int nPrecisionIn)

Set the formatting precision for this field in characters.

This should normally be zero for fields of types other than OFTReal.

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

Parameters
• nPrecision: the new precision.

void Set(const char *pszNameIn, OGRFieldType eTypeIn, int nWidthIn = 0, int nPrecisionIn = 0, OGRJustification eJustifyIn = OJUndefined)

Set defining parameters for a field in one call.

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

Parameters
• pszNameIn: the new name to assign.

• eTypeIn: the new type (one of the OFT values like OFTInteger).

• nWidthIn: the preferred formatting width. Defaults to zero indicating undefined.

• nPrecisionIn: number of decimals places for formatting, defaults to zero indicating undefined.

• eJustifyIn: the formatting justification (OJLeft or OJRight), defaults to OJUndefined.

void SetDefault(const char *pszDefaultIn)

Set default field value.

The default field value is taken into account by drivers (generally those with a SQL interface) that support it at field creation time. OGR will generally not automatically set the default field value to null fields by itself when calling OGRFeature::CreateFeature() / OGRFeature::SetFeature(), but will let the low-level layers to do the job. So retrieving the feature from the layer is recommended.

The accepted values are NULL, a numeric value, a literal value enclosed between single quote characters (and inner single quote characters escaped by repetition of the single quote character), CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or a driver specific expression (that might be ignored by other drivers). For a datetime literal value, format should be ‘YYYY/MM/DD HH:MM:SS[.sss]’ (considered as UTC time).

Drivers that support writing DEFAULT clauses will advertize the GDAL_DCAP_DEFAULT_FIELDS driver metadata item.

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

Since

GDAL 2.0

Parameters
• pszDefaultIn: new default field value or NULL pointer.

const char *GetDefault() const

Get default field value.

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

Return

default field value or NULL.

Since

GDAL 2.0

int IsDefaultDriverSpecific() const

Returns whether the default value is driver specific.

Driver specific default values are those that are not NULL, a numeric value, a literal value enclosed between single quote characters, CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or datetime literal value.

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

Return

TRUE if the default value is driver specific.

Since

GDAL 2.0

int IsIgnored() const

Return whether this field should be omitted when fetching features.

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

Return

ignore state

void SetIgnored(int bIgnoreIn)

Set whether this field should be omitted when fetching features.

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

Parameters
• ignore: ignore state

int IsNullable() const

Return whether this field can receive null values.

By default, fields are nullable.

Even if this method returns FALSE (i.e not-nullable field), it doesn’t mean that OGRFeature::IsFieldSet() will necessary return TRUE, as fields can be temporary unset and null/not-null validation is usually done when OGRLayer::CreateFeature()/SetFeature() is called.

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

Return

TRUE if the field is authorized to be null.

Since

GDAL 2.0

void SetNullable(int bNullableIn)

Set whether this field can receive null values.

By default, fields are nullable, so this method is generally called with FALSE to set a not-null constraint.

Drivers that support writing not-null constraint will advertize the GDAL_DCAP_NOTNULL_FIELDS driver metadata item.

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

Since

GDAL 2.0

Parameters
• bNullableIn: FALSE if the field must have a not-null constraint.

int IsSame(const OGRFieldDefn *poOtherFieldDefn) const

Test if the field definition is identical to the other one.

Return

TRUE if the field definition is identical to the other one.

Parameters
• poOtherFieldDefn: the other field definition to compare to.

Public Static Functions

const char *GetFieldTypeName(OGRFieldType eType)

Fetch human readable name for a field type.

This static method is the same as the C function OGR_GetFieldTypeName().

Return

pointer to an internal static name string. It should not be modified or freed.

Parameters
• eType: the field type to get name for.

const char *GetFieldSubTypeName(OGRFieldSubType eSubType)

Fetch human readable name for a field subtype.

This static method is the same as the C function OGR_GetFieldSubTypeName().

Return

pointer to an internal static name string. It should not be modified or freed.

Since

GDAL 2.0

Parameters
• eSubType: the field subtype to get name for.

static OGRFieldDefnH ToHandle(OGRFieldDefn *poFieldDefn)

Convert a OGRFieldDefn* to a OGRFieldDefnH.

Since

GDAL 2.3

static OGRFieldDefn *FromHandle(OGRFieldDefnH hFieldDefn)

Convert a OGRFieldDefnH to a OGRFieldDefn*.

Since

GDAL 2.3

## OGRGeomFieldDefn class¶

class OGRGeomFieldDefn

Definition of a geometry field of an OGRFeatureDefn.

A geometry field is described by :

Since

OGR 1.11

Public Functions

OGRGeomFieldDefn(const char *pszNameIn, OGRwkbGeometryType eGeomTypeIn)

Constructor.

Since

GDAL 1.11

Parameters
• pszNameIn: the name of the new field.

• eGeomTypeIn: the type of the new field.

OGRGeomFieldDefn(const OGRGeomFieldDefn *poPrototype)

Constructor.

Create by cloning an existing geometry field definition.

Since

GDAL 1.11

Parameters
• poPrototype: the geometry field definition to clone.

void SetName(const char *pszNameIn)

Reset the name of this field.

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

Since

GDAL 1.11

Parameters
• pszNameIn: the new name to apply.

const char *GetNameRef() const

Fetch name of this field.

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

Return

pointer to an internal name string that should not be freed or modified.

Since

GDAL 1.11

OGRwkbGeometryType GetType() const

Fetch geometry type of this field.

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

Return

field geometry type.

Since

GDAL 1.11

void SetType(OGRwkbGeometryType eTypeIn)

Set the geometry type of this field.

This should never be done to an OGRGeomFieldDefn that is already part of an OGRFeatureDefn.

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

Since

GDAL 1.11

Parameters
• eTypeIn: the new field geometry type.

OGRSpatialReference *GetSpatialRef() const

Fetch spatial reference system of this field.

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

Return

field spatial reference system.

Since

GDAL 1.11

void SetSpatialRef(OGRSpatialReference *poSRSIn)

Set the spatial reference of this field.

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

This method drops the reference of the previously set SRS object and acquires a new reference on the passed object (if non-NULL).

Since

GDAL 1.11

Parameters
• poSRSIn: the new SRS to apply.

int IsIgnored() const

Return whether this field should be omitted when fetching features.

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

Return

ignore state

Since

GDAL 1.11

void SetIgnored(int bIgnoreIn)

Set whether this field should be omitted when fetching features.

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

Since

GDAL 1.11

Parameters
• ignore: ignore state

int IsNullable() const

Return whether this geometry field can receive null values.

By default, fields are nullable.

Even if this method returns FALSE (i.e not-nullable field), it doesn’t mean that OGRFeature::IsFieldSet() will necessary return TRUE, as fields can be temporary unset and null/not-null validation is usually done when OGRLayer::CreateFeature()/SetFeature() is called.

Note that not-nullable geometry fields might also contain ‘empty’ geometries.

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

Return

TRUE if the field is authorized to be null.

Since

GDAL 2.0

void SetNullable(int bNullableIn)

Set whether this geometry field can receive null values.

By default, fields are nullable, so this method is generally called with FALSE to set a not-null constraint.

Drivers that support writing not-null constraint will advertize the GDAL_DCAP_NOTNULL_GEOMFIELDS driver metadata item.

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

Since

GDAL 2.0

Parameters
• bNullableIn: FALSE if the field must have a not-null constraint.

int IsSame(const OGRGeomFieldDefn *poOtherFieldDefn) const

Test if the geometry field definition is identical to the other one.

Return

TRUE if the geometry field definition is identical to the other one.

Since

GDAL 1.11

Parameters
• poOtherFieldDefn: the other field definition to compare to.

Public Static Functions

static OGRGeomFieldDefnH ToHandle(OGRGeomFieldDefn *poGeomFieldDefn)

Convert a OGRGeomFieldDefn* to a OGRGeomFieldDefnH.

Since

GDAL 2.3

static OGRGeomFieldDefn *FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)

Convert a OGRGeomFieldDefnH to a OGRGeomFieldDefn*.

Since

GDAL 2.3