queensf
总版主
总版主
  • 注册日期2003-12-04
  • 发帖数735
  • QQ
  • 铜币3枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2120回复:1

AO对选中要素进行属性统计

楼主#
更多 发布于:2004-02-26 11:03
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



喜欢0 评分0
[color=blue][size=4][i][b][u] 【 解决不了的事情,就不要想。世界不会因为我而改变。 】 [/size][/u][/b][/i][/color]
blaster
路人甲
路人甲
  • 注册日期2005-02-22
  • 发帖数153
  • QQ
  • 铜币486枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2005-03-24 16:25
<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部