运行上面代码:Traceback (most recent call last): File "D:\实验2\空间连接.py", line 13, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\analysis.py", line 84, in Select raise e ExecuteError: ERROR 000358: 无效的表达式 Shape_Area > 600 SquareMeters 执行(Select)失败。 执行(fzzz)失败。请按错误原因改正上面代码并写出可复制的完整代码
时间: 2023-09-10 19:09:00 浏览: 298
根据错误提示,表达式 "Shape_Area > 600 SquareMeters" 无效,应该修改为 "Shape_Area > 600",并且在代码中加入连接空间数据库的代码。以下是修改后的可复制的完整代码:
```python
import arcpy
# 连接空间数据库
arcpy.env.workspace = r"C:\data\mydb.sde"
# 设置输入和输出图层
input_layer = "parcels"
output_layer = "large_parcels"
# 创建查询表达式
query_expression = "Shape_Area > 600"
# 进行选择
try:
arcpy.Select_analysis(input_layer, output_layer, query_expression)
print("选择成功!")
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
```
相关问题
运行上面代码出现错误:Traceback (most recent call last): File "D:\实验2\空间连接.py", line 12, in <module> NameError: name 'output_features' is not defined 执行(ccc)失败。请改正上面代码
这个错误提示说`output_features`没有定义,可能是你在代码中没有定义这个变量。你需要检查一下你的代码,确保你已经定义了这个变量,并且没有拼写错误。
如果你不确定如何定义这个变量,可以查看代码中是否有类似于`output_features = 768`这样的语句。如果没有,你需要添加这个语句并赋一个值给`output_features`变量,例如:`output_features = 1024`。如果你已经定义了这个变量,那么可能是因为变量名没有正确地引用或者在变量定义前被使用了导致的问题。
上面代码运行错误:Traceback (most recent call last): File "D:\实验\一键删除所有字段.py", line 6, in <module> NameError: name 'fc' is not defined 执行(脚本1)失败。请改正上面代码
这个错误是因为脚本中的变量 "fc" 没有被定义。您需要使用 `arcpy.GetParameterAsText()` 函数从工具箱参数中获取要素类的路径,然后将其赋值给 "fc" 变量。
以下是可以在 ArcGIS 10.2.2 工具箱中使用的 Python 2.7 脚本代码,可以一键删除所有字段:
```python
import arcpy
# 从工具参数中获取要素类路径
fc = arcpy.GetParameterAsText(0)
# 获取所有字段的列表
fields = arcpy.ListFields(fc)
# 循环删除每个字段
for field in fields:
arcpy.DeleteField_management(fc, field.name)
```
请注意,此代码将删除要素类中的所有字段,包括要素类的标识字段和几何字段。如果您只想删除自定义字段,请修改代码以排除这些字段。
同时,您需要在工具箱中创建一个参数,类型为“要素类”,名称为“Input Feature Class”,并将其添加到脚本工具中。这样,您就可以将要素类路径传递到脚本中,并成功删除所有字段。
阅读全文
相关推荐

















