This project has moved. For the latest updates, please go here.

Creating Shapefile from Data(base)Table

Topics: General Topics
Nov 16, 2006 at 3:20 PM
Hi All,

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)

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)
End If
Dim newShapeFile As ShapeFile = ShapeFile.Create("d:\", "wells", ShapeType.Point, 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
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