How to save the attribute table

1011
4
10-13-2010 11:00 PM
AsimShrestha1
New Contributor
When I run my program written in C# using ArcGIS Engine 9.3, it creates several new columns in the attribute table of the segment layer, so on each run (when a different point layer is selected) the columns are filled with new values.
I need to the save each instance of the attribute table after each run so that I can use the generated statistics later on.
Any help is really appreciated
Thanks
0 Kudos
4 Replies
yimingji
New Contributor
I might have not understood your question correctly.

Why not just loop through all the features, and save the attributes you want to a collection type.
0 Kudos
AsimShrestha1
New Contributor
Thanks jojolover for your reply,
I'm dealing with road segments(segment layer) and crash data(point layer) for different year. So when I run the program with crash data for say 2008 it would generate an attribute table for the road segment for 2008, similarly when crash data for 2009 is selected the attribute table for road segment is modified. I need to capture these different attribute tables and save them under different names.

I'm very new to ArcGIS and don't know much. Can you please explain to me how save the whole attribute to a collection type?

Thanks once again
0 Kudos
JamesCrandall
MVP Frequent Contributor
I handle these kinds of operations with ADO.NET functionality, generating different in memory DataTables for accessing and using varying data in other calculations.  This would offer you the ability to not only create seperate data containers, but you could also generate/maintain related data in parent/child relationships too. 

If you are not versed in ADO.NET, then here is a good start right from the source:

http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx

I have also put up a great example that has what you need to convert any IFeatureLayer into an ADO.NET DataTable object -- maybe you could utilize some of this:

http://resources.esri.com/arcgisdesktop/dotnet/index.cfm?fa=codeGalleryDetails&scriptID=16946

Here is a relevent function from the example I've put up on the CodeGallery:

Public Function ConvertToADONETDataTableFromLayer(ByVal inLayer As IFeatureLayer) As DataTable

        Try

            Dim tmpDT As New DataTable("tmpDT")
            Dim column As DataColumn

            Dim pTable As ITable = inLayer.FeatureClass
            Dim pFields As IFields = pTable.Fields
            Dim pCur As ICursor = pTable.Search(Nothing, False)

            For c = 0 To pCur.Fields.FieldCount - 1
                column = New DataColumn()
                column.ColumnName = (pFields.Field(c).Name)
                If pFields.Field(c).Type = esriFieldType.esriFieldTypeString Then
                    column.DataType = System.Type.GetType("System.String")
                ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeInteger Then
                    column.DataType = System.Type.GetType("System.Int32")
                ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeDouble Then
                    column.DataType = System.Type.GetType("System.Double")
                ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeDate Then
                    column.DataType = System.Type.GetType("System.DateTime")
                ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeSingle Then
                    column.DataType = System.Type.GetType("System.Single")
                ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeBlob Then
                    column.DataType = System.Type.GetType("System.Byte")
                End If


                column.ReadOnly = False
                tmpDT.Columns.Add(column)
            Next

            Dim pRow As IRow = pCur.NextRow
            Dim newRow As DataRow

            Do Until pRow Is Nothing

                newRow = tmpDT.NewRow()
                newRow.BeginEdit()
                For cols = 0 To pCur.Fields.FieldCount - 1
                    newRow(cols) = pRow.Value(pRow.Fields.FindField(pFields.Field(cols).Name))
                Next
                newRow.EndEdit()
                tmpDT.Rows.Add(newRow)
                tmpDT.AcceptChanges()

                pRow = pCur.NextRow

            Loop

            Return tmpDT

        Catch ex As Exception
            MsgBox(ex.ToString)
            Return Nothing
        End Try

    End Function



Good Luck to ya!

james



Thanks jojolover for your reply,
I'm dealing with road segments(segment layer) and crash data(point layer) for different year. So when I run the program with crash data for say 2008 it would generate an attribute table for the road segment for 2008, similarly when crash data for 2009 is selected the attribute table for road segment is modified. I need to capture these different attribute tables and save them under different names.

I'm very new to ArcGIS and don't know much. Can you please explain to me how save the whole attribute to a collection type?

Thanks once again
0 Kudos
AsimShrestha1
New Contributor
Thanks James,
I was able to save the instances of the attribute tables to multiple datasets. Now I need to display them as graphs (histograms) on the map itself.
0 Kudos