游标查询
游标操作
定义环境
# 设置工作空间
workspace = r'D:\CPS\MyProject\gis\learn\shp'
# 要读取的shp/对象
point = r"test_point.shp"
# 要查询的关键词,可以不指定
fields = ["FID","NEAR_DIST"]
主要api
arcpy.SearchCursor()
- 返回迭代器,元素是对象,需要使用
getValue()
配合isNull()
来获取数据 - 不能使用
with
# 返回 Cursor 对象
with arcpy.da.SearchCursor(point,fields) as cursors:
for each in cursors:
# 查询某个字段
print(each.)- 返回迭代器,元素是对象,需要使用
arcpy.da.SearchCursor()
- 返回迭代器, 元素是
turple
,通过下标获取数据,数据对应请求字段 - 可以使用
with
# 返回turple
with arcpy.da.SearchCursor(point,fields) as cursors:
for each in cursors:
# 查询某个字段
print(each[0])- 返回迭代器, 元素是