Private Sub Command4_Click()
Dim gds As MapObjects2.GeoDataset
Dim sName As String
Dim Desc As New TableDesc
Dim dc As New DataConnection
Dim Lyr As New MapObjects2.MapLayer
Dim resc As MapObjects2.Recordset
Dim rst1 As ADODB.Recordset
Dim i As Integer
Dim Cnn2 As ADODB.Connection
Dim P1 As MapObjects2.Point
Dim str1 As String
Dim X2 As Single, Y2 As Single
Dim X1 As Single, Y1 As Single
Set Cnn2 = New ADODB.Connection
str1 = "Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "/fuzhou1.mdb"
Cnn2.ConnectionString = str1
Cnn2.Open
Set rst1 = New ADODB.Recordset
rst1.Open "select * from office", Cnn2, adOpenStatic, adLockReadOnly
With CommonDialog1
.Filter = "ESRI Shapefiles(*.shp)|*.shp"
.DefaultExt = ".shp"
.ShowSave
If Len(.FileName) = 0 Then Exit Sub
dc.Database = CurDir
If Not dc.Connect Then Exit Sub
sName = Left(.FileTitle, Len(.FileTitle) - 4)
End With
With Desc
.FieldCount = 2
.FieldName(0) = "Name"
.FieldName(1) = "id"
.FieldType(0) = moString
.FieldType(1) = moLong
.FieldLength(0) = 16
.FieldPrecision(1) = 15
End With
Set gds = dc.AddGeoDataset(sName, moPoint, Desc)
Set Lyr.GeoDataset = gds
For i = 1 To rst1.RecordCount
X1 = Format(Form2.Map1.FromMapDistance(rst1!x), "#.00")
Y1 = Format(Form2.Map1.FromMapDistance(rst1!y ), "#.00")
Set P1 = Form2.Map1.ToMapPoint(X1, Y1)
With Lyr.Records
.AddNew
.Fields("Shape").Value = P1
.Fields("Name").Value = rst1!name
.Fields("id").Value = rst1!id
.Update
End With
rst1.MoveNext
Next
Lyr.Symbol.Color = moMaroon
MsgBox "文件已生成"
Exit Sub
End Sub
这可以生成shape的点状文件,不过如果要生成线状文件要怎么改动程序呢?有没有人知道的可以帮我解决下啊,不甚感激!
数据库中的表(点:x(经度值)、y(纬度值)、id)
线:id pid x y recordno
1 0 1
1 1 2
1 2 3
1 3 4
2 0 5
2 1 6
2 2 7
.........
这是数据库表中的数据
会的赶紧帮我一把啊!!!!