<< Click to Display Table of Contents >>

 

UpdateCursor

 

用於更新資料到feature Class 或table資料, 此方法會先從資料集中取得更新資料用Cursor, 之後透過迴圈循環的方式, 逐一取得feature Class資料的row data, 來更新每筆資料的屬性值。

 

語法:

UpdateCursor (dataset, where_clause)

參數

說明

參數類型

datase

資料集,可以是feature class

shp檔或是geo檔案

字串

where_clause

(可給或不給)

查詢條件,用於篩選出符合特定條件的資料,作為待更新資料, 若不指定,則回傳所有的資料, 作為待更新資料

字串

回傳值

類型

說明

Cursor

Cursor物件, 可用來對feature class中的資料進行更新

範例:

import sgpy

# 建立更新資料用Cursor

rows = sgpy.UpdateCursor("D:/temp/Line2.shp", where_clause="prop2 = 'abc'")

for row in rows:

   #取得特定欄位的資料,經計算後,將結果寫入特定欄位中

   row.setValue("prop1", row.getValue("prop2")+ "a")

   rows.updateRow(row) #對資料進行更新

   del row

del rows

 


©2015 Supergeo Technologies Inc. All rights reserved.