Arcpy开发记录

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)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值