上传用户:anyunliang
上传日期:2022-04-05
资源大小:2856k
文件大小:3k
源码类别:

GIS编程

开发平台:

Visual Basic

  1. Private Sub Command1_Click()
  2. 'this sample used the new AddField methods and the LayerInfo object to make a new tab
  3. 'file.   for each record in the Us_Cust table (found in mapstats.mdb) it adds a point
  4. 'feature to the new table.   for each feature added to the table, selected attribute
  5. 'data from Us_Cust is associated with that point (the company name, order ammount, city
  6. 'and state).
  7.    Dim rs As DAO.Recordset
  8.        Dim db As DAO.Database
  9.      
  10.        Dim flds As New MapXLib.Fields
  11.        Dim lyrNew As MapXLib.Layer
  12.        Dim ptNew As New MapXLib.Point
  13.        Dim ftrNew As MapXLib.Feature
  14.        Dim ff As MapXLib.FeatureFactory
  15.        Dim li As New MapXLib.LayerInfo
  16.        Dim rvs As New MapXLib.Rowvalues
  17.        Dim ds As MapXLib.Dataset
  18.      
  19.        'make database connection and get a recordset
  20.        Set db = DBEngine.OpenDatabase("C:Program FilesMapInfoMapX 5.0datamapstats.mdb")
  21.        Set rs = db.OpenRecordset("US_Cust")
  22.      
  23.        'we'll use feature factory later
  24.        Set ff = Map1.FeatureFactory
  25.      
  26.        'define the columnar structure of the new table we're going to create
  27.        flds.AddStringField "Company", 50
  28.        flds.AddStringField "City", 50
  29.        flds.AddStringField "State", 2
  30.        flds.AddNumericField "Order_Amt", 12, 2
  31.        'define the LayerInfo object
  32.        li.Type = miLayerInfoTypeNewTable
  33.        li.AddParameter "FileSpec", App.Path & "custtab.tab"
  34.        li.AddParameter "Name", "mycustomers"
  35.        li.AddParameter "Fields", flds
  36.      
  37.        'add the new layer to the top of the map
  38.        Map1.Layers.Add li, 1
  39.      
  40.        'make a dataset from the new layer and get its Rowvalues collection
  41.        Set lyrNew = Map1.Layers(1)
  42.        Set ds = Map1.Datasets.Add(miDataSetLayer, lyrNew)
  43.        Set rvs = ds.Rowvalues(0)
  44.      
  45.        'for each records in the Us_Cust table we'll make a point feature and add it
  46.        'to the newly created layer.   Using the Rowvalues object from that layer's
  47.        'dataset we'll supply attribute data for each point feature added
  48.        rs.MoveFirst
  49.       Do While Not rs.EOF
  50.             rvs.Item("Company").value = rs.Fields("Company")
  51.             rvs.Item("City").value = rs.Fields("City")
  52.             rvs.Item("State").value = rs.Fields("State")
  53.             rvs.Item("Order_Amt").value = rs.Fields("Order_Amt")
  54.          
  55.             ptNew.Set rs.Fields("X"), rs.Fields("Y")
  56.             Set ftrNew = ff.CreateSymbol(ptNew)
  57.             Set ftrNew = lyrNew.AddFeature(ftrNew, rvs)
  58.         
  59.             rs.MoveNext
  60.        Loop
  61.      
  62.       'close database connection
  63.        Set rs = Nothing
  64.       Set db = Nothing
  65. End Sub