原理:
利用圖斑最小外包矩形的左上角坐標(數(shù)學坐標)Y坐標將序、X坐標升序的方式獲取自上而下,從左到右的要素記錄排序,然后遍歷編號。
"!shape.extent.xmin!"計算要素最小外包矩形的左上角X坐標;
"!shape.extent.ymax!" 計算要素最小外包矩形的左上角Y坐標;
字段計算器中可做Python腳本表達式用,Arcpy中其類型為Python_9.3,在“解析ArcGis字段計算器”相關(guān)博文中,已對上面代碼信息進行過說明。
代碼如下:
#要素類路徑fcpath="C:/Users/Administrator/Desktop/shp/demo.shp"#新建Ymax/Xmin兩個字段,分別計算圖斑最小外包矩形的左上角Y、X坐標(數(shù)學坐標)arcpy.AddField_management(fcpath,"Xmin","DOUBLE")arcpy.AddField_management(fcpath,"Ymax","DOUBLE")#字段計算,計算坐標,計算表達式類型為Python_9.3arcpy.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:975601416for row in rows: row.setValue("BSM",i+1) #BSM字段(整型)存放編號,每迭代一次+1 rows.updateRow(row) i+=1arcpy.DeleteField_management(fcpath,"Xmin;Ymax")