arcgis python工具箱代码
时间: 2023-07-02 11:10:21 浏览: 84
以下是一个简单的 ArcGIS Python 工具箱代码示例,它将缓冲区分析应用于输入要素类:
```python
import arcpy
class BufferAnalysis(object):
def __init__(self):
self.label = "Buffer Analysis"
self.description = "Applies buffer analysis to input feature class"
self.canRunInBackground = False
def getParameterInfo(self):
input_fc = arcpy.Parameter(
displayName="Input Feature Class",
name="input_fc",
datatype="DEFeatureClass",
parameterType="Required",
direction="Input")
buffer_distance = arcpy.Parameter(
displayName="Buffer Distance",
name="buffer_distance",
datatype="LinearUnit",
parameterType="Required",
direction="Input")
output_fc = arcpy.Parameter(
displayName="Output Feature Class",
name="output_fc",
datatype="DEFeatureClass",
parameterType="Required",
direction="Output")
return [input_fc, buffer_distance, output_fc]
def execute(self, parameters, messages):
input_fc = parameters[0].valueAsText
buffer_distance = parameters[1].valueAsText
output_fc = parameters[2].valueAsText
arcpy.Buffer_analysis(input_fc, output_fc, buffer_distance)
messages.addMessage("Buffer analysis completed successfully.")
return
```
在此示例中,我们定义了一个名为 `BufferAnalysis` 的类,它包含工具箱的标签、描述和参数信息。 `getParameterInfo` 方法返回一个包含工具箱参数的列表。 `execute` 方法以参数作为输入并执行缓冲区分析,最后输出一条成功消息。
阅读全文