?? clsfloodedarea.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 = "clsWaterRange"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'************************************************************************************************
'*********************** To calculate the flooded area ***********************
'*********************** The result is raster cells ***********************
'*********************** ZHANG Wenjiang, 2004/02/17 ***********************
'************************************************************************************************
Option Explicit
Dim m_pCommand As ICommand
Dim m_pTool As ITool
Dim m_pSketchTool As ISketchTool
Dim m_pApp As IApplication
Dim m_pEditor As IEditor
Implements ICommand
Private Property Get ICommand_Bitmap() As esriCore.OLE_HANDLE
ICommand_Bitmap = frmResources.picWaterRange.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 FloodedRange(m_pApp) 'WaterDepth 'polygonSelect0 'NeighborhoodNotation 'pixelOp
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
'************************************************************************************************''''''''''''''
'''''FloodedRange計算洪水淹沒范圍
'************************************************************************************************''''''''''''''
Public Sub FloodedRange(pApp As IApplication, Optional ByRef pSdeFWS As IWorkspace = Nothing)
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 "放棄淹沒范圍計算"
GoTo errHandle
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 Sub 'exit sub to avoid error handler
errHandle:
MsgBox "計算淹沒范圍失敗" & Chr(13) & ERR.Description, vbInformation + vbOKOnly, "提示信息"
End Sub
'************************************************************************************************''''''''''''''
'''''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) '創(chuàng)建一個洪水淹沒矢量圖斑
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創(chuàng)建一個多邊形文件
'************************************************************************************************''''''''''''''
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
Set pFieldEdit = pField
pFieldEdit.name = strShapeFieldName
pFieldEdit.Type = esriFieldTypeGeometry
Dim pGeomDef As IGeometryDef
Dim pGeomDefEdit As IGeometryDefEdit
Set pGeomDef = New GeometryDef
Set pGeomDefEdit = pGeomDef
With pGeomDefEdit
.GeometryType = esriGeometryPolygon
Set .SpatialReference = spatialRef 'New UnknownCoordinateSystem
End With
Set pFieldEdit.GeometryDef = pGeomDef
pFieldsEdit.AddField pField
Set pField = New esriCore.Field
Set pFieldEdit = pField
With pFieldEdit
.Length = 30
.name = "MiscText"
.Type = esriFieldTypeString
End With
pFieldsEdit.AddField pField
' Create the shapefile
Dim pFeatClass As IFeatureClass
Set pFeatClass = pShapeWsF.CreateFeatureClass(strShapeName, pFields, Nothing, _
Nothing, esriFTSimple, strShapeFieldName, "")
Set CreateShapefile = pFeatClass
Set pFields = Nothing
Set pField = Nothing
Set pGeomDef = Nothing
Exit Function
Errhdr:
MsgBox "創(chuàng)建shape文件失敗" & Chr(13) & ERR.Description, vbInformation + vbOKOnly, "提示信息"
End Function
'************************************************************************************************''''''''''''''
'''''CreateFeature根據(jù)給定幾何體特征創(chuàng)建一個空間特征體
'************************************************************************************************''''''''''''''
Private Sub CreateFeature(pFeatureClass As IFeatureClass, pGeometry As IGeometry)
Dim pFeature As IFeature
Set pFeature = pFeatureClass.CreateFeature
Set pFeature.Shape = pGeometry
pFeature.Store
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -