明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

MapX中access表圖形化為mapinfo表的2種途徑

[摘要]access表-->MI表有兩種途徑:1.bindlayerXY方式綁定。指定bindlayer.filespec就可以創(chuàng)建永久表,不指定則為臨時(shí)表。Private Sub Command4_Click()'只能創(chuàng)建一個(gè)字段,GeoName,來源于City字段。當(dāng)City字段不能唯一...
access表-->MI表有兩種途徑:


1.bindlayerXY方式綁定。
指定bindlayer.filespec就可以創(chuàng)建永久表,不指定則為臨時(shí)表。

Private Sub Command4_Click()
'只能創(chuàng)建一個(gè)字段,GeoName,來源于City字段。當(dāng)City字段不能唯一是,state字段用于限定。
'不能創(chuàng)建索引
Dim BindlayerObject As New mapxlib.BindLayer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ds As mapxlib.Dataset

Set db = DBEngine.WorkSpaces(0).Opendatabase("C:\Program Files\MapInfo\MapX 4.0\Data\Mapstats.mdb")
Set rs = db.OpenRecordset("US_Cust")

BindlayerObject.LayerName = "新圖層名"
BindlayerObject.Filespec = App.Path + "\mytab.tab" '若不指定,則為臨時(shí)表
BindlayerObject.RefColumn1 = "X"
BindlayerObject.RefColumn2 = "Y"
BindlayerObject.LayerType = miBindLayerTypeXY

Set ds = Map1.Datasets.Add(miDataSetDAO, rs, "數(shù)據(jù)集名", "City", "State", BindlayerObject)
End Sub


2.layerInfo新建表
layers.add lyrinfo創(chuàng)建好一個(gè)有完備字段的空表
ds.rowvalues,
lyr.addfeature ftr,rvs填入圖元和屬性

Private Sub Command1_Click()
'可以創(chuàng)建多個(gè)字段
'mapx5中可以創(chuàng)建索引,mapx4中不可以
Dim rs As DAO.Recordset
Dim db As DAO.Database

Dim flds As New MapXLib.Fields

Dim lyrNew As MapXLib.Layer
Dim ptNew As New MapXLib.Point
Dim ftrNew As MapXLib.Feature
Dim ff As MapXLib.FeatureFactory
Dim li As New MapXLib.LayerInfo
Dim rvs As New MapXLib.Rowvalues
Dim ds As MapXLib.Dataset

Set db = DBEngine.OpenDatabase("C:\Program Files\MapInfo\MapX 4.0\data\mapstats.mdb")
Set rs = db.OpenRecordset("US_Cust")

Set ff = Map1.FeatureFactory

flds.AddStringField "Company", 50 ,true 'mapx5中可以創(chuàng)建索引,
'flds.AddStringField "Company", 50 'mapx4中不可以創(chuàng)建索引,
flds.AddStringField "City", 50
flds.AddStringField "State", 2
flds.AddNumericField "Order_Amt", 12, 2


li.Type = miLayerInfoTypeNewTable
li.AddParameter "FileSpec", App.Path & "\custtab.tab"
li.AddParameter "Name", "mycustomers"
li.AddParameter "Fields", flds


Map1.Layers.Add li, 1
'到此為止,已經(jīng)用access表建好mapinfo表,也設(shè)置好了字段,但是沒有圖元在上面,也沒有記錄。
'下面從access表中x,y創(chuàng)建點(diǎn)圖元,同時(shí)把其屬性數(shù)據(jù)也添加進(jìn)去
'--------------------------------------------------------------------

Set lyrNew = Map1.Layers(1)
Set ds = Map1.Datasets.Add(miDataSetLayer, lyrNew)
Set rvs = ds.Rowvalues(0)

rs.MoveFirst
Do While Not rs.EOF
rvs.Item("Company").value = rs.Fields("Company") 'rvs.Item("Company")可寫為rvs("Company")
rvs.Item("City").value = rs.Fields("City")
rvs.Item("State").value = rs.Fields("State")
rvs.Item("Order_Amt").value = rs.Fields("Order_Amt")

ptNew.Set rs.Fields("X"), rs.Fields("Y")
Set ftrNew = ff.CreateSymbol(ptNew)
Set ftrNew = lyrNew.AddFeature(ftrNew, rvs) ' 圖元+屬性,即feature+Rowvalues
'Set ftrNew = lyrNew.AddFeature(ftrNew)
'ftrNew.Update True, rvs

rs.MoveNext
Loop

Set rs = Nothing
Set db = Nothing
End Sub