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

来源:互联网 发布:随机红包生成算法 编辑:程序博客网 时间:2024/04/29 11:01

在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