ArcGIS ArcPy Python处理数据
2024-08-30 00:50:46
1、使用搜索游标查看行中的字段值。
import arcpy
# Set the workspace
arcpy.env.workspace = "c:/base/data.gdb"
# Create the search cursor
cursor = arcpy.SearchCursor("roads", '"TYPE" <> 4')
# Iterate through the rows in the cursor
for row in cursor:
print("Name: {0}, CFCC code: {1}".format(row.NAME, row.CFCC))
del cursor, row
2、使用更新游标更改行中的字段值。
import arcpy
# Set the workspace
arcpy.env.workspace = "c:/base/data.gdb"
# Create the update cursor
cursor = arcpy.UpdateCursor("roads")
# Update the road buffer distance field based on road type.
# Road type is either 1,2,3,4 Distance is in meters.
for row in cursor:
row.setValue("BUFFER_DIST", row.getValue("TYPE") * 100)
cursor.updateRow(row)
# Delete cursor and row objects
del cursor, row
3、使用插入游标在表中新建行。
import datetime
import arcpy
# Create insert cursor for table
cursor = arcpy.InsertCursor("c:/base/data.gdb/roads_maint")
# Create 25 new rows. Set default values on distance and CFCC code
for i in range(1000, 1025):
row = cursor.newRow()
row.setValue('rowid', i)
row.setValue('distance', 100)
row.setValue('CFCC', 'A10')
row.setValue('LastInsp', datetime.datetime.now())
cursor.insertRow(row)
# Delete cursor and row objects
del cursor, row
4、删除记录
with arcpy.da.Editor(arcpy.env.workspace) as edit:
with arcpy.da.UpdateCursor(layerName, ["GB"], 'GB not in (' + layerCodes + ')') as cursor:
for row in cursor:
print("GB Code: {0}".format(row[0]))
cursor.deleteRow()
最新文章
- 【C语言入门教程】3.1 程序的 3 种基本结构
- Java项目相关监控与调优
- [译]SQL Server 之 查询计划的简单参数化
- 堆(heap)和栈(stack)的区别
- rank() over(partition)的使用
- 专题一、ArrayList增删操作技术细节详解
- python消息队列snakemq使用总结
- Linux的rp_filter与策略路由
- tensorflow中moving average的用法
- 2、使用Angular-CLI初始化Angular项目(踩过的深坑!!!)
- HTTP请求行、请求头、请求体详解(转)
- Linux下OSG的编译和安装以及遇到的问题
- ExtJS5入门
- Alan Cox:单向链表中prev指针的妙用
- js生成二维码实例
- 解决VMware安装Ubuntu的过程中窗口过小无法看到按钮的问题
- visual studio 2010 winform程序不能添加对system.web的引用
- SpringBoot与Dubbo整合上篇
- PHP安全性考虑
- POJ 2184 Cow Exhabition