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

📄 ao对选中要素进行属性统计.txt

📁 统计制作中常用的源代码
💻 TXT
字号:
AO对选中要素进行属性统计  
作者: 兔八哥  
   
Public Sub SumSelectedFeatures()

Dim pMxDoc As IMxDocument
Dim pmap As Imap
Dim player As IFeatureLayer
Dim pFcc As IFeatureClass
Dim pFields As Ifields
Dim pNumFields As Ifields
Dim numAreaField As Double
Dim pField As Ifield

Set pMxDoc = ThisDocument
Set pmap = pMxDoc.FocusMap
Set player = pmap.Layer(0)
Set pFcc = player.FeatureClass
Set pFields = pFcc.Fields

'Get a field to Sum
Set pNumFields = pFields
numAreaField = pFields.FindField("pop1997") ' <--Enter a field here


'Check for a valid field index number
If numAreaField < 0 Then
MsgBox "Please enter a Valid field name", vbCritical, "Field Doesn't Exist"
Exit Sub
End If

Set pField = pFields.Field(numAreaField)

'***Other useful field stuff***
'.FindField("AREA")
'MsgBox numAreaField
'MsgBox pField.Name
'MsgBox pFields.FieldCount
'MsgBox player.Name

'Get the selected records
Dim pFeatureSelection As IFeatureSelection
Set pFeatureSelection = player

Dim pSelected As ISelectionSet
Set pSelected = pFeatureSelection.SelectionSet

Dim pCursor As Icursor
pSelected.Search Nothing, False, pCursor

Dim pfeature As Ifeature
Dim counter As Integer
counter = 0

Dim sumAREA As Double
sumAREA = 0

Set pfeature = pCursor.NextRow

Do Until pfeature Is Nothing
counter = counter + 1
sumAREA = sumAREA + pfeature.Value(numAreaField)

Set pfeature = pCursor.NextRow

Loop

MsgBox "Total " & pField.Name & " is: " & sumAREA
'MsgBox counter & " Selected records"

End Sub

 

⌨️ 快捷键说明

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