- Main Page
- Classes
- Files
- Directories
- Related Pages

- Class List
- Class Hierarchy
- Class Members

# OGRLayer Class Reference

`#include <ogrsf_frmts.h>`

List of all members.

## Public Member Functions
virtual OGRGeometry * | GetSpatialFilter ()
virtual void | SetSpatialFilter (OGRGeometry *)
virtual void | SetSpatialFilterRect (double dfMinX, double dfMinY, double dfMaxX, double dfMaxY)
virtual OGRErr | SetAttributeFilter (const char *)
virtual void | ResetReading ()=0
virtual OGRFeature * | GetNextFeature ()=0
virtual OGRErr | SetNextByIndex (long nIndex)
virtual OGRFeature * | GetFeature (long nFID)
virtual OGRErr | SetFeature (OGRFeature *poFeature)
virtual OGRErr | CreateFeature (OGRFeature *poFeature)
virtual OGRErr | DeleteFeature (long nFID)
virtual OGRFeatureDefn * | GetLayerDefn ()=0
virtual OGRSpatialReference * | GetSpatialRef ()
virtual int | GetFeatureCount (int bForce=TRUE)
virtual OGRErr | GetExtent (OGREnvelope *psExtent, int bForce=TRUE)
virtual int | TestCapability (const char *)=0
virtual const char * | GetInfo (const char *)
virtual OGRErr | CreateField (OGRFieldDefn *poField, int bApproxOK=TRUE)
virtual OGRErr | SyncToDisk ()
virtual const char * | GetFIDColumn ()
virtual const char * | GetGeometryColumn ()
int | Reference ()
int | Dereference ()
int | GetRefCount () const

## Detailed Description

This class represents a layer of simple features, with access methods.

## Member Function Documentation

OGRErr OGRLayer::CreateFeature | ( | OGRFeature * | poFeature | ) | `[virtual]`

  | Create and write a new feature within a layer. The passed feature is written to the layer as a new feature, rather than overwriting an existing one. If the feature has a feature id other than OGRNullFID, then the native implementation may use that as the feature id of the new feature, but not necessarily. Upon successful return the passed feature will have been updated with the new feature id. This method is the same as the C function OGR_L_CreateFeature(). Parameters:
  | poFeature | the feature to write to disk.
Returns: OGRERR_NONE on success.

OGRErr OGRLayer::CreateField | ( | OGRFieldDefn * | poField,
|  | int | bApproxOK = `TRUE`
| ) | `[virtual]`

  | Create a new field on a layer. You must use this to create new fields on a real layer. Internally the OGRFeatureDefn for the layer will be updated to reflect the new field. Applications should never modify the OGRFeatureDefn used by a layer directly. This function is the same as the C function OGR_L_CreateField(). Parameters:
  | poField | field definition to write to disk.
  | bApproxOK | If TRUE, the field may be created in a slightly different form depending on the limitations of the format driver.
Returns: OGRERR_NONE on success.

OGRErr OGRLayer::DeleteFeature | ( | long | nFID | ) | `[virtual]`

  | Delete feature from layer. The feature with the indicated feature id is deleted from the layer if supported by the driver. Most drivers do not support feature deletion, and will return OGRERR_UNSUPPORTED_OPERATION. The TestCapability() layer method may be called with OLCDeleteFeature to check if the driver supports feature deletion. This method is the same as the C function OGR_L_DeleteFeature(). Parameters:
  | poFeature | the feature to write to disk.
Returns: OGRERR_NONE on success.

int OGRLayer::Dereference | ( |  | ) |

| Decrement layer reference count. This method is the same as the C function OGR_L_Dereference(). Returns: the reference count after decrementing.

OGRErr OGRLayer::GetExtent | ( | OGREnvelope * | psExtent,
|  | int | bForce = `TRUE`
| ) | `[virtual]`

  | Fetch the extent of this layer. Returns the extent (MBR) of the data in the layer. If bForce is FALSE, and it would be expensive to establish the extent then OGRERR_FAILURE will be returned indicating that the extent isn't know. If bForce is TRUE then some implementations will actually scan the entire layer once to compute the MBR of all the features in the layer. The returned extent does not take the spatial filter into account. If a spatial filter was previously set then it should be ignored but some implementations may be unable to do that, so it is safer to call GetExtent() without setting a spatial filter. Layers without any geometry may return OGRERR_FAILURE just indicating that no meaningful extents could be collected. This method is the same as the C function OGR_L_GetExtent(). Parameters:
  | psExtent | the structure in which the extent value will be returned.
  | bForce | Flag indicating whether the extent should be computed even if it is expensive.
