📄 clsevaluateplane.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsEvaluatePlane"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'************************************************************************************************
'*********************** 统计指定区域内的面状财物损失 ***********************
'*********************** ZHANG Wenjiang, 2004/06/07 ***********************
'************************************************************************************************
Option Explicit
Dim m_pCommand As ICommand
Dim m_pTool As ITool
Dim m_pSketchTool As ISketchTool
Dim m_pApp As IApplication
Implements ICommand
Private Property Get ICommand_Bitmap() As esriCore.OLE_HANDLE
ICommand_Bitmap = frmResources.picArea.Picture
End Property
Private Property Get ICommand_Caption() As String
ICommand_Caption = "面状项目评估"
End Property
Private Property Get ICommand_Category() As String
ICommand_Category = "洪损评估"
End Property
Private Property Get ICommand_Checked() As Boolean
ICommand_Checked = False
End Property
Private Property Get ICommand_Enabled() As Boolean
ICommand_Enabled = True
End Property
Private Property Get ICommand_HelpContextID() As Long
End Property
Private Property Get ICommand_HelpFile() As String
End Property
Private Property Get ICommand_Message() As String
ICommand_Message = "面状项目评估"
End Property
Private Property Get ICommand_Name() As String
ICommand_Name = "CustomSketch.SketchTool"
End Property
Private Sub ICommand_OnClick()
Call planarPropSum(m_pApp)
End Sub
Private Sub ICommand_OnCreate(ByVal hook As Object)
On Error GoTo ErrorHandler:
Set m_pApp = hook
Set m_pCommand = CreateObject("esricore.SketchTool")
m_pCommand.OnCreate hook
Set m_pTool = m_pCommand
Set m_pSketchTool = m_pCommand
Exit Sub
ErrorHandler:
MsgBox "OnCreate - " & ERR.Description
Exit Sub
End Sub
Private Property Get ICommand_Tooltip() As String
ICommand_Tooltip = "面状项目评估"
End Property
'************************************************************************************************'''
''''populationSum对受灾人口进行估计,具体工作由populateSum来实现
'************************************************************************************************'''
Public Sub planarPropSum(pApp As IApplication)
On Error GoTo ERH
Dim sWorkPath As String, sShapeFileName As String, sGridFileName As String
Dim pOutRas1 As IGeoDataset
Dim fs
Dim strResultPath As String, strResultFile As String, strTemp As String
Dim itemName As String, itemPrice As Integer
Dim pPlanarPropLyr As IFeatureLayer, pFloodRangeLyr As IFeatureLayer
frmEvaluatePlane.Left = (Screen.Width - frmEvaluatePlane.Width) / 2
frmEvaluatePlane.Top = (Screen.Height - frmEvaluatePlane.Height) / 2
frmEvaluatePlane.Show vbModal
If frmEvaluatePlane.flagOK Then
Set fs = CreateObject("Scripting.FileSystemObject")
strResultFile = frmEvaluatePlane.txtPathResult '统计的结果,shape格式
itemName = frmEvaluatePlane.strItemName
itemPrice = CInt(frmEvaluatePlane.strItemPrice)
Set pPlanarPropLyr = frmEvaluatePlane.shpPlanarPropLyr
Set pFloodRangeLyr = frmEvaluatePlane.shpFloodAreaLyr
If fs.FileExists(strResultFile) Then '
fs.DeleteFile (strResultFile)
End If
If fs.FileExists(Left(strResultFile, Len(strResultFile) - 4) + ".dbf") Then '
fs.DeleteFile (Left(strResultFile, Len(strResultFile) - 4) + ".dbf")
End If
Call SplitPath(strResultFile, strResultPath, strTemp)
strResultFile = strTemp
Else
MsgBox "放弃评估"
Exit Sub
End If
Call planarSum(pFloodRangeLyr, pPlanarPropLyr, strResultFile, strResultPath, _
itemName, itemPrice, pApp)
Exit Sub
ERH:
MsgBox "受灾统计失败0" & Chr(13) & ERR.Description, vbInformation + vbOKOnly, "提示信息"
End Sub
'************************************************************************************************'''
''''populateSum具体实现对受灾人口的统计
'************************************************************************************************'''
Public Sub planarSum(pFloodRangeLyr As IFeatureLayer, pPlanarPropLyr As IFeatureLayer, _
strResultFile As String, strResultPath As String, itemName As String, _
itemPrice As Integer, pApp As IApplication)
On Error GoTo errHandle
' Create the RasterExtractionOp/MathOps object
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pSpaRef As ISpatialReference
Set pSpaRef = GetLayerSourceSpatialRef(pPlanarPropLyr) 'New UnknownCoordinateSystem
' Set pFeatureWorkspace = Nothing
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(strResultPath, 0)
Dim pFlds As IFields
Set pFlds = CreateFeatureFields(esriGeometryPolygon, True, False, pSpaRef, itemName)
Call AppendField(pFlds, "地区", esriFieldTypeString, False)
Call AppendField(pFlds, "财物总量", esriFieldTypeInteger, False)
Call AppendField(pFlds, "面积", esriFieldTypeDouble, False)
Call AppendField(pFlds, "受灾面积", esriFieldTypeDouble, False)
Call AppendField(pFlds, "受灾数量", esriFieldTypeInteger, False)
Call AppendField(pFlds, "受灾损失", esriFieldTypeDouble, False)
Dim pCLSID As UID
Set pCLSID = New UID
pCLSID.Value = "esricore.Feature"
Dim pFClass As IFeatureClass
Set pFClass = pFeatureWorkspace.CreateFeatureClass(Left(strResultFile, Len(strResultFile) - 4), _
pFlds, pCLSID, Nothing, esriFTSimple, "Shape", "")
'设置有关字段的索引号
Dim indexName As Integer, indexProp As Integer, indexFloodLoss1 As Integer
Dim indexName1 As Integer, indexProp1 As Integer, indexFloodProp1 As Integer, indexFloodArea1 As Integer, indexArea1 As Integer
Dim pFields As IFields
Set pFields = pPlanarPropLyr.FeatureClass.Fields
indexName = pFields.FindField("地区") '政区名称
indexProp = pFields.FindField("财物总量") '政区人口
indexName1 = pFlds.FindField("地区") '政区名称
indexProp1 = pFlds.FindField("财物总量") '政区人口
indexArea1 = pFlds.FindField("面积") '政区面积
indexFloodArea1 = pFlds.FindField("受灾面积") '受灾面积
indexFloodProp1 = pFlds.FindField("受灾数量") '受灾人口
indexFloodLoss1 = pFlds.FindField("受灾损失") '受灾人口
' MsgBox indexName & "-" & indexName1 & "-" & indexProp1 & "-" & indexArea1 & "-" & indexProp
Dim pOutCursor As IFeatureCursor
Set pOutCursor = pFClass.Insert(True)
Dim pOutBuffer As IFeatureBuffer
Set pOutBuffer = pFClass.CreateFeatureBuffer
Dim pFilter As IQueryFilter
Set pFilter = New QueryFilter
pFilter.WhereClause = ""
Dim pFloodCursor As IFeatureCursor, pPropCursor As IFeatureCursor
Set pPropCursor = pPlanarPropLyr.Search(pFilter, False)
Dim sumArea As Double
Dim pTopologOp As ITopologicalOperator, pGeoResult As IGeometry
Dim pPropArea As IArea, pAndArea As IArea
Dim pPropPoly As IPolygon, pFloodPoly As IPolygon
Dim pPropFeat As IFeature, pFloodFeat As IFeature
Set pPropFeat = pPropCursor.NextFeature
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do While Not pPropFeat Is Nothing
Set pTopologOp = pPropFeat.Shape
Set pFloodCursor = pFloodRangeLyr.Search(pFilter, False)
Set pFloodFeat = pFloodCursor.NextFeature
sumArea = 0
Do While Not pFloodFeat Is Nothing
Set pFloodPoly = pFloodFeat.Shape
Set pGeoResult = pTopologOp.Intersect(pFloodPoly, esriGeometry2Dimension)
Set pAndArea = pGeoResult
sumArea = sumArea + pAndArea.Area
Set pFloodFeat = pFloodCursor.NextFeature
Loop
Set pOutBuffer.Shape = pPropFeat.Shape
Set pPropArea = pPropFeat.Shape
pOutBuffer.Value(indexName1) = pPropFeat.Value(indexName) '统计出该区域内淹没的面积,需乘以人口密度才为受灾人口
pOutBuffer.Value(indexProp1) = pPropFeat.Value(indexProp) '统计出该区域内淹没的面积,需乘以人口密度才为受灾人口
pOutBuffer.Value(indexArea1) = pPropArea.Area '统计出该区域内淹没的面积,需乘以人口密度才为受灾人口
pOutBuffer.Value(indexFloodArea1) = sumArea '统计出该区域内淹没的面积,需乘以人口密度才为受灾人口
pOutBuffer.Value(indexFloodProp1) = pPropFeat.Value(indexProp) * sumArea / pPropArea.Area '统计出该区域内淹没的面积,需乘以人口密度才为受灾人口
pOutBuffer.Value(indexFloodLoss1) = pOutBuffer.Value(indexFloodProp1) * itemPrice '统计出该区域内淹没的面积,需乘以人口密度才为受灾人口
pOutCursor.InsertFeature pOutBuffer
Set pPropFeat = pPropCursor.NextFeature
Loop '''''''''''''''''''''''''''''''''''''''''''''''''''''''Do While Not filterFeat Is Nothing
Dim pMxDoc As IMxDocument
Set pMxDoc = pApp.Document
Dim pPolygonLayer As IFeatureLayer
Set pPolygonLayer = New FeatureLayer
Set pPolygonLayer.FeatureClass = pFClass
Call setFeatureLayerRenderer(pPolygonLayer, vbBlue)
pPolygonLayer.name = "受灾分布"
pMxDoc.FocusMap.AddLayer pPolygonLayer 'pRL
pMxDoc.ActiveView.Refresh
' Set pPolygonLayer = Nothing
Set pWorkspaceFactory = Nothing
Set pFeatureWorkspace = Nothing
Set pOutBuffer = Nothing
Set pOutCursor = Nothing
Exit Sub 'exit sub to avoid error handler
errHandle:
MsgBox "受灾统计失败" & Chr(13) & ERR.Description, vbInformation + vbOKOnly, "提示信息"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -