阅读:2120回复:1
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 |
|
|
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" />
|
|