ThinkGeo.com    |     Documentation    |     Premium Support

Editing Shapefiles

I am still new to C#, and would like an example of editing a shapefile that actually traps the possible error messages for the BeginTransaction, Add (or Delete or Update), and CommitTransaction.  Below is the code without trapping (rural is a ShapefileFeatureLayer):


          rural.Open();

          rural.FeatureSource.BeginTransaction();

          rural.FeatureSource.AddFeature(newpoint, pointColumns);

          rural.FeatureSource.CommitTransaction();

          rural.Close();


Also is there a listing of the error messages for the InvalidOperationException, and for any other Exception that is specific to MapSuite?




thanks.


Elisa

 



Elisa,


Thanks for your post.
 
Following code snippet shows you how to do a simple editting(here is add).

 

string targetShapeFilePath =@"C:\tmp\post7544testdata.shp";
ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polygon, targetShapeFilePath, dbfColumns, System.Text.Encoding.UTF8, OverwriteMode.Overwrite);
ShapeFileFeatureLayer shapes = new ShapeFileFeatureLayer(targetShapeFilePath, ShapeFileReadWriteMode.ReadWrite);
shapes.Open();
shapes.EditTools.BeginTransaction();
foreach (Feature feature in allFeatures)
{
    shapes.EditTools.Add(feature);
}
TransactionResult result = shapes.EditTools.CommitTransaction(); 
shapes.Close();
if (result.TotalFailureCount > 0)
{
    MessageBox.Show(string.Format("{0} failed", result.TotalFailureCount));
}


Any more questions just feel free to let me know.
 
Thanks.
 
Yale