Returns: OGRERR_NONE on success, OGRERR_FAILURE if extent not known.

OGRFeature * OGRLayer::GetFeature | ( | long | nFID | ) | `[virtual]`

  | Fetch a feature by it's identifier. This function will attempt to read the identified feature. The nFID value cannot be OGRNullFID. Success or failure of this operation is unaffected by the spatial or attribute filters. If this method returns a non-NULL feature, it is guaranteed that it's feature id (OGRFeature::GetFID()) will be the same as nFID. Use OGRLayer::TestCapability(OLCRandomRead) to establish if this layer supports efficient random access reading via GetFeature(); however, the call should always work if the feature exists as a fallback implementation just scans all the features in the layer looking for the desired feature. Sequential reads are generally considered interrupted by a GetFeature() call. This method is the same as the C function OGR_L_GetFeature(). Parameters:
  | nFID | the feature id of the feature to read.
Returns: a feature now owned by the caller, or NULL on failure.

int OGRLayer::GetFeatureCount | ( | int | bForce = `TRUE` | ) | `[virtual]`

  | Fetch the feature count in this layer. Returns the number of features in the layer. For dynamic databases the count may not be exact. If bForce is FALSE, and it would be expensive to establish the feature count a value of -1 may be returned indicating that the count isn't know. If bForce is TRUE some implementations will actually scan the entire layer once to count objects. The returned count takes the spatial filter into account. This method is the same as the C function OGR_L_GetFeatureCount(). Parameters:
  | bForce | Flag indicating whether the count should be computed even if it is expensive.
Returns: feature count, -1 if count not known.

const char * OGRLayer::GetFIDColumn | ( |  | ) | `[virtual]`

| This method returns the name of the underlying database column being used as the FID column, or "" if not supported. This method is the same as the C function OGR_L_GetFIDColumn(). Returns: fid column name.

const char * OGRLayer::GetGeometryColumn | ( |  | ) | `[virtual]`

| This method returns the name of the underlying database column being used as the geometry column, or "" if not supported. This method is the same as the C function OGR_L_GetFIDColumn(). Returns: fid column name.

const char * OGRLayer::GetInfo | ( | const char * | pszTag | ) | `[virtual]`

  | Fetch metadata from layer. This method can be used to fetch various kinds of metadata or layer specific information encoded as a string. It is anticipated that various tag values will be defined with well known semantics, while other tags will be used for driver/application specific purposes. This method is deprecated and will be replaced with a more general metadata model in the future. At this time no drivers return information via the GetInfo() call. Parameters:
  | pszTag | the tag for which information is being requested.
Returns: the value of the requested tag, or NULL if that tag does not have a value, or is unknown.

OGRFeatureDefn * OGRLayer::GetLayerDefn | ( |  | ) | `[pure virtual]`

| Fetch the schema information for this layer. The returned OGRFeatureDefn is owned by the OGRLayer, and should not be modified or freed by the application. It encapsulates the attribute schema of the features of the layer. This method is the same as the C function OGR_L_GetLayerDefn(). Returns: feature definition.

OGRFeature * OGRLayer::GetNextFeature | ( |  | ) | `[pure virtual]`

| Fetch the next available feature from this layer. The returned feature becomes the responsiblity of the caller to delete. Only features matching the current spatial filter (set with SetSpatialFilter()) will be returned. This method implements sequential access to the features of a layer. The ResetReading() method can be used to start at the beginning again. This method is the same as the C function OGR_L_GetNextFeature(). Returns: a feature, or NULL if no more features are available.

int OGRLayer::GetRefCount | ( |  | ) | const

| Fetch reference count. This method is the same as the C function OGR_L_GetRefCount(). Returns: the current reference count for the layer object itself.

