[Gdal-dev] Updating Records Using OGR
John Nipper
jnipper at bhinc.com
Tue Jun 22 16:00:49 EDT 2004
Hello,
Just started using Ogr, and I am able to compile, run, and access data
without issue. However, I am unable to change records. It looks as though
it is built in, but I must be missing a step. So here is what I do in
simplified C++ ... much of which is copied from ogrinfo.cpp. Note, that I
have omitted all error checking code from the following code:
OGRRegisterAll();
OGRDataSource *poDS;
OGRSFDriver *poDriver;
poDS = OGRSFDriverRegistrar::Open( pszDataSource, TRUE, &poDriver ); //
Where pszDataSource is set to the datasource
poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter, NULL );
// and pszSQLStatement is set as well
OGRFeature *poFeature;
OGRErr retError;
retError = poLayer->StartTransaction();
while( (poFeature = poResultSet->GetNextFeature()) != NULL )
{
// Do some thing to the geometry and/or features
//For example
nameFld = poFeature->GetFieldIndex("NAME");
poFeature->SetField(nameFld, featName2); // Where featName2 is a new
string to place in the field value.
poFeature->SetFeature(poFeature);
}
retError = poLayer->CommitTransaction();
I tried the above scenario with shapefiles as well as Oracle Spatial. I can
loop through the data within the debugger, and everything looks all good.
But any information that I change, never gets posted in the original data.
I must be doing something wrong, or leaving out something. If I am reading
the driver code correctly, the data should be replaced.
Thanks,
John Nipper
jnipper at bhinc.com
More information about the Gdal-dev
mailing list