如下是正文:html
原理:工具
利用圖斑最小外包矩形的左上角座標(數學座標)Y座標將序、X座標升序的方式獲取自上而下,從左到右的要素記錄排序,而後遍歷編號。學習
"!shape.extent.xmin!"計算要素最小外包矩形的左上角X座標;spa
"!shape.extent.ymax!" 計算要素最小外包矩形的左上角Y座標;code
字段計算器中可作Python腳本表達式用,Arcpy中其類型爲Python_9.3,在「解析ArcGis字段計算器」相關博文中,已對上面代碼信息進行過說明。htm
代碼以下:blog
#要素類路徑 fcpath="C:/Users/Administrator/Desktop/shp/demo.shp" #新建Ymax/Xmin兩個字段,分別計算圖斑最小外包矩形的左上角Y、X座標(數學座標) arcpy.AddField_management(fcpath,"Xmin","DOUBLE") arcpy.AddField_management(fcpath,"Ymax","DOUBLE") #字段計算,計算座標,計算表達式類型爲Python_9.3 arcpy.CalculateField_management(fcpath,"Xmin","!shape.extent.xmin!","PYTHON_9.3") arcpy.CalculateField_management(fcpath,"Ymax","!shape.extent.ymax!","PYTHON_9.3") #迭代更新遊標,"Ymax D;Xmin A" 意爲Ymax字段將序,Xmin字段升序 rows=arcpy.UpdateCursor(fcpath,"","","","Ymax D;Xmin A") i=0 #code source: https://www.cnblogs.com/yzhyingcool/ QQ:975601416 for row in rows: row.setValue("BSM",i+1) #BSM字段(整型)存放編號,每迭代一次+1 rows.updateRow(row) i+=1
del row
del rows arcpy.DeleteField_management(fcpath,"Xmin;Ymax")