Create Shapefile from Database Table

Nov 20, 2006 at 6:12 PM
Hi All,

I posted this in the User's forum last week and didn't hear anything, I thought I would try the Developer forum... Sorry for the cross-post.

I am running a query against a database, filling a DataTable and then trying to generate a shapefile from it. I keep getting "Recorded record length doesn't equal computed record length" from line 187 of DbaseHeader.cs. I've tried everything I can think of to make things work out to no avail. So,maybe you all can help. Here's my code:


Dim da As New SqlDataAdapter(WellSQL, ConString)
Dim dt As New DataTable("Wells")
da.FillSchema(dt, SchemaType.Mapped)
da.Fill(dt)

Dim fdt As FeatureDataTable = DataTable2FeatureDataTable(dt)

Dim dr As FeatureDataRow
Dim pt As SharpMap.Geometries.Point
For Each r As DataRow In dt.Rows
'//make & add rows
If r("LATITUDE") IsNot Nothing AndAlso r("LONGITUDE") IsNot Nothing Then
'dr = f.Tables(0).NewRow
dr = fdt.NewRow
pt = New SharpMap.Geometries.Point(r("LONGITUDE"), r("LATITUDE"))
dr.Geometry = pt
For i As Integer = 0 To r.Table.Columns.Count - 1
dr(i) = r(i)
Next
'f.Tables(0).Rows.Add(dr)
fdt.Rows.Add(dr)
End If
Next
Dim newShapeFile As ShapeFile = ShapeFile.Create("d:\", "wells", ShapeType.Point, fdt)
newShapeFile.Open(True)
newShapeFile.Save(fdt)


Public Function DataTable2FeatureDataTable(ByVal sTable As DataTable) As FeatureDataTable
Dim dt As New FeatureDataTable '(Of String)("API_WELLNO")

Dim dc As DataColumn
For Each c As DataColumn In sTable.Columns
dc = New DataColumn
With dc
.ColumnName = c.ColumnName
.DataType = c.DataType
.MaxLength = c.MaxLength
End With
dt.Columns.Add(dc)
Next
Return dt
End Function

I'm using the latest 2.0RC code.

I have verified that the DataTable.Columns(i).MaxLength poperty is correct for strings, should i need something other than -1 for numbers?

Thanks in advance,

Dave Lowther