⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 地理信息系统工程案例精选程序,本书所有案例均需要单独配置
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form1 
   Caption         =   "Statistics对象示例"
   ClientHeight    =   4575
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8040
   LinkTopic       =   "Form1"
   ScaleHeight     =   4575
   ScaleWidth      =   8040
   StartUpPosition =   3  '窗口缺省
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   5520
      Style           =   2  'Dropdown List
      TabIndex        =   2
      Top             =   600
      Width           =   2415
   End
   Begin MapObjects2.Map Map1 
      Height          =   4335
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5295
      _Version        =   131072
      _ExtentX        =   9340
      _ExtentY        =   7646
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "Form1.frx":0000
   End
   Begin VB.Label lblSum 
      Caption         =   "Label8"
      Height          =   255
      Left            =   5520
      TabIndex        =   9
      Top             =   3960
      Width           =   2415
   End
   Begin VB.Label lblStdDev 
      Caption         =   "Label7"
      Height          =   255
      Left            =   5520
      TabIndex        =   8
      Top             =   3480
      Width           =   2415
   End
   Begin VB.Label lblMin 
      Caption         =   "Label6"
      Height          =   255
      Left            =   5520
      TabIndex        =   7
      Top             =   3000
      Width           =   2415
   End
   Begin VB.Label lblMean 
      Caption         =   "Label5"
      Height          =   255
      Left            =   5520
      TabIndex        =   6
      Top             =   2520
      Width           =   2415
   End
   Begin VB.Label lblMax 
      Caption         =   "Label4"
      Height          =   255
      Left            =   5520
      TabIndex        =   5
      Top             =   2040
      Width           =   2415
   End
   Begin VB.Label lblCount 
      Caption         =   "Label3"
      Height          =   255
      Left            =   5520
      TabIndex        =   4
      Top             =   1560
      Width           =   2415
   End
   Begin VB.Label Label2 
      Caption         =   "相应字段的统计信息:"
      Height          =   255
      Left            =   5520
      TabIndex        =   3
      Top             =   1080
      Width           =   1935
   End
   Begin VB.Label Label1 
      Caption         =   "字段:"
      Height          =   255
      Left            =   5520
      TabIndex        =   1
      Top             =   240
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'组合框鼠标单击事件响应代码
Private Sub Combo1_Click()
  '在List1中显示当前选择字段的值
  
  Dim RecordsetX As MapObjects2.Recordset
  Set RecordsetX = Map1.Layers(0).Records
  
  '创建Statistics对象
  Dim StatisticsX As MapObjects2.Statistics
  Set StatisticsX = RecordsetX.CalculateStatistics(Combo1.Text)
  
  '显示统计信息
  lblCount.Caption = "记录数:" & CStr(StatisticsX.Count)
  lblMax.Caption = "最大值:" & CStr(StatisticsX.Max)
  lblMean.Caption = "平均值:" & CStr(StatisticsX.Mean)
  lblMin.Caption = "最小值:" & CStr(StatisticsX.Min)
  lblStdDev.Caption = "标准差:" & CStr(StatisticsX.StdDev)
  lblSum.Caption = "总和:" & CStr(StatisticsX.Sum)
  
End Sub

Private Sub Form_Load()
  Call SetupLayers
  Call GetFields
End Sub

Sub SetupLayers()
  '调入数据
  
  Dim dc As New DataConnection
  'MapObjects自带的USA地图
  '默认路径为C:\Program Files\ESRI\MapObjects2\Samples\Data\USA
  dc.Database = "C:\Program Files\ESRI\MapObjects2\Samples\Data\USA"
  '若连接地理数据库失败,则结束程序
  If Not dc.Connect Then End
  '调入图层Counties.shp
  Dim layer As New MapLayer
  Set layer.GeoDataset = dc.FindGeoDataset("Counties")
  Map1.Layers.Add layer
End Sub

Sub GetFields()
  '获取MapLayer的Recordset对象中所有字段
  
  '获取Country图层
  Dim LayerX As MapLayer
  Set LayerX = Map1.Layers(0)
  '获取其数据集
  Dim RecordsetX As MapObjects2.Recordset
  Set RecordsetX = LayerX.Records
  
  Combo1.Clear
  '获取其中所有字段
  Dim FieldX As MapObjects2.Field
  For Each FieldX In RecordsetX.Fields
    '判断是不是数值类型的字段
    '数值类型的字段才有统计信息
    If FieldX.Type = moLong Or FieldX.Type = moDouble Then
      Combo1.AddItem FieldX.Name
    End If
  Next
  
  If Combo1.ListCount > 0 Then
    Combo1.ListIndex = 0
  End If
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -