Python函数练习(基本函数以及点的创建)

这篇博客展示了如何使用Python的arcpy模块创建点几何对象,并将其存储为shapefile。首先定义了两个加法函数,然后通过条件判断为点创建不同的类别标签。最后,基于给定点坐标创建了点几何对象,并将它们插入到新的shapefile中,同时为每个点分配了一个唯一标识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

def myAdd(a,b):
    c=a+b
    return c
def myClass(num):
    if num>0 and num<10:
        return "A"
    elif num>=10 and num<20:
        return "B"
    else:return "C"
d=myAdd(3,5)
e=myAdd(14,15)
print d
print e
f=myClass(100)
print f
import arcpy
point=[[120,30],[155,60],[129,49],[40,50]]
sq=arcpy.SpatialReference(4326)
path="C:\Users\DELL\Desktop\新建文件夹"
fileName="point.shp"
fc=arcpy.CreateFeatureclass_management(path,fileName,"POINT","","","",sq)
arcpy.AddField_management(fc,"FIDX","TEXT",50)
cursor=arcpy.InsertCursor(fc)
index=0
for pt in point:
    point=arcpy.Point()
    point.X=pt[0]
    point.Y=pt[1]
    row=cursor.newRow()
    row.shape=point
    row.FIDX=index
    cursor.insertRow(row)
    index=index+1
print "finished"

参考视频:
https://www.bilibili.com/video/BV1Si4y1j7Hx?from=search&seid=5623986169959251073

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值