no attribute table changes saved to shapefile

Dec 14, 2012 at 4:15 PM

Dear all,

 

I found a problem when after loading a shapefile, with some coding I change the value of some attributes for all features and then I try to save them.

The code is:

       For i = 0 To fsp.Features.Count - 1
             fsp.Features(i).DataRow.BeginEdit()
             fsp.Features(i).DataRow.Item("MACRO") = somevalue 
            fsp.Features(i).DataRow.AcceptChanges()
            fsp.Features(i).DataRow.EndEdit()

           
        Next

fsp.saveas(filename,true)

the saved shapefile has no modification on the attribute table, while if I debug the code till before saving it seems that the attributes of each feature is correctly modified!

Anyone knows what I am doing wrong?

I spent the whole afternoon trying to fix this but I could not make it! 

Please help me!

Thank you

Oscar

Dec 15, 2012 at 6:45 AM

You need to save your modified dataset of the layer before save the shapefile.

DataSet.Save()

Dec 15, 2012 at 7:28 AM

Hi Ambiente,

 

I tried to do this but it does not solve the problem

However I think I got the solution. It seems that simply adding the shapefile to the map would not load the attribute table in ram.... or something similar.

What I have done is simply call the fillattributes before starting to change attribute values, and now it saves everything correctly.

There are too many things I am still not aware of how dotspatial library works... so I often make silly errors.

 

Thank you

Oscar 

Dec 17, 2012 at 9:17 PM

Try this before saving..

Dim fsp As FeatureLayer 'Load layer
fsp.DataSet.Features.SuspendEvents()

For i = 0 To fsp.Features.Count - 1
  fsp.Features(i).DataRow.BeginEdit()
  fsp.Features(i).DataRow.Item("MACRO") = somevalue 
  'fsp.Features(i).DataRow.AcceptChanges() 'Eliminate this line
  fsp.Features(i).DataRow.EndEdit()
Next

fsp.DataSet.InitializeVertices()
fsp.AssignFastDrawnStates()
fsp.DataSet.UpdateExtent()
fsp.DataSet.Save()
fsp.DataSet.InvalidateVertices()

fLayerDrawing.DataSet.Features.ResumeEvents()

fsp.saveas(filename,true)

I hope you serve something...

Dec 18, 2012 at 7:56 AM

Thank you Camiza,

so far I solved just filling attributes as soon as I open the shapefile.

However, can you explain me what the instructions after the for cycle serve for? the point is that besides the tag help there is not much of information on what these instructions serve for and how they work. If you can shed some light on it I would be very grateful

Thank you 

Oscar

Dec 18, 2012 at 5:20 PM

oscarafone77 do you speak spanish? 

my English is very bad and I explain in English confuse you more....

but what these instructions is prevent tripping events that make your program slow and that force any modification not saved properly especially fsp.DataSet.Features.SuspendEvents () allows you to modify your shapefiles faster and ensure that If you save your changes when you return to instantiate fLayerDrawing.DataSet.Features.ResumeEvents ().

in other words it does is allow safe and rapid changes and to shoot fLayerDrawing.DataSet.Features.ResumeEvents () makes the file is newly created and recompiled changes overcoming errors at runtime.

 

I hope you serve something...

 


Dec 19, 2012 at 6:51 AM

Hi Camiza,

I am italian, and I don't speak spanish, sorry! However there is no problem for me with your english.

What you explained me sounds very useful, I will use these new knowledge in my project, where in many occasions I just got solutions intuitively, now I will be more conscious in what I am doing.

 

thank you again for the explanation, very useful! 

 

Oscar