mumair
October 29, 2019, 4:18am
1
Hi,
I am looking at an option to save OGR layer loaded from SQL Server to a local Shapefile.
Is there a way to achieve this? I tried following code but of no use
Shapefile shp = new Shapefile();
shp = axMap1.get_Shapefile(sqlOGRHandle);
shp.SaveAs(@“C: \Users\Umair\Desktop\a.shp”, null);
pmeems
October 29, 2019, 8:12am
2
Please have a look at the example at AddLayerFromDatabase()
mumair
October 29, 2019, 10:11am
3
This wasn’t of much help but I have finally managed to fix it using following approach. Adding code for anyone who needs it
private void toolStripStartEdit_Click(object sender, EventArgs e)
{
layer.OpenFromDatabase(CONNECTION_STRING, layerName, true);
if (!layer.OpenFromDatabase(CONNECTION_STRING, layerName, true))
{
MessageBox.Show("Failed to open layer: " + layer.get_ErrorMsg(layer.LastErrorCode));
return;
}
MessageBox.Show("Driver supports editing: " + layer.TestCapability(tkOgrLayerCapability.olcRandomWrite));
if (!layer.get_SupportsEditing(tkOgrSaveType.ostSaveAll))
{
MessageBox.Show("Can't edit a layer: " + layer.get_ErrorMsg(layer.LastErrorCode));
layer.Close();
return;
}
//else
//{
axMap1.AddLayer(layer, true);
_shpfile = layer.GetBuffer();
_shpfile.InteractiveEditing = true;
axMap1.CursorMode = tkCursorMode.cmEditShape;
MessageBox.Show("Shapefile Loaded & Editing enabled");
//}
}
private void ToolStripStopAndSaveEditings_Click(object sender, EventArgs e)
{
int count;
var saveResults = layer.SaveChanges(out count);
layer.Close();
axMap1.CursorMode = tkCursorMode.cmPan;
MessageBox.Show("Changes Saved Successfully");
axMap1.Refresh();
}