arcpy将csv转换为shp

#和txt的处理方式大同小异
#实现思路为列出文件夹中所有的文件,然后读出每个csv中的记录,再添加shp
# encoding: utf-8
import csv
import arcpy
import os
wenjianjia=r"C:\Users\h\Downloads\csv"
outGDB=r"d:\csv.gdb"
parents = os.listdir(wenjianjia)
numsd=0
for file in parents:
    #计数,查看当前进度
    numsd+=1
    print numsd
    with open(wenjianjia+"\\"+file) as f:
        sr = arcpy.SpatialReference(4326)
        filename=file.split('.')
        print filename[0]
        fc = arcpy.CreateFeatureclass_management(outGDB, "shp"+filename[0], "POINT", "", "", "", sr)
        reader = csv.reader(f)
        cursor = arcpy.InsertCursor(fc)
        count=0
        for line in reader:
            #第一行是名称,去掉
            if(count==0):
                b=1
            else:
                feature = cursor.newRow()
                vertex = arcpy.CreateObject("Point")
                vertex.X = line[2]
                vertex.Y = line[1]
                feature.shape = vertex
                cursor.insertRow(feature)
            count += 1

文件存放格式

csv文件内容

 

转载自:https://blog.csdn.net/A873054267/article/details/87394728

You may also like...