一、数据
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!'
三、结果: