• GeoProcessing中通过GP.GetMessage(2)捕捉异常


    Sub MappingFields()

    On Error GoTo EH:

      '//initialize license
      Dim aoi As IAoInitialize
      Set aoi = New AoInitialize
      aoi.Initialize esriLicenseProductCodeArcInfo
     
      Dim GP As IGeoProcessor
      Set GP = New GeoProcessor
      GP.OverwriteOutput = True

      Dim strTableA As String
      strTableA = "C:"Temp"VBTests"FieldMapping"citiblocks.gdb"census"
     
      Dim pDataElement As IDataElement
      Dim pDETableA As IDETable
     
      Dim pGPU As IGPUtilities
      Set pGPU = New GPUtilities
     
      Set pDataElement = pGPU.MakeDataElement(strTableA, Nothing, Nothing)
      Set pDETableA = pDataElement
     
      Dim pArray As IArray
      Set pArray = New esriSystem.Array
      pArray.Add pDETableA
     
      Dim pFieldMapping As IGPFieldMapping
      Set pFieldMapping = New GPFieldMapping
      '** initialize the field mapping
      pFieldMapping.Initialize pArray, Nothing
     
      '** create a new output field
      Dim TrackIDField As IFieldEdit
      Set TrackIDField = New Field
      TrackIDField.Name = "TRACTID"
      TrackIDField.Type = esriFieldType.esriFieldTypeString
      TrackIDField.Length = 20

      '** create a new FieldMap
      Dim TrackID As IGPFieldMap
      Set TrackID = New GPFieldMap
      Set TrackID.OutputField = TrackIDField
      
      '** find field map STFID containing the input field STFID
      Dim FieldMap_Index As Long, Field_Index As Long
      FieldMap_Index = pFieldMapping.FindFieldMap("STFID")
     
      Dim STFID_FieldMap As IGPFieldMap
      Set STFID_FieldMap = pFieldMapping.GetFieldMap(FieldMap_Index)
     
      Field_Index = STFID_FieldMap.FindInputField(pDETableA, "STFID")
     
      Dim inputField As IField
      Set inputField = STFID_FieldMap.GetField(Field_Index)
     
      TrackID.AddInputField pDETableA, inputField, 5, 10  'starPos, endPos
      '** add the new field map to the field mapping
      pFieldMapping.AddFieldMap TrackID
     
      '** execute Table to Table tool using the FieldMapping
      Dim pParameters As IVariantArray
      Set pParameters = New varArray
      pParameters.Add (strTableA)
      pParameters.Add ("C:"Temp"VBTests"FieldMapping"citiblocks.gdb")
      pParameters.Add "census3"
      pParameters.Add ""
      pParameters.Add pFieldMapping
      GP.Execute "TableToTable_conversion", pParameters, Nothing
      Debug.Print GP.GetMessages(0)
      Exit Sub

    EH:
      Debug.Print GP.GetMessages(2)

    End Sub

     
  • 相关阅读:
    那是什么进程 —— svchost.exe是什么? 它为何运行?
    共享一下我的博客皮肤
    C#3.0亮点 —— 关键字var和匿名类型
    改善代码设计 —— 优化物件之间的特性(Moving Features Between Objects)
    C#3.0亮点 —— 分部方法
    解决C#中一个"异步方法却同步执行"的问题
    改善代码设计 —— 简化函数调用(Making Method Calls Simpler)
    改善代码设计 —— 总结篇(Summary)
    理解A*寻路算法具体过程
    改善代码设计 —— 组织好你的数据(Composing Data)
  • 原文地址:https://www.cnblogs.com/flyingfish/p/1081372.html
Copyright © 2020-2023  润新知