pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
一.GDB数据库相关
1.单独的shape更新时,不会有限制,数据会自动截取
2.在GDB下,使用UpdateCursor更新字段时,填入的数据长度必须与字段长度要求一致,否则报错:
二.Cursor相关
嵌套使用cursor时,第二个cursor要使用reset()
def fieldFuncInGDB(pointFile,polygonFile):
"""
:param pointFile: 点文件
:param polygonFile: 面文件
:return: 将点所在的面的字段属性复制到点的相应字段,类似空间连接
"""
i=1
cs1 = arcpy.da.UpdateCursor(pointFile, ["SHAPE@","XZQDM","XZQMC"])
cs2 = arcpy.da.SearchCursor(polygonFile, ["SHAPE@", "XZQDM", "XZQMC"])
for row1 in cs1:
for row2 in cs2:
if row2[0].contains(row1[0]):
row1[1] = row2[1][0:12]
row1[2] = row2[2]
print i, row2[1][0:12], row2[2]
i += 1
cs2.reset()#++++++++++++++++++++++++++++++必须reset!!!!!
cs1.updateRow(row1)
三.根据表格创建point
#coding=utf-8
import arcpy
arcpy.env.overwriteOutput = True
import pandas as pd
xlFile = r'E:\test\1.xlsx'
fileSavePath = r'E:\test'
df = pd.read_excel(xlFile.decode('utf-8'))
CNList = []
for index,value in df.iterrows():
CNList.append(value.values)
l1 = df.columns.values.tolist()
l1_Coded = []
for field in l1:
l1_Coded.append(field.encode('utf-8'))
l1_Coded[l1_Coded.index('x')]='SHAPE@X'
l1_Coded[l1_Coded.index('y')]='SHAPE@Y'
l2 = df.columns.values.tolist()
l2.remove('x')
l2.remove('y')
l2_Coded = []
for field in l2:
l2_Coded.append(field.encode('utf-8'))
p = arcpy.CreateFeatureclass_management(fileSavePath, 'newPoint', 'POINT')
for filed_name in l2_Coded:
arcpy.AddField_management(p, filed_name, 'TEXT')
yb = arcpy.da.InsertCursor(p, l1_Coded)
for CN in CNList:
yb.insertRow(CN)
del yb
四.contain和within的区别
五.新环境报错openpyxl找不到
解决办法,离线解压相应的包
安装后要将这个jdcal.py拷贝至python->lib>sidepack下
六.融合工具的使用
使用融合工具后形成的新shp文件,不能直接再次去融合,应该行打散后再进行融合,否则在计算时不能裂化至polygon,只能到multypolygon,从而不能进行计算
七.如何创建空要素
有时为了测试需要创建空要素:
s3 = F.listFile(r'E:\test','t2.shp','m')
yb = arcpy.da.InsertCursor(s3,['SHAPE@'])
empty_polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(1,1),arcpy.Point(1,1)]))
yb.insertRow([empty_polygon])
del yb
八 .从头创建要素时,要带spatial_ref
spatial_ref = arcpy.SpatialReference(4326)
ArcpyPolyline = arcpy.Polyline(ArcpyArray_List, spatial_ref)