ThinkGeo.com    |     Documentation    |     Premium Support

Sample code for save / cancel edit for shape file

Hi,

I have already looked at the sample projects in the wiki. It seems that they require for new features to be saved first before they can be edited.

Is there a way so that the user can :

  1. add a new feature
  2. then edit the new feature
  3. finally delete an existing feature
    all before saving or cancelling the changes?

Hi Yohan,

I guess you want to know how to operate existing shape file, please see the code as below:

        ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer("Your data path", GeoFileReadWriteMode.ReadWrite);
        layer.Open();

        Feature newFeature = new Feature(10, 10);
        layer.FeatureSource.BeginTransaction();
        layer.FeatureSource.AddFeature(newFeature);
        //layer.FeatureSource.UpdateFeature(oldFeature);
        //layer.FeatureSource.DeleteFeature(oldFeature);
        layer.FeatureSource.CommitTransaction();

Wish that’s helpful.

Regards,

Ethan

Hi Ethan,

Thank you for the help, I was able to modify your sample code for my needs.

Hi Yohan,

I am glad to hear that’s helpful.

Regards,

Ethan