ArcPy --读取CSV格式的XY坐标并转成shp文件

以下脚本是直接在ArcGIS中的python IDLE中编写代码,可以选择在vsc中编写

以下脚本 这段代码节选自yGIS-csdn
其中 windows路径下的 转义符问题(已修正)


import arcpy, sys

month = ["feb","mar","may","jun","jul","aug","oct","nov","dec"]

for part in range(8):
    for m in month:
     
        try:
            
            path = r"G:\Athrun\ArcData\Point"
         
            outputname = str(part)+"_"+str(m)+"_quanzhou.shp"
            spatRef = arcpy.SpatialReference(4326)
         
            createFC=arcpy.CreateFeatureclass_management(path, outputname, "POINT", "","","", spatRef)
         
         
            arcpy.AddField_management(path+"\\"+outputname, "NAME", "TEXT", 50)
         
            iflds = ["NAME","SHAPE@XY"]
         
            #iCur = arcpy.da.InsertCursor(createFC, iflds)
            iCur = arcpy.da.InsertCursor(path+"\\"+outputname, iflds)
         
            count = 1
         
            for ln in open(('F:\\quanzhou_ship\\'+str(m)+'\\'+str(part)+r'_quanzhou_'+str(m)+'.csv'), 'r').readlines():
                lnstrip = ln.strip()
                if count > 1:
                   dataList = ln.split(",")
                   lat = dataList[15]
         
                   lon = dataList[16]
                   id = dataList[0]
         
                   ivals = [id,(float(lon), float(lat)) ]
                   iCur.insertRow(ivals)
                count += 1
            del iCur
        except EnvironmentError as e:
            tbE = sys.exc_info()[2]
            print("Failed at Line {}\n".format(tbE.tb_lineno))
            print("Error: {}".format(str(e)))
        except Exception as e:
            tbE = sys.exc_info()[2]
            print("Failed at Line {}\n".format(tbE.tb_lineno))
            print("Error: {}".format(e.message))
     

你可能感兴趣的:(使用笔记,python,arcgis,csv)