2
Vote

Reloading Project files fails

description

Have created several shapefiles with Dotspatial and save the project setting into a .dspx file. but can't reload the file into the environment.
with the follow error 'An incompatible feature type was supplied and was not of type Point.', line 361 of XmlDeserializer.cs, when the type is actually MapPolygonLayer?
If I save just preexisting layers, all is fine. Only have problems with layers created by DotSpatial.
All layers have been saved to disk using FeatureSet.SaveAs(Filename).

file attachments

comments

ahrensd wrote Jul 11, 2012 at 3:47 AM

The problem seems to be occuring because I've created these shpefiles as FeatureSets and added them to the MapWindow using Layers.Add(IFeatureSet).
Therefore when the project saved the deserization tries to bring back the FeatureSet not a shapefile.
How can I save the project file with linkages back to the underlining shapefiles.
Proved this to be the case is the easiest of my created datasets to save the shapefile and add the layer via Layers.Add(filename). The other situations are not so easy to accumplish this work around, also seems at bit of waste file handling.

Any ideas how I can get around this....

ambiente wrote Jul 15, 2012 at 1:49 PM

My way to do this:
_myPoints = New FeatureSet(FeatureType.Point)
            _myPoints.DataTable.Columns.Add("ID", GetType(System.Int32))
            _myPoints.DataTable.Columns.Add("Name", GetType(System.String))
            _myPoints.DataTable.Columns.Add("Address", GetType(System.String))
            _myPoints.DataTable.Columns.Add("Symbol", GetType(System.Int32))
            _myPoints.Projection = KnownCoordinateSystems.Geographic.World.WGS1984
Dim dlg = New SaveFileDialog() With {.Filter = SaveShapeFileDialogFilterText, .SupportMultiDottedExtensions = True, .FileName = _myPoints.Name}
                If dlg.ShowDialog(Me) = DialogResult.OK Then
                    _myPoints.SaveAs(dlg.FileName, True)
                End If

                Dim pointLayer As IMapPointLayer = CType(Map1.Layers.Add(dlg.FileName), IMapPointLayer)

ahrensd wrote Jul 16, 2012 at 6:39 AM

Ambiente,

Can you then edit/add features to the shapefile, cause as a soulution to my problem I did much as you suggested. However once I save the project file I get an error if I try to add features.

ambiente wrote Jul 16, 2012 at 8:09 AM

ahrensd

here is the second part where I add the features.
.....
Dim pointLayer As IMapPointLayer = CType(Map1.Layers.Add(dlg.FileName), IMapPointLayer)
                'Dim pointLayer As IMapPointLayer = CType(Map1.Layers.Add(_myPoints), IMapPointLayer)

                pointLayer.Symbology.ClearCategories()
                pointLayer.DataSet.FillAttributes()

                Dim pin_red32 As PointCategory = New PointCategory(My.Resources.pin_red32, 32)
                pin_red32.LegendText = "pin_red32"
                pin_red32.FilterExpression = "[Symbol] = 0"
                pointLayer.Symbology.AddCategory(CType(pin_red32, IPointCategory))

                Dim pin_blue32 As PointCategory = New PointCategory(My.Resources.pin_blue32, 32)
                pin_blue32.LegendText = "pin_blue32"
                pin_blue32.FilterExpression = "[Symbol] = 1"
                pointLayer.Symbology.AddCategory(CType(pin_blue32, IPointCategory))

                Dim pin_yellow32 As PointCategory = New PointCategory(My.Resources.pin_yellow32, 32)
                pin_yellow32.LegendText = "pin_yellow32"
                pin_yellow32.FilterExpression = "[Symbol] = 2"
                pointLayer.Symbology.AddCategory(CType(pin_yellow32, IPointCategory))

                Dim pin_black32 As PointCategory = New PointCategory(My.Resources.pin_black32, 32)
                pin_black32.LegendText = "pin_black32"
                pin_black32.FilterExpression = "[Symbol] = 3"
                pointLayer.Symbology.AddCategory(CType(pin_black32, IPointCategory))

                pointLayer.AssignFastDrawnStates()
                Map1.Refresh()

ahrensd wrote Jul 17, 2012 at 11:59 PM

Have been able to save the project file and reopen the file...
However once I save the project the features appear to have been altered in some way, cause when I go to add a feature to one of the shapefiles I get a error in line 397 of DotSpatial.Symbology.DrawingFilter, KeyNotFoundException "The given key was not present in the dictionary."
Indicating to me that the orginal _drawnStates to the current keys are mismatched, and assume that the features have been altered during the saving process.

ambiente wrote Jul 18, 2012 at 4:13 PM

I had the same problem, you need to add:

MyLayer.DataSet.FillAttributes()

before you add the Categories and

MyLayer.AssignFastDrawnStates()

after it.
For me it works now without any error.