OGRGeometry * OGRLayer::GetSpatialFilter | ( |  | ) | `[virtual]`

| This method returns the current spatial filter for this layer. The returned pointer is to an internally owned object, and should not be altered or deleted by the caller. This method is the same as the C function OGR_L_GetSpatialFilter(). Returns: spatial filter geometry.

OGRSpatialReference * OGRLayer::GetSpatialRef | ( |  | ) | `[inline, virtual]`

| Fetch the spatial reference system for this layer. The returned object is owned by the OGRLayer and should not be modified or freed by the application. This method is the same as the C function OGR_L_GetSpatialRef(). Returns: spatial reference, or NULL if there isn't one.

int OGRLayer::Reference | ( |  | ) |

| Increment layer reference count. This method is the same as the C function OGR_L_Reference(). Returns: the reference count after incrementing.

void OGRLayer::ResetReading | ( |  | ) | `[pure virtual]`

| Reset feature reading to start on the first feature. This affects GetNextFeature(). This method is the same as the C function OGR_L_ResetReading().

OGRErr OGRLayer::SetAttributeFilter | ( | const char * | pszQuery | ) | `[virtual]`

  | Set a new attribute query. This method sets the attribute query string to be used when fetching features via the GetNextFeature() method. Only features for which the query evaluates as true will be returned. The query string should be in the format of an SQL WHERE clause. For instance "population > 1000000 and population < 5000000" where population is an attribute in the layer. The query format is a restricted form of SQL WHERE clause as defined "eq_format=restricted_where" about half way through this document: http://ogdi.sourceforge.net/prop/6.2.CapabilitiesMetadata.html Note that installing a query string will generally result in resetting the current reading position (ala ResetReading()). This method is the same as the C function OGR_L_SetAttributeFilter(). Parameters:
  | pszQuery | query in restricted SQL WHERE format, or NULL to clear the current query.
Returns: OGRERR_NONE if successfully installed, or an error code if the query expression is in error, or some other failure occurs.

OGRErr OGRLayer::SetFeature | ( | OGRFeature * | poFeature | ) | `[virtual]`

  | Rewrite an existing feature. This method will write a feature to the layer, based on the feature id within the OGRFeature. Use OGRLayer::TestCapability(OLCRandomWrite) to establish if this layer supports random access writing via SetFeature(). This method is the same as the C function OGR_L_SetFeature(). Parameters:
  | poFeature | the feature to write.
Returns: OGRERR_NONE if the operation works, otherwise an appropriate error code.

OGRErr OGRLayer::SetNextByIndex | ( | long | nIndex | ) | `[virtual]`

  | Move read cursor to the nIndex'th feature in the current resultset. This method allows positioning of a layer such that the GetNextFeature() call will read the requested feature, where nIndex is an absolute index into the current result set. So, setting it to 3 would mean the next feature read with GetNextFeature() would have been the 4th feature to have been read if sequential reading took place from the beginning of the layer, including accounting for spatial and attribute filters. Only in rare circumstances is SetNextByIndex() efficiently implemented. In all other cases the default implementation which calls ResetReading() and then calls GetNextFeature() nIndex times is used. To determine if fast seeking is available on the current layer use the TestCapability() method with a value of OLCFastSetNextByIndex. This method is the same as the C function OGR_L_SetNextByIndex(). Parameters:
  | nIndex | the index indicating how many steps into the result set to seek.
Returns: OGRERR_NONE on success or an error code.

void OGRLayer::SetSpatialFilter | ( | OGRGeometry * | poFilter | ) | `[virtual]`

  | Set a new spatial filter. This method set the geometry to be used as a spatial filter when fetching features via the GetNextFeature() method. Only features that geometrically intersect the filter geometry will be returned. Currently this test is may be inaccurately implemented, but it is guaranteed that all features who's envelope (as returned by OGRGeometry::getEnvelope()) overlaps the envelope of the spatial filter will be returned. This can result in more shapes being returned that should strictly be the case. This method makes an internal copy of the passed geometry. The passed geometry remains the responsibility of the caller, and may be safely destroyed. For the time being the passed filter geometry should be in the same SRS as the layer (as returned by OGRLayer::GetSpatialRef()). In the future this may be generalized. This method is the same as the C function OGR_L_SetSpatialFilter(). Parameters:
  | poFilter | the geometry to use as a filtering region. NULL may be passed indicating that the current spatial filter should be cleared, but no new one instituted.

