在arcmap+vba中使用arcgis中的toolbox中的工具

在VBA中或者VB中用IGeoProcessor接口中的Execute方法可以調用arcgis中所有Toolbox工具。
GP.Execute的命令名稱格式如下:“工具名稱(toolbox中的名稱)”+下劃線+所在工具集的假名。如“MosaicToNewRaster_management”
下面例子中調用了MosaicToNewRaster工具--鑲嵌柵格數據
Set GP = New GeoProcessor
        Set VA = New VarArray
        GP.OverwriteOutput = True
            outputPath = Left(ListBox.List(i), Len(ListBox.List(i)) - 1)
            tmpNum = InStrRev(outputPath, "\", -1, vbTextCompare)
            mytmpname = Right(outputPath, Len(ListBox.List(i)) - tmpNum - 1)

        VA.Add inputPath
        VA.Add outputPath
        VA.Add tifName
        VA.Add "#"
        VA.Add "8_BIT_UNSIGNED"
        VA.Add "#"
        VA.Add "3"
        VA.Add "LAST"
        VA.Add "FIRST"
       
        GP.Execute "MosaicToNewRaster_management", VA, Nothing

'===初始化GeoProcessor

Dim GP As IGeoProcessor
Set GP = New GeoProcessor

'===輸出時覆蓋同名文件
GP.OverwriteOutput = True

'//Declare 3 variables for input and output parameters
Dim inputPath As String
Dim outputPath As String
Dim tifName As String

'//定義參數
inputPath = "D:\TEST\Input1.TIF;D:\TEST\Input2.TIF"
outputPath = "D:\TEST"
tifName = "MOS.tif"

'//設置變量數組
Dim VA As IVariantArray

Set VA = New VarArray
    VA.Add inputPath ’==輸入的柵格文件
    VA.Add outputPath ’==鑲嵌後輸出的柵格文件路徑
    VA.Add tifName ’==鑲嵌後的文件名
    VA.Add "#" ’==定義座標系統
    VA.Add "8_BIT_UNSIGNED" ’==輸出的位數
    VA.Add "#" ’==單元格大小
    VA.Add "3"’===波段
    VA.Add "LAST"   ’ ===重疊區域處理方法
    VA.Add "FIRST" ’ ===色帶處理方法

'=====執行工具

 GP.Execute "MosaicToNewRaster_management", VA, Nothing


下面是常用的工具名稱及假名

1. Analysis Tools— analysis
2. Conversion Tools— conversion
3. Data Management Tools— management
4. 3D Analyst Tools— 3d
5. Cartography Tools— cartography
6. Geocoding Tools— geocoding
7. Geostatistical Analyst Tools— ga
8. Linear Referencing Tools— lr
9. Multidimension Tools— md
10. Network Analyst Tools— na
11. Samples— samples
12. Spatial Analyst Tools— sa
13. Spatial Statistics Tools— stats
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章