OGR layer editing

Functions

bool OgrLayer.get_SupportsEditing (tkOgrSaveType editingType)
 Gets a value indicating whether the layer supports editing. More...
 
string OgrLayer.get_UpdateSourceErrorMsg (int errorIndex)
 Gets a specified error message from the log registered during OgrLayer.SaveChanges call. More...
 
int OgrLayer.get_UpdateSourceErrorShapeIndex (int errorIndex)
 Gets shape index associated with specified error message from the log registered during OgrLayer.SaveChanges call. More...
 
tkOgrSaveResult OgrLayer.SaveChanges (out int savedCount, tkOgrSaveType saveType=tkOgrSaveType.ostSaveAll, bool validateShapes=true)
 Saves local changes to the datasource. More...
 

Properties

bool OgrLayer.DataIsReprojected [get]
 Gets a value indicating whether underlying data ( OgrLayer.GetBuffer ) was reprojected. More...
 
string OgrLayer.FIDColumnName [get]
 Gets name of feature ID column. More...
 
int OgrLayer.UpdateSourceErrorCount [get]
 Gets the number of errors registered in the log during OgrLayer.SaveChanges call. More...
 

Detailed Description

Here is a list of methods and properties to save changes made to OgrLayer back to datasource. The properties and methods described here belong to OgrLayer class.

dot_inline_dotgraph_26.png

Graph description
Editing of underlying in-memory shapefile can be done for all types of OGR layers.
However saving of these changes back to datasource isn't always possible because of following reasons:

Function Documentation

◆ get_SupportsEditing()

bool OgrLayer.get_SupportsEditing ( tkOgrSaveType  editingType)

Gets a value indicating whether the layer supports editing.

The property works like this:
1) checks whether underlying driver supports random write operation: OgrLayer.TestCapability(tkOgrLayerCapability::olcRandomWrite);
2) the presence of Feature Id column is verified;
3) checks if the data is still in the same projection (OgrLayer.DataIsReprojected).
OgrLayer.SaveChanges method doesn't make the first check, thus trying to write the data even if functionality isn't advertised by driver.

Parameters
editingTypeThe requested type of editing.
Returns
True in case editing is supported.

◆ get_UpdateSourceErrorMsg()

string OgrLayer.get_UpdateSourceErrorMsg ( int  errorIndex)

Gets a specified error message from the log registered during OgrLayer.SaveChanges call.

Parameters
errorIndexIndex of error.
Returns
Error message or empty string on invalid index.

◆ get_UpdateSourceErrorShapeIndex()

int OgrLayer.get_UpdateSourceErrorShapeIndex ( int  errorIndex)

Gets shape index associated with specified error message from the log registered during OgrLayer.SaveChanges call.

Parameters
errorIndexError index.
Returns
Index of shape in underlying in-memory shapefile (OgrLayer.GetBuffer()).

◆ SaveChanges()

tkOgrSaveResult OgrLayer.SaveChanges ( out int  savedCount,
tkOgrSaveType  saveType = tkOgrSaveType.ostSaveAll,
bool  validateShapes = true 
)

Saves local changes to the datasource.

To check whether the operation is supported for current layer use OgrLayer.get_SupportsEditing.
The method works like this:
1) Underlying shapefile is analyzed for changes, i.e. for shapes with Shapefile.get_ShapeModified property set to true.
2) For each of such shapes UPDATE statement is generated by driver. Shapes are identified in source by the value of Feature ID column.
3) If update operation for particular shape fails the error is registered in: OgrLayer.get_UpdateSourceErrorMsg().
The operation may fail for a particular shape because of 2 main reasons:

  • shape is invalid, while validateShapes parameter set to true;
  • new values aren't accepted by datasource, which often can maintain stricter data constraints.
Parameters
savedCountReturns number of saved changed.
saveTypeSets which part of data should be saved, geometry, attributes or both. Default value is tkOgrSaveType.ostSaveAll (i.e. both geometry and attributes).
validateShapesSets whether shapes will be validated before saving. Default value is true, i.e. invalid shapes won't be saved.
Returns
Result of the operation.

Properties

◆ DataIsReprojected

bool OgrLayer.DataIsReprojected
get

Gets a value indicating whether underlying data ( OgrLayer.GetBuffer ) was reprojected.

This may happen because of projection mismatch on adding it to the map. See GlobalSettings.ReprojectLayersOnAdding for details.

◆ FIDColumnName

string OgrLayer.FIDColumnName
get

Gets name of feature ID column.

Feature ID column corresponds to primary key in underlying database table. It is used to uniquely identify features and to save changes back to datasource. Feature ID column (if present) will always be inserted as a first field of attribute table of underlying shapefile. This field must not be edited.
For inserted features the column values are set to NULL.
In case underlying datasource doesn't have feature ID column, an empty string will be returned.

◆ UpdateSourceErrorCount

int OgrLayer.UpdateSourceErrorCount
get

Gets the number of errors registered in the log during OgrLayer.SaveChanges call.