NULL values in the shape file records

Feb 5, 2015 at 10:46 AM
I have a problem with saving attribute data to a shape file (see code below). I'm certain that the right data is in the FeatureSet datatable. However, after saving and reloading the FeatureSet, there are only null values in the datatable. This Is confirmed by opeing the shapefile in MapWinGIS and ArcGIS. Would anybody have a suggestion?
Public Sub TestAttribs(MyPolygons As IFeatureSet)
    Dim ResFeatures As New FeatureSet
    ' copy the datatable structure
    ResFeatures.DataTable = MyPolygons.DataTable.Clone
    ' put trivial stuff in the featureset
    For Each ThisPoly As Feature In MyPolygons.Features
        ResFeatures.Features.Item(ResFeatures.Features.Count - 1).CopyAttributes(ThisPoly)
        ResFeatures.Features.Item(ResFeatures.Features.Count - 1).DataRow.AcceptChanges()
        ResFeatures.Features.Item(ResFeatures.Features.Count - 1).DataRow.EndEdit()

    ' There is content in the rows of the ResFeatures datatable and #datatable rows = #features
    Dim NRows As Integer = ResFeatures.DataTable.Rows.Count
    Dim NFeatures As Integer = ResFeatures.Features.Count
    Dim ContentsBefore As String = ResFeatures.DataTable.Rows(2)(7)

    'save to shape file
    ResFeatures.DataTable.AcceptChanges()       ' to be sure
    ResFeatures.SaveAs("c:\NewPolys.shp", True)
    Dim fs As FeatureSet = FeatureSet.Open("c:\NewPolys.shp")
    ' rows contain NULL values
    Dim ContentsAfter As String = fs.DataTable.Rows(2)(7)

End Sub
Feb 5, 2015 at 7:08 PM
Hey pan,

please use ResFeatures.CopyTableSchema(MyPolygons) instead of ResFeatures.DataTable = MyPolygons.DataTable.Clone.

Clone creates DataColumns that have no length. That is the reason why DotSpatial doesn't save the data to the dbf.
CopyTableSchema should create correct DataColumns.