在VB+Mapx5.0中新建图层及属性的源代码

 

代码:

Private Sub Command1_Click()
'this sample used the new AddField methods and the LayerInfo object to make a new tab
'file.   for each record in the Us_Cust table (found in mapstats.mdb) it adds a point
'feature to the new table.   for each feature added to the table, selected attribute
'data from Us_Cust is associated with that point (the company name, order ammount, city
'and state).
   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
     
       'make database connection and get a recordset
       Set db = DBEngine.OpenDatabase("C:/Program Files/MapInfo/MapX 5.0/data/mapstats.mdb")
       Set rs = db.OpenRecordset("US_Cust")
     
       'we'll use feature factory later

       Set ff = Map1.FeatureFactory
     
       'define the columnar structure of the new table we're going to create
       flds.AddStringField "Company", 50
       flds.AddStringField "City", 50
       flds.AddStringField "State", 2
       flds.AddNumericField "Order_Amt", 12, 2

       'define the LayerInfo object
       li.Type = miLayerInfoTypeNewTable
       li.AddParameter "FileSpec", App.Path & "/custtab.tab"
       li.AddParameter "Name", "mycustomers"
       li.AddParameter "Fields", flds

     
       'add the new layer to the top of the map
       Map1.Layers.Add li, 1
     
       'make a dataset from the new layer and get its Rowvalues collection
       Set lyrNew = Map1.Layers(1)
       Set ds = Map1.Datasets.Add(miDataSetLayer, lyrNew)
       Set rvs = ds.Rowvalues(0)
     
       'for each records in the Us_Cust table we'll make a point feature and add it
       'to the newly created layer.   Using the Rowvalues object from that layer's
       'dataset we'll supply attribute data for each point feature added

       rs.MoveFirst
      Do While Not rs.EOF
            rvs.Item("Company").value = rs.Fields("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)
        
            rs.MoveNext

       Loop
     
      'close database connection
       Set rs = Nothing
      Set db = Nothing
End Sub

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值