This project is read-only.

Saving ProjectFile with SerializationManager

Dec 11, 2014 at 12:22 PM
Hello Everyone,

I am trying to save my shapefile layers (one data frame) as a project file.
I have close to 10 layers, three of them are point layer and the rest are lines. I have built the shapefiles with coding and used the following line to save the project file:
frmmap.AppMan.SerializationManager.SaveProject(@"D:\test.dspx");
So far this works fine and I get the dspc xml file.
But problem is that when I try to open it with the
frmmap.AppMan.SerializationManager.OpenProject(@"D:\test.dspx");
It only loads my point shapefiles name in the legend. and there is no sign of the line layers.
Also the point shapefiles seem to be empty. There is no data stored in them. attribute table is empty as well and the map does not show anything.

The dspx file seems to include the name and the specifications of all of the layers.

I tried to open the dspx file with DemoMap.exe but the same thing happens.

Any thought would be appreciated.

Regards
Dec 11, 2014 at 12:35 PM
Currently the shapefiles aren't saved when you save the project.

You have to save the layers first by calling FeatureLayer.Dataset.Save or FeatureLayer.Dataset.SaveAs if the layer was never saved before. FeatureLayer would be the layer you want to save converted to FeatureLayer.

Afterwards calling OpenProject should load your layers. Be aware that they'll most probably be in IndexMode and the AttributeTable won't be filled.
Dec 11, 2014 at 12:50 PM
Thanks Jany for your prompt response.

I have already saved the shapefile layers before saving the project file.
I can open the saved shapefiles in DemoMap or my own program one by one without any issue and attribute table has no problem. The only issue in this way is that I lose all of the formatting stuff which I am hoping to keep by saving the ProjectFile.

I would have attached the files but I could not figure out how to do it on codeplex.
Dec 11, 2014 at 2:29 PM
It's what I thought. The filenames of the datasets that belong to your layers are missing in the dspx. That's what would happen if you hadn't saved your layers. But I found another cause for this too. Something that I fixed in my own code but not in DotSpatial.

Please download changeset 75317 and check if your problem is solved.
Dec 11, 2014 at 3:12 PM
Thanks for your response.

I applied the changeset and recompiled the the dlls but no luck.
The same problem is still there.


This being said, I can see that shape file paths have been added into the dspx file.


I am not sure what do you mean by saving the layers.

I have used the following line to save my FeatureSet before adding it to the map control.

fs.SaveAs(dm.InpFilePath + "GISShapeFiles\" + Type + ".shp", true);

and this happens before calling ProjectSave.

Let me know if this make sense.
Dec 11, 2014 at 6:31 PM
So far it seems as if you're doing everything right. So I don't understand why your layers aren't shown after you load the dspx.

Please take demomap and add the layers with the help of the add button and save the project in file menu. Do they show up if you reopen demomap and load the saved dspx?
Dec 11, 2014 at 6:42 PM
Yes, they do show up in the DemoMap when I use DemoMap to save the project file.
This is why I am confused too.
Dec 11, 2014 at 7:35 PM
Alright so there seems to be something wrong with the way you use the code. Can you give me the code that makes trouble? If not try to write a small example that causes this error.
Dec 11, 2014 at 7:54 PM
Just emailed it to you.
Thanks
Dec 12, 2014 at 3:28 PM
Edited Dec 12, 2014 at 3:29 PM
Here is the solution to the issue that is suggest by Jany. So thank you Jany.


Somewhere in my code where I was building the shapefiles i had the following line
IMapFeatureLayer layer = appManager1.Map.Layers.Add(fs); 
fs is the FeatureSet object that I used to add the point or lines and it was also saved to the drive.

Apparently we loose the feature type in the line layer when we are doing it in this way.

So Jany suggested to replace the code with
IMapFeatureLayer layer = appManager1.Map.Layers.Add(shapefilePath) as IMapFeatureLayer;
which adds the saved shapefile by loading it from the drive.

This indeed solved the problem, although it comes with a price of loading files from drive instead of memory.
Marked as answer by Ehsan_Ro on 12/12/2014 at 7:28 AM