import arcpy import sys # 设置输入参数 input_features = arcpy.GetParameterAsText(0) # 输入要素类 output_features = arcpy.GetParameterAsText(1) # 输出要素类 minimum_area = arcpy.GetParameterAsText(2) # 面积阈值,单位为平方米 # 将面积阈值转换为浮点型 try: minimum_area = float(minimum_area) except ValueError: arcpy.AddError("面积阈值必须为数字!") sys.exit() # 创建要素图层并添加要素 arcpy.MakeFeatureLayer_management(input_features, "input_layer") arcpy.SelectLayerByAttribute_management("input_layer", "NEW_SELECTION", "Shape_Area < {}".format(minimum_area)) arcpy.CopyFeatures_management("input_layer", output_features) # 输出结果 arcpy.SetParameterAsText(3, output_features)运行错误:IndentationError: unexpected indent (批量删除小面积.py, line 8) 执行(删除小面)失败。请改正代码
时间: 2024-01-21 21:16:24 浏览: 75
这个错误是由于代码的缩进不正确导致的,建议按照以下方式修改代码:
```python
import arcpy
import sys
# 设置输入参数
input_features = arcpy.GetParameterAsText(0)
# 输入要素类
output_features = arcpy.GetParameterAsText(1)
# 输出要素类
minimum_area = arcpy.GetParameterAsText(2)
# 面积阈值,单位为平方米
# 将面积阈值转换为浮点型
try:
minimum_area = float(minimum_area)
except ValueError:
arcpy.AddError("面积阈值必须为数字!")
sys.exit()
# 创建要素图层并添加要素
arcpy.MakeFeatureLayer_management(input_features, "input_layer")
arcpy.SelectLayerByAttribute_management("input_layer", "NEW_SELECTION", "Shape_Area < {}".format(minimum_area))
arcpy.CopyFeatures_management("input_layer", output_features)
# 输出结果
arcpy.SetParameterAsText(3, output_features)
```
这样就可以避免缩进错误了。
阅读全文