void OGRLayer::SetSpatialFilterRect | ( | double | dfMinX,
|  | double | dfMinY,
|  | double | dfMaxX,
|  | double | dfMaxY
| ) | `[virtual]`

  | Set a new rectangular spatial filter. This method set rectangle to be used as a spatial filter when fetching features via the GetNextFeature() method. Only features that geometrically intersect the given rectangle will be returned. The x/y values should be in the same coordinate system as the layer as a whole (as returned by OGRLayer::GetSpatialRef()). Internally this method is normally implemented as creating a 5 vertex closed rectangular polygon and passing it to OGRLayer::SetSpatialFilter(). It exists as a convenience. The only way to clear a spatial filter set with this method is to call OGRLayer::SetSpatialFilter(NULL). This method is the same as the C function OGR_L_SetSpatialFilterRect(). Parameters:
  | dfMinX | the minimum X coordinate for the rectangular region.
  | dfMinY | the minimum Y coordinate for the rectangular region.
  | dfMaxX | the maximum X coordinate for the rectangular region.
  | dfMaxY | the maximum Y coordinate for the rectangular region.

OGRErr OGRLayer::SyncToDisk | ( |  | ) | `[virtual]`

| Flush pending changes to disk. This call is intended to force the layer to flush any pending writes to disk, and leave the disk file in a consistent state. It would not normally have any effect on read-only datasources. Some layers do not implement this method, and will still return OGRERR_NONE. The default implementation just returns OGRERR_NONE. An error is only returned if an error occurs while attempting to flush to disk. This method is the same as the C function OGR_L_SyncToDisk(). Returns: OGRERR_NONE if no error occurs (even if nothing is done) or an error code.

int OGRLayer::TestCapability | ( | const char * | pszCap | ) | `[pure virtual]`

  | Test if this layer supported the named capability. The capability codes that can be tested are represented as strings, but defined constants exists to ensure correct spelling. Specific layer types may implement class specific capabilities, but this can't generally be discovered by the caller. OLCRandomRead / "RandomRead": TRUE if the GetFeature() method works for this layer. OLCSequentialWrite / "SequentialWrite": TRUE if the CreateFeature() method works for this layer. Note this means that this particular layer is writable. The same OGRLayer class may returned FALSE for other layer instances that are effectively read-only. OLCRandomWrite / "RandomWrite": TRUE if the SetFeature() method is operational on this layer. Note this means that this particular layer is writable. The same OGRLayer class may returned FALSE for other layer instances that are effectively read-only. OLCFastSpatialFilter / "FastSpatialFilter": TRUE if this layer implements spatial filtering efficiently. Layers that effectively read all features, and test them with the OGRFeature intersection methods should return FALSE. This can be used as a clue by the application whether it should build and maintain it's own spatial index for features in this layer. OLCFastFeatureCount / "FastFeatureCount": TRUE if this layer can return a feature count (via OGRLayer::GetFeatureCount()) efficiently ... ie. without counting the features. In some cases this will return TRUE until a spatial filter is installed after which it will return FALSE. OLCFastGetExtent / "FastGetExtent": TRUE if this layer can return its data extent (via OGRLayer::GetExtent()) efficiently ... ie. without scanning all the features. In some cases this will return TRUE until a spatial filter is installed after which it will return FALSE. OLCFastSetNextByIndex / "FastSetNextByIndex": TRUE if this layer can perform the SetNextByIndex() call efficiently, otherwise FALSE. This method is the same as the C function OGR_L_TestCapability(). Parameters:
  | pszCap | the name of the capability to test.
Returns: TRUE if the layer has the requested capability, or FALSE otherwise. OGRLayers will return FALSE for any unrecognised capabilities.

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

- ogrsf_frmts.h
- ogrsf_frmts.dox
- ogrlayer.cpp

Generated for GDAL by 1.4.5.