MapX中access表图形化为mapinfo表的两种途径

发表于:2007-07-14来源:作者:点击数: 标签:
access表-- MI 表有两种途径: 1.bindlayerXY方式绑定。 指定bindlayer.filespec就可以创建永久表,不指定则为临时表。 Private Sub Command4_Click() '只能创建一个字段,GeoName,来源于City字段。当City字段不能唯一是,state字段用于限定。 '不能创建索引
aclearcase/" target="_blank" >ccess表-->MI表有两种途径:


1.bindlayerXY方式绑定。
指定bindlayer.filespec就可以创建永久表,不指定则为临时表。

Private Sub Command4_Click()
'只能创建一个字段,GeoName,来源于City字段。当City字段不能唯一是,state字段用于限定。
'不能创建索引
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" '若不指定,则为临时表
BindlayerObject.RefColumn1 = "X"
BindlayerObject.RefColumn2 = "Y"
BindlayerObject.LayerType = miBindLayerTypeXY

Set ds = Map1.Datasets.Add(miDataSetDAO, rs, "数据集名", "City", "State", BindlayerObject)
End Sub


2.layerInfo新建表
layers.add lyrinfo创建好一个有完备字段的空表
ds.rowvalues,
lyr.addfeature ftr,rvs填入图元和属性

Private Sub Command1_Click()
'可以创建多个字段
'mapx5中可以创建索引,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中可以创建索引,
'flds.AddStringField "Company", 50 'mapx4中不可以创建索引,
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
'到此为止,已经用access表建好mapinfo表,也设置好了字段,但是没有图元在上面,也没有记录。
'下面从access表中x,y创建点图元,同时把其属性数据也添加进去
'--------------------------------------------------------------------

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

原文转自:http://www.ltesting.net