新增字段值

2021-09-24 02:39:03 字數 3109 閱讀 2114

import arcpy

from arcpy import da

from arcpy import env

path=''

env.workspace=path

fc='bjgreendupli_prj.shp'

mplst=

namelst=

for row in da.searchcursor(fc,['name','area','shape@']):

if row[0][-3:]=='sea':

print('area is'+str(row[1]))

seam='seam.shp'

arcpy.createfeatureclass_management(path,seam,'polygon','','','',fc)

arcpy.addfield_management(seam,'name','text')

cursor=da.insercursor(seam,['shape@','name'])

for n in range(len(mplst)):

cursor.insertrow([mplst[n],namelst[n]])

del cursor

#使用sql語句查詢條件下子集

import arcpy

from arcpy import env

path=''

env.workspace=path

env.overwriteoutput=true

fc='seam'

fieldname1='area'

fieldname2='length'

arcpy.addfield_management(fc,fieldname1,'float')

arcpy.addfield_management(fc,fieldname2,'float')

arealst=

lengthlst=

for row in arcpy.da.searchcursor(fc,['shape@area','shape@length']):

cursor=arcpy.da.updatecursor(fc,['area','length'])

n=0for row in cursor:

row[0]=arealst[n]

row[1]=lengthlst[n]

cursor.updaterow(row)

del cursor,row

c=arcpy.da.searchcursor(fc,('length','name'),""""length"<2000""")

#多欄位可以是列表或組,三重引號

for row in c:

print('%s\'length is %s'%(str(row[1]),str(row[0])))

#sql表示式

whereclause="""%s<2000""" % arcpy.addfielddelimiters(fc,'length')

#在欄位名稱中新增字段分隔符,以便在 sql 表示式中使用。

#計算指數

import arcpy,math

from arcpy import env

path=''

env.workspace=path

env.overwriteoutput=true

sea='seam.shp'

seag=arcpy.copyfeatures_management(sea,arcpy.geometry())#複製要素到arcpy.geometry()

#返回幾何部分列表

np='np'#斑塊數目

te='te'#邊界總長度

ed='ed'#邊界密度

lpi='lpi'#最大斑塊指數

mps='mps'#平均斑塊面積

par='par'#周長面積比

c='c'#形狀指數

arcpy.addfield_management(sea,np,'float')

arcpy.addfield_management(sea,te,'float')

arcpy.addfield_management(sea,ed,'float')

arcpy.addfield_management(sea,lpi,'float')

arcpy.addfield_management(sea,mps,'float')

arcpy.addfield_management(sea,par,'float')

arcpy.addfield_management(sea,c,'float')

arealst=

lengthlst=

namelst=

for row in arcpy.da.searchcursor(sea,['shape@area','shape@length','name']):

print(arealst,lengthlst)

cursor=arcpy.da.updatecursor(sea,['np','te','ed','lpi','mps','par','c','name'])

n=0for row in cursor:

row[0]=len(seag)

row[1]=sum(lengthlst)

row[2]=sum(lengthlst)/sum(arealst)*pow(10,6)

if row[-1]==namelst[arealst.index(max(arealst))]:

row[3]=max(arealst)/sum(arealst)*100

else:

row[3]=0

row[4]=sum(arealst)/len(seag)

row[5]=lengthlst[n]/arealst[n]

row[6]=math.sqrt(arealst[n]/lengthlst[n])

cursor.updaterow(row)

n=n+1

del cursor,row

seag=arcpy.copyfeatures_management(sea,arcpy.geometry())#複製要素到arcpy.geometry()

mysql 新增字段 MySql新增字段命令

mysql 新增字段 alter table t user add column user age int 11 default null comment 年齡 after user email mysql 修改字段 alter table user10 modify email varchar 2...

ORACLE新增字段 刪除字段

1.刪除表 drop table sys job 2.建立表 create table create table sys job job id number 30 not null,job name varchar2 30 not null alter table sys job addconstr...

Mysql 新增字段 修改字段 刪除字段

alter table 表名 add 欄位名 字段型別 字段長度 default 預設值 comment 注釋 例如 alter table order add code char 6 default null comment 優惠碼 2 修改字段 修改欄位名 字段型別 長度 a 修改欄位名 alt...