import arcpy fc = arcpy.GetParameterAsText(0) field = arcpy.GetParameterAsText(1) value = arcpy.GetParameterAsText(2) query = "{} = '{}'".format(arcpy.AddFieldDelimiters(fc, field), value) with arcpy.da.UpdateCursor(fc, ["OID@", field], where_clause=query) as cursor: for row in cursor: cursor.deleteRow() arcpy.AddMessage("Deleted OID {} with {} = {}".format(row[0], field, value))运行错误:Traceback (most recent call last): File "D:\多对一空间连接\批量删除小面积.py", line 10, in <module> RuntimeError: 使用了无效的 SQL 语句。 [大面大面] 执行(删除小面)失败。
时间: 2023-12-13 08:03:16 浏览: 24
这个错误可能是由于 SQL 查询语句没有正确构造造成的。你可以尝试打印一下 SQL 查询语句,然后在数据库中执行该语句,看看是否有效。
你可以修改代码,在 `query` 变量的赋值语句后面添加一行代码,如下所示:
```python
query = "{} = '{}'".format(arcpy.AddFieldDelimiters(fc, field), value)
print(query) # 打印 SQL 查询语句
```
然后运行脚本,查看打印出来的 SQL 查询语句是否正确。如果 SQL 查询语句正确,你可以将该语句复制到数据库工具中,执行该语句,看看是否能够正确删除记录。如果 SQL 查询语句不正确,你需要检查输入参数是否正确,或者修改 SQL 查询语句的构造方法。
相关问题
input_features = arcpy.GetParameterAsText(0) join_field = arcpy.GetParameterAsText(1) target_feature = arcpy.GetParameterAsText(2) target_field = arcpy.GetParameterAsText(3) area_threshold = arcpy.GetParameterAsText(4)arcpy.CopyFeatures_management(target_feature, arcpy.GetParameterAsText(5))分别是什么意思
这段代码是用来获取工具参数并对数据进行复制的。具体解释如下:
- `input_features`:一个要素类或要素图层,作为加入操作的输入要素。
- `join_field`:用来将输入要素与目标要素类/图层连接的字段。
- `target_feature`:要连接到输入要素的要素类或要素图层。
- `target_field`:用来将目标要素与输入要素连接的字段。
- `area_threshold`:指定连接的最小面积阈值(可选参数)。
- `arcpy.CopyFeatures_management(target_feature, arcpy.GetParameterAsText(5))`:将目标要素类或图层复制到输出要素类或图层中。`arcpy.GetParameterAsText(5)`是用来获取输出要素类的参数。
简而言之,这段代码是用来将两个要素类或图层连接起来,并将结果复制到输出要素类或图层中。
rasterFolder=arcpy.GetParameterAsText(0) newRasterName=arcpy.GetParameterAsText(1) coordinateSystem=arcpy.GetParameterAsText(2) pixelType=arcpy.GetParameterAsText(3) cellSize=arcpy.GetParameterAsText(4) numberOfBands=arcpy.GetParameterAsText(5) mosaicMethod=arcpy.GetParameterAsText(6) mosaicColormapMode=arcpy.GetParameterAsText(7)
这段代码是用于从 ArcGIS 工具箱中获取用户输入的参数值,并将这些参数值分别存储在变量中。具体来说,这些参数值包括:
1. rasterFolder:栅格图像所在文件夹的路径。
2. newRasterName:新栅格图像的名称。
3. coordinateSystem:新栅格图像的坐标系。
4. pixelType:新栅格图像的像素类型。
5. cellSize:新栅格图像的像元大小。
6. numberOfBands:新栅格图像的波段数。
7. mosaicMethod:新栅格图像的拼接方法。
8. mosaicColormapMode:新栅格图像的颜色映射模式。
这些参数值将在后续的代码中被用来指定栅格图像拼接的方式、创建新栅格图像的属性等。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)