📄 clsevaluatewizard.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 = "clsEvaluateWizard"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'************************************************************************************************
'*********************** 应用向导形式实现连贯的损失评估 ***********************
'*********************** ZHANG Wenjiang, 2004/05/14 ***********************
'************************************************************************************************
Option Explicit
Dim m_pCommand As ICommand
Dim m_pTool As ITool
Dim m_pSketchTool As ISketchTool
Dim m_pApp As IApplication
Dim pMxDoc As IMxDocument
Dim m_bSumResultFirst As Boolean
Dim itemName As String
Dim strResultPath As String, strResultFile As String
Dim pResultShpLyr As IFeatureLayer, indexName1 As Integer, indexLoss1 As Integer
Implements ICommand
Private Property Get ICommand_Bitmap() As esriCore.OLE_HANDLE
ICommand_Bitmap = frmResources.picEvaluate.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 lossEvaluateWizard(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
'************************************************************************************************''''''
'''''''lossEvaluateWizard调用分步评估的函数,将整个评估步骤集成在一起
'''''''计算水深: WaterDepth()
'''''''评估作物洪损: cropEvaluation()
'''''''评估其他财物洪损:EvaluateLoss()
'''''''统计多项洪水损失:evaluateSum()
'************************************************************************************************''''''
Public Sub lossEvaluateWizard(pApp As IApplication)
On Error GoTo ERH
' Set pMxDoc = m_pApp.Document
Dim bFlag As Boolean
bFlag = FloodedRange(pApp) '''''''计算范围: WaterRange()
If Not bFlag Then GoTo ERH
bFlag = WaterDepth(pApp) '''''''计算水深: WaterDepth()
If Not bFlag Then GoTo ERH
bFlag = cropEvaluation(pApp) '''''''评估作物洪损: cropEvaluation()
If Not bFlag Then GoTo ERH
Dim nResult As Integer
nResult = MsgBox("评价其他损失项目", vbYesNo)
While nResult = vbYes
bFlag = planarPropSum(pApp) '''''''评估其他财物洪损:EvaluateLoss()
If Not bFlag Then GoTo ERH
nResult = MsgBox("继续评价其他项目", vbYesNo)
Wend
bFlag = evaluateSum(pApp) '''''''统计多项洪水损失:evaluateSum()
If Not bFlag Then GoTo ERH
MsgBox "完成洪水评估计算"
Exit Sub
ERH:
MsgBox "评估失败" & Chr(13) & ERR.Description, vbInformation + vbOKOnly, "提示信息"
End Sub
'**************************************************************************************************************
'clsWaterRange
'**************************************************************************************************************
'************************************************************************************************''''''''''''''
'''''FloodedRange计算洪水淹没范围
'************************************************************************************************''''''''''''''
Public Function FloodedRange(pApp As IApplication) As Boolean
On Error GoTo errHandle
' Declare the dataset objects
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pFeaLyr As IFeatureLayer, pFloodFeatLyr As IFeatureLayer, pOutFeatLyr As IFeatureLayer, pWaterFeatLyr As IFeatureLayer
Dim fs
Dim strWaterPath As String, strFloodPath As String, strResultPath As String
Dim strWaterFile As String, strFloodFile As String, strResultFullFile As String, strTemp As String
frmFloodArea.Left = (Screen.Width - frmFloodArea.Width) / 2
frmFloodArea.Top = (Screen.Height - frmFloodArea.Height) / 2
frmFloodArea.Show vbModal
If frmFloodArea.flagOK Then
Set fs = CreateObject("Scripting.FileSystemObject")
strWaterFile = frmFloodArea.strPathWater & ".shp"
strFloodFile = frmFloodArea.strPathFlood & ".shp"
strResultFullFile = frmFloodArea.strPathResult
' If Not fs.FileExists(strWaterFile) Then '
' MsgBox "指定本体水体文件不存在,请查实"
' Exit Sub
' End If
'
' If Not fs.FileExists(strFloodFile) Then '
' MsgBox "指定洪水水体文件不存在,请查实"
' Exit Sub
' End If
' Call SplitPath(strWaterFile, strWaterPath, strTemp)
' strWaterFile = strTemp
' Call SplitPath(strFloodFile, strFloodPath, strTemp)
' strFloodFile = strTemp
If fs.FileExists(strResultFullFile) Then '
MsgBox strResultFullFile & "已存在,将被覆盖"
fs.DeleteFile (strResultFullFile) '
End If
If fs.FileExists(Left(strResultFullFile, Len(strResultFullFile) - 4) + ".dbf") Then '
fs.DeleteFile (Left(strResultFullFile, Len(strResultFullFile) - 4) + ".dbf") '
End If
Call SplitPath(strResultFullFile, strResultPath, strTemp)
strResultFullFile = Left(strTemp, Len(strTemp) - 4)
Else
MsgBox "放弃淹没范围计算"
FloodedRange = False
Exit Function
End If
Set pFloodFeatLyr = frmFloodArea.shpFloodLyr
Set pWaterFeatLyr = frmFloodArea.shpWaterLyr
Dim pSpaRef As ISpatialReference
Set pSpaRef = GetLayerSourceSpatialRef(pFloodFeatLyr) ' set CoordinateSystem for the new result shape file
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(strResultPath, 0)
Dim pNewFeatClass As IFeatureClass
Set pNewFeatClass = CreateShapefile(pFeatureWorkspace, strResultFullFile, pSpaRef) ' create a null shape file for the flood range
Call Difference(pFloodFeatLyr, pWaterFeatLyr, pNewFeatClass) '''通过difference进行多边形的异处理,去除本体水体
Dim pMxDoc As IMxDocument
Set pMxDoc = pApp.Document
Dim pFeatLyr As IFeatureLayer
Set pFeatLyr = New FeatureLayer
Set pFeatLyr.FeatureClass = pNewFeatClass
pFeatLyr.name = "洪水淹没范围"
Call setFeatureLayerRenderer(pFeatLyr, vbRed)
pMxDoc.FocusMap.AddLayer pFeatLyr
pMxDoc.ActiveView.Refresh
Set pWorkspaceFactory = Nothing
Set pFeatureWorkspace = Nothing
Set pWaterFeatLyr = Nothing
Set pFloodFeatLyr = Nothing
Set pMxDoc = Nothing
Set pFeatLyr = Nothing
MsgBox "完成淹没范围计算!"
Exit Function 'exit sub to avoid error handler
errHandle:
MsgBox "计算淹没范围失败" & Chr(13) & ERR.Description, vbInformation + vbOKOnly, "提示信息"
End Function
'************************************************************************************************''''''''''''''
'''''Difference进行两个多边形图层间的叠加,剔除洪水水体中的平水期水体,得到真正淹没的范围
'************************************************************************************************''''''''''''''
Public Sub Difference(pSourceFeatLayer As IFeatureLayer, pFilterFeatLayer As IFeatureLayer, pOutFeatClass As IFeatureClass)
On Error GoTo errHandle:
Dim pFilter As IQueryFilter
Dim pFeatCursor1 As IFeatureCursor
Dim pFeatCursor2 As IFeatureCursor
Set pFilter = New QueryFilter
pFilter.WhereClause = ""
Dim sourceFeat As IFeature, filterFeat As IFeature, resultFeat As IFeature
Dim pGeoResult As IGeometry, pIntersect As IGeometry
Dim pTopoOp As ITopologicalOperator
Set pFeatCursor1 = pFilterFeatLayer.Search(pFilter, False)
Set filterFeat = pFeatCursor1.NextFeature
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do While Not filterFeat Is Nothing
Set pFeatCursor2 = pSourceFeatLayer.Search(pFilter, False)
Set sourceFeat = pFeatCursor2.NextFeature
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do While Not sourceFeat Is Nothing
Set pTopoOp = sourceFeat.Shape
If Not pTopoOp.Intersect(filterFeat.Shape, esriGeometry2Dimension).IsEmpty Then ' Skip creation if without the intersection of polygons is null
Set pGeoResult = pTopoOp.Difference(filterFeat.Shape)
Call CreateFeature(pOutFeatClass, pGeoResult) '创建一个洪水淹没矢量图斑
End If
Set sourceFeat = pFeatCursor2.NextFeature
Loop '''''''''''''''''''''''''''''''''''''''''''''''''''Do While Not sourceFeat Is Nothing
Set filterFeat = pFeatCursor1.NextFeature
Loop '''''''''''''''''''''''''''''''''''''''''''''''''''''''Do While Not filterFeat Is Nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set pFilter = Nothing
Exit Sub 'exit sub to avoid error handler
errHandle:
MsgBox "提取洪水淹没范围失败" & Chr(13) & ERR.Description, vbInformation + vbOKOnly, "提示信息"
End Sub
'************************************************************************************************''''''''''''''
'''CreateShapefile创建一个多边形文件
'************************************************************************************************''''''''''''''
Public Function CreateShapefile(pShapeWsF As IFeatureWorkspace, strShapeName As String, spatialRef As ISpatialReference) As IFeatureClass
On Error GoTo Errhdr
Const strShapeFieldName As String = "Shape"
' Set up a simple fields collection
Dim pFields As IFields
Dim pFieldsEdit As IFieldsEdit
Set pFields = New esriCore.Fields
Set pFieldsEdit = pFields
Dim pField As IField
Dim pFieldEdit As IFieldEdit
' Make the shape field
' it will need a geometry definition, with a spatial reference
Set pField = New esriCore.Field
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -