【ArcGIS Pro二次开发】(18):地理处理工具类【Geoprocessing】补遗

本文详细介绍了ArcGISProSDK3.0中Geoprocessing类的关键方法,如MakeValueArray用于创建参数数组,ExecuteToolAsync用于异步执行地理处理工具,以及GPExecuteToolFlags参数设置。文章还提到了ShowMessageBox和OpenToolDialogAsync方法,分别用于显示GP工具消息和打开参数对话框,提供更丰富的用户交互体验。
摘要由CSDN通过智能技术生成

ArcGIS Pro SDK 3.0中的Geoprocessing类是用于执行地理处理工具的核心类。地理处理工具是用于执行空间分析、数据转换、数据管理等任务的工具集,包括常见的空间分析工具、栅格处理工具、矢量处理工具、地图制图工具等。

之前有简单记录了下Geoprocessing工具的用法:

【ArcGIS Pro二次开发】(9):GeoProcessing工具和自定义工具的调用

最近在使用过程中发现遗漏了不少东西,再次记录,方便查阅。

这次主要记录Geoprocessing的主要方法和参数的使用。


一、【MakeValueArray】方法

MakeValueArray方法用于创建一个GPValue数组,传递多个参数给地理处理工具。

var parameters = Geoprocessing.MakeValueArray(ly, null, @"100 Meters",null,null, "ALL");

参数的类型和数量根据你所要执行的GP工具而定。


二、【ExecuteToolAsync】方法

ExecuteToolAsync是一个异步方法,用于执行地理处理工具。

IGPResult result = await Geoprocessing.ExecuteToolAsync("Buffer_analysis", parameters, null, null, null, executeFlags);

ExecuteToolAsync方法的参数如下:

参数1:要执行的地理处理工具的名称,例如上面的“Buffer_analysis”指的是【缓冲区】工具。

参数2:即上面【MakeValueArray】方法创建的参数数组,参数名称和值的类型必须与地理处理工具的要求相匹配。

参数3:environments。用于设置地理处理工具的环境变量。一般不需要设置环境变量,默认设置为null。

如果需要设置的话,可以通过【MakeEnvironmentArray】来创建:

var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true , extent: "460532 3773964 525111 3827494");

如上所示,设置了2个参数:【overwriteoutput】输出是否覆盖、【extent】范围。

参数4: cancelToken。用于取消地理处理工具的执行。如果不需要取消功能,一般就默认设置为null。

参数5:callback。一个GPToolExecuteEventHandler接口,说实话我也不知道有啥用,默认设置为null。

参数6:executeFlags。用于设置工具的执行参数,下面会重点讲。

以上6个参数,一般情况下注意设置1,2,6这3个参数,另3个基本都是设为null。


三、【GPExecuteToolFlags】参数

GPExecuteToolFlags是工具的一组参数设置,用于指定地理处理工具应怎么执行。

GPExecuteToolFlags executeFlags = GPExecuteToolFlags.RefreshProjectItems | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory | GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.InheritGPOptions;

上面列出了GPExecuteToolFlags的5个主要参数设置:

1、【RefreshProjectItems】

用于在地理处理工具执行后刷新地图项目,如果工具执行后对要素存在修改,建议设置刷新。

2、【GPThread】

用于指定在执行地理处理工具时是否使用新线程。使用新线程可以避免主线程阻塞并提高程序响应速度,但也可能导致内存使用过高和线程冲突等问题。建议正常情况下还是先不用。

3、【AddToHistory】

指定执行结果将添加到历史记录中。这对于用户需要追踪之前的地理处理操作非常有用。建议打开。

4、【AddOutputsToMap】

工具执行结果添加到当前地图中。这点可根据需要选择,最终结果数据可以添加显示,但是如果是中间数据,则可以不显示。我在之前做的一个拓扑工具就因为没有设置,致使中间数据添加到当前地图中,显得很乱。

5、【InheritGPOptions】

用于指定是否继承执行地理处理工具的GP选项。例如,如果当前GP环境设置了输出坐标系、Z值和M值,那么在执行地理处理工具时,这些设置将被继承并应用于工具的输出。一般情况下,我是不会去设置GP环境,所以这个Flag也不会去用。


四、【ShowMessageBox】方法

这里的Geoprocessing.ShowMessageBox,和一般的MessageBox不同,是专门针对GP工具的消息框,感觉更好用一些。

Geoprocessing.ShowMessageBox(toolResult.Messages, "GP Messages", toolResult.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);

窗口界面如下:


五、【OpenToolDialogAsync】方法

Geoprocessing.OpenToolDialogAsync方法用于打开地理处理工具的参数对话框,以便用户可以手动输入参数值。该方法通常用于需要用户自定义参数值的情况,例如需要使用用户指定的文件路径、日期等。这个方法主要是实现用户交互,如果需要用户手动输入参数值,用这个比较合适。不过感觉到目前为止,都还想不到什么地方会用到它。


以上就是本次补遗的内容。现在回头看之前的文章,还是挺乱的,有很多疏漏。

现在是初学的积累阶段,等以后再好好整理吧。

Although I’d taken a lot of programming classes in college, I never fully appreciated programming until I had a job that involved a lot of repetitive tasks. After amusing myself by automating much of that job, I decided to return to school and study biol- ogy, which is when I took my first GIS course. I was instantly in love, and managed to convince someone to give me a biology degree for writing an extension for ArcView GIS (a precursor to A rc GIS , for you Esri fans out there). After finishing that up, I went to work for the Remote Sensing/Geographic Information Systems Laboratory at Utah State University. One of my first projects involved some web mapping, and I soon became a big fan of the open source UMN M ap S erver software. That was my introduc- tion to open source geospatial software, including GDAL . I’m fairly certain that I didn’t appreciate the power of the GDAL/OGR library when I first learned about it, but I came to my senses once I started using it in my C++ and C# code. In the College of Natural Resources, there weren’t many people around who were interested in coding, but I did get to point people to the GDAL command-line utilities on a regular basis. But then Esri introduced Python as the scripting language of choice for A rc GIS , and things started to change. I don’t think I had used Python much before then, but playing with arcgisscripting (the original Esri Python module) made me realize how much I enjoyed working with Python, so naturally I had to start using GDAL with it as well. More importantly for this book, my coworker John Lowry suggested that we team- teach a Python-for- GIS class. He taught students how to use Python with A rc GIS , and I taught them about GDAL . The class turned out to be popular, so we taught it that way for another few years until John moved away. I took over the entire class and have been teaching it in various configurations ever since. I’ve never bothered to take the class material from the first two years off the web, however, which is how Manning found me. They asked if I would write a book on using GDAL with Python. I’d never had the desire to write a book, so it took a bit of persuasion to convince me to do it. In the end, it was my love for teaching that won me over. I’ve discovered over the years that I really enjoy teaching, mostly because I love watching students incorporate what they’re learning into the rest of their work. This is especially true of graduate students, some of whom might not have completed their research in a timely manner (or at all) if they hadn’t learned how to write code. I know that these skills will continue to assist them throughout their careers, and my hope is that this book will provide the same help to you, no matter if you’re a student, professional, or a hobbyist. This is fun stuff, and I hope you enjoy it as much as I do!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

规划GIS会

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值