Hello,
I am trying to save OgrLayer edits back to a SQL Server database via SaveChanges(), but this doesn't work for me. The error I keep running into is "OgrLayer: Feature ID (FID) column wasn't found." This is despite the table having an 'ogr_fid' column which is recognized and returned by OgrLayer.FIDColumnName.
Here is how my loading code is structured:
Then there is a separate problem I'm having, but I tried to create a new layer to store my edits in, hoping I could use that to learn more about the process and/or work around the editing problem. I accomplished this with the following code:
In case this helps, here are the results of calling OgrLayer.TestCapability:
Rob
I am trying to save OgrLayer edits back to a SQL Server database via SaveChanges(), but this doesn't work for me. The error I keep running into is "OgrLayer: Feature ID (FID) column wasn't found." This is despite the table having an 'ogr_fid' column which is recognized and returned by OgrLayer.FIDColumnName.
Here is how my loading code is structured:
OgrDataSource.Open(_connectionString);
...
// layer is an object I use for keeping track of database layers
OgrLayer ogrlyr = OgrDataSource.GetLayerByName(schema + layer.Name, true); //forUpdate = true
...
Map.AddLayer(ogrlyr, true);
...
Shapefile sf = Map.get_Shapefile(handle); // store this for later use
This is how my editing code roughly flows:// edit mode finished and we are in Map_ShapeValidated
Shape output = Map.ShapeEditor.ValidatedShape; // output != null
bool editing = sf.StartEditingShapes(true, null); // return true
int resultCode = -1;
polygon.EditInsertShape(shp, ref resultCode); // resultCode is set != -1
int savecount = -1;
tkOgrSaveResult orgresult = ogrlyr.SaveChanges(out savecount, tkOgrSaveType.ostGeometryOnly, true);
// orgresult is always osrNoneSaved
At this point if get the error message like this:ogrlyr.get_ErrorMsg(ogrlyr.LastErrorCode)
I get this message: "OgrLayer: Feature ID (FID) column wasn't found."Then there is a separate problem I'm having, but I tried to create a new layer to store my edits in, hoping I could use that to learn more about the process and/or work around the editing problem. I accomplished this with the following code:
OgrDataSource.CreateLayer(
"geo.editTest1",
ShpfileType.SHP_POLYLINE,
MapWrapper.DefaultProjection.GeoProjection,
"OVERWRITE=NO;MW_MULTI_PART=no");
After I do this, the layer is created in my database and there is indeed a geometry in the table. When I rerun my application and I try to load layers then OgrDataSource.LayerCount returns 1 and my other layers are ignored. Why would this be happening?In case this helps, here are the results of calling OgrLayer.TestCapability:
olcRandomRead --> True
olcSequentialWrite --> True
olcRandomWrite --> True
olcFastSpatialFilter --> False
olcFastFeatureCount --> True
olcFastGetExtent --> False
olcCreateField --> True
olcDeleteField --> False
olcReorderFields --> False
olcAlterFieldDefn --> False // this return false, and the OgrLayer error message immediately following is "OgrLayer: Feature ID (FID) column wasn't found."
olcTransactions --> True
olcDeleteFeature --> True
olcFastSetNextByIndex --> False
olcStringsAsUTF8 --> False
olcIgnoreFields --> True
olcCreateGeomField --> False
Thanks in advance for reading this long post,Rob