使用ArcPy将txt经纬度数据创建成点图层(shp格式)

一、数据

txt格式 utf8编码

num,name,lon,lat
1,安康,108.508,47.55
2,汉中,109.604,24.36
3,西安,110.366,68.68

二、代码

import arcpy
import os
from arcpy import env
f=open('E:/coor.txt','r')
lines=f.readlines()
head=lines[0].split(",")
del lines[0]
print head[0]
resultpath="E:/data"
resultshp="zbdshp6.shp"
spatRef = arcpy.SpatialReference(4326)
createFC = arcpy.CreateFeatureclass_management(resultpath,resultshp,"POINT", "", "", "",spatRef)
arcpy.AddField_management(createFC,head[0],"SHORT")
arcpy.AddField_management(createFC,head[1],"TEXT")
arcpy.AddField_management(createFC,head[2],"DOUBLE")
arcpy.AddField_management(createFC,head[3],"DOUBLE")
cur = arcpy.InsertCursor(createFC)
for line in lines:
    p = line.split(',');
    row = cur.newRow()
    point = arcpy.Point()
    num=p[0]
    name=p[1]
    lon=p[2]
    lat=p[3]
    point.X=lon
    point.Y=lat
    pointGeometry=arcpy.PointGeometry(point)
    row.shape=pointGeometry
    row.name=name
    row.lon=lon
    row.lat=lat
    cur.insertRow(row)

print 'The program was successfully completed!'

三、结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值