# Create Shape, Edit Shape, Edit Attributes, Save Results

**URL:** <https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719>\
**Category:** MapWinGIS\
**Created:** [September 14, 2020, 7:12pm UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719 "2020-09-14T19:12:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sw4web](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/sw4web/32/266_2.png) [@sw4web](https://mapwindow.discourse.group/u/sw4web)\
**Post date:** [September 14, 2020, 7:12pm UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/1 "2020-09-14T19:12:26Z")

</div>

Shapefile Type = SHP\_POINT,  
I have several Points in this Point\_Shapefile.  
The Shape to Add is a Point.

 ![Point_Shapefile](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/2931c93d57b337728c77a86a8ebc79e06dc1b038.png)

TO DO:

1. Create a New Point, Save Shapefile or Update Shapefile to include the New Point

2. Edit the New Point (or any point in the Shapefile), by moving Point Interactively to another position, then Save.

3.Edit any Point’s Attributes using the ‘Edith Attributes’ Method, Save.

1. Delete Point Shapefile.

SOLUTIONS and PROBLEMS:

1. Create New Point Shape was done easily following example by @jerryfaust([Mapwingis 5.0.1 tkCursorMode.cmEditShape](https://mapwindow.discourse.group/t/mapwingis-5-0-1-tkcursormode-cmeditshape/78))  
//SUMMARY  
private void BtnAddNew\_Click(object sender, EventArgs e)  
{  
\_shpfile.InteractiveEditing = true;  
axMap1.CursorMode = tkCursorMode.cmAddShape;  
axMap1.MapCursor = tkCursor.crsrMapDefault;  
}  
Point Added Successfully,  
PROBLEM: New Point Shape NOT Saved when Page is Refreshed.

2. Edit Point Shapefile also worked without problem.  
@jerryfaust( [Mapwingis 5.0.1 tkCursorMode.cmEditShape](https://mapwindow.discourse.group/t/mapwingis-5-0-1-tkcursormode-cmeditshape/78))  
//SUMMARRY  
private void BtnEdit\_Click(object sender, EventArgs e)  
{  
\_shpfile.InteractiveEditing = true;  
axMap1.CursorMode = tkCursorMode.cmEditShape;  
axMap1.MapCursor = tkCursor.crsrMapDefault;  
\_shpfile.Save();  
}  
The Point is moved successfully to another position on the map using the ‘cmEditShape’ tool.  
PROBLEM: Edited Point NOT Saved when Page is Refreshed.

3. Using the ‘Edit Attributes’ Example; ([https://www.mapwindow.org/documentation/mapwingis4.9/\_edit\_attributes\_8cs-example.html](https://www.mapwindow.org/documentation/mapwingis4.9/_edit_attributes_8cs-example.html))  
 ![EditAttributes](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/6844de563202c9f91fa53db3596cb6fe632242a1.png)  
//SUMMARRY:  
int layerHandle = axMap1.get\_LayerHandle(0); // it’s assumed here that the layer we want to edit is the first 1 (with 0 index)  
Shapefile sf = axMap1.get\_Shapefile(layerHandle);  
if (sf != null)  
{  
double projX = 0.0;  
double projY = 0.0;  
axMap1.PixelToProj(e.x, e.y, ref projX, ref projY);

Point Edited Successfully. The Attribute Table is Updated Successfully.  
PROBLEM: Updated Values in the Attribute Table NOT Saved when Page is Refreshed.

1. Delete Point Works without a hitch, following the MapWinGIS Example([https://www.mapwindow.org/documentation/mapwingis4.9/\_remove\_shape\_8cs-example.html](https://www.mapwindow.org/documentation/mapwingis4.9/_remove_shape_8cs-example.html))  
The Point is Deleted immediately, and the Refreshed Page indicates clearly that the Point was Deleted.

But Here is something interesting.  
If the Point Shape is Added successfully using cmAddShape( which does not save) but, when I Select the EditShape Button and Click on the Newly Added Point, or move the point around, the Newly Created Point is SAVED! But the EditShape interactive Editing position of the New Point is NOT Saved. The Point goes back to the point where it was created.  
Why is New Point Saved ONLY after cmEdit tool is used to select the new point?

All right folks, sorry for taking up so much of your reading time. Please I need some one kind with a little extra time on their hand to take a look at this and let me know what is I’m doing not right.  
All I want done is Save.

I’ve tried  
“sf.Save()” and  
sf.SaveAs(@" c:\ point.shp") and  
sf.StopEditingShapes(true, true, null);

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [September 14, 2020, 7:39pm UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/2 "2020-09-14T19:39:44Z")

</div>

Hello @sw4web

At first glance (perhaps not in depth), is your call to `_shpfile.Save()` in the `BtnEdit_Click` method. That was not in the original example, and I don’t think you want to do that.

```
private void BtnEdit_Click(object sender, EventArgs e)
{
    _shpfile.InteractiveEditing = true;
    axMap1.CursorMode = tkCursorMode.cmEditShape;
    axMap1.MapCursor = tkCursor.crsrMapDefault;
    _shpfile.Save(); // <- this was not in the original example
}

```

What you are doing is Saving prior to actually making the edit. This event handler sets up the edit, then saves the shapefile (to disk), after which you are then making your edit. So if at that point, you say you are refreshing the map (do you mean that you reload from disk?) If so, I believe that you are reloading the pre-edited shapefile.

You should perhaps have a separate Save button, in which you call `_shpfile.Save()`. All adds, edits and deletes are taking place in memory, and you can also undo; and you can click the Save button occasionally when you want to save your changes to disk.

Respectfully,  
Jerry.

---

<div class="post-metadata">

**Author:** ![sw4web](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/sw4web/32/266_2.png) [@sw4web](https://mapwindow.discourse.group/u/sw4web)\
**Post date:** [September 15, 2020, 3:50am UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/3 "2020-09-15T03:50:08Z")

</div>

Hi, Jerry thanks. My mistake, adding the Save bit. Will create a separate Save button and let you know how it goes.  
Thank you for your time.

---

<div class="post-metadata">

**Author:** ![sw4web](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/sw4web/32/266_2.png) [@sw4web](https://mapwindow.discourse.group/u/sw4web)\
**Post date:** [September 15, 2020, 5:13am UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/4 "2020-09-15T05:13:03Z")

</div>

Hello, @jerryfaust Everything works like a charm with the separate Save button. However, the Save Edit Attributes does not overwrite the Shapefile being editied, but saves smoothly in a different location. I could live with that. Once more thank you very much.

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [September 15, 2020, 5:56am UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/5 "2020-09-15T05:56:41Z")

</div>

Hello @sw4web

You’re welcome. Glad that it’s (mostly) working. It’s strange that you have to do a SaveAs…

Are you still in Edit mode when you try to save? That is a prerequisite. (see the [Save documentation here](https://www.mapwindow.org/documentation/mapwingis4.9/group __shapefile__ management.html#gae7298f8e85f9d42484c37519fea67611))

Also, you could use the Callback function of the Save method (or better yet, the [global callback](https://www.mapwindow.org/documentation/mapwingis4.9/class_global_settings.html#ac01309d06b2dc9c11019a8c8589da3c8) to receive all errors and warnings). It would be interesting to know if the OCX is telling you why it won’t save.

Regards,  
Jerry.

---

<div class="post-metadata">

**Author:** ![sw4web](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/sw4web/32/266_2.png) [@sw4web](https://mapwindow.discourse.group/u/sw4web)\
**Post date:** [September 16, 2020, 2:03pm UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/6 "2020-09-16T14:03:11Z")

</div>

Hi, @jerryfaust thanks for your enlightenment. I really can’t say if I’m still in Edit mode or not. As I said, I tried “sf. StopEditingShapes(true, true, null)” hoping that should exit Edit mode. Shapefile still not Saved when I close the window and open it again, I notice that changes I made didn’t save.

I would love to use the Global Callback function so I can see what type of errors and where they are coming from, but I don’t know how to apply this function. A simple guide would do.

Thanks once more. You’ve been of great help in this matter. Keep it up.

Regards.

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [September 16, 2020, 4:36pm UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/7 "2020-09-16T16:36:34Z")

</div>

Hello @sw4web

The easiest way to set up the callback is within your main Form, in c#, something like

```
public partial class Form1 : Form, ICallback
{
    public Form1()
    {
        InitializeComponent();
    }

    public void Progress(string KeyOfSender, int Percent, string Message)
    {
        //
    }

    public void Error(string KeyOfSender, string ErrorMsg)
    {
        Console.WriteLine(string.Format("{0}: {1}", KeyOfSender, ErrorMsg));
    }
}

```

Give that a try.  
Jerry.

---

<div class="post-metadata">

**Author:** ![sw4web](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/sw4web/32/266_2.png) [@sw4web](https://mapwindow.discourse.group/u/sw4web)\
**Post date:** [September 16, 2020, 5:15pm UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/8 "2020-09-16T17:15:38Z")

</div>

Will do. Let you know the result.  
Thanks.

---

<div class="post-metadata">

**Author:** ![sw4web](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/sw4web/32/266_2.png) [@sw4web](https://mapwindow.discourse.group/u/sw4web)\
**Post date:** [September 21, 2020, 10:04am UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/9 "2020-09-21T10:04:24Z")

</div>

Hi, @jerryfaust  
Gave it a shot. Same results. Couldn’t figure it out. I’ve settled for “SaveAs”, although “Save” would have been more appropriate, to avoid having so many updated files. No need to border you further on the subject, seeing as we are quite busy.  
Thanks for your support all the same. My project is almost completed. If I run into further issues I’ll let you know. If you would like a private audience of my Windows Desktop Application (Due to security reasons I can’t make it public), I will zip the package to you privately for comment - If you have the time.  
Thanks.  
Regards.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [January 5, 2022, 3:09pm UTC](https://mapwindow.discourse.group/t/create-shape-edit-shape-edit-attributes-save-results/719/10 "2022-01-05T15:09:08Z")

</div>


