daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import csv,arcpy,codecs,ast  csvfile = r'\Cd1001-f18gisClientsEnbridgeLine4_MP66_75Project_DataTablemw_bh_loc_20171115.csv'
  2.  
  3. fc = r'Q:ClientsEnbridgeLine4_MP66_75Project_Databh_mw_loc.shp'
  4.  
  5. with codecs.open(csvfile,'rb',encoding="utf-8-sig") as csvFile:
  6.  
  7.     csvheader1 = [x.strip() for x in next(csvFile).split(',')]
  8.     print csvheader1
  9.     for row in csv.reader(csvFile):
  10.         print row
  11.  
  12. gdbFields = arcpy.ListFields(fc) insertList = []
  13.  
  14. for x in range (0,len(csvheader1)):
  15.     insertList.append('csvrow['+str(x)+']') insertList.append('(float(csvrow[1]),float(csvrow[2]))') csvheader2 = list(csvheader1) csvheader2.append("SHAPE@XY") insertList2 = tuple(csvheader2)
  16.  
  17. print csvheader2
  18.  
  19. newFields = [x for x in csvheader1 if x not in gdbFields] print newFields for x in newFields:
  20.     arcpy.AddField_management(fc,x,'TEXT','','','200') gdbNewFields = gdbFields + newFields insertFields = csvheader1.append("SHAPE@XY") fcWellIDValues = [row[0] for row in arcpy.da.SearchCursor(fc, "Well_ID")] print fcWellIDValues csvDict = csv.DictReader(codecs.open(csvfile, encoding ="utf-8-sig")) for csvrow in csvDict:
  21.  
  22.  
  23.     if csvrow["Well_ID"] in fcWellIDValues:
  24.         with arcpy.da.UpdateCursor(fc, gdbNewFields) as cursor:
  25.             for row in cursor:
  26.                 if row["Well_ID"] == csv["Well_ID"]:
  27.                     for x in newFields:
  28.                         row[x] == csvrow[x]
  29.                     cursor.updateRow(row)
  30.  
  31.     elif csvrow["Well_ID"] not in fcWellIDValues:
  32.         with arcpy.da.InsertCursor(fc,csvheader2)as cursor:
  33.             cursor.insertRow([insertList2])
  34.  
  35. print "done"
  36.    
  37. Traceback (most recent call last):
  38.   File "C:UsersvlawDesktopApplicationcsv_mwloader.py", line 47, in <module>
  39.     cursor.insertRow([insertList2])
  40. TypeError: sequence size must match size of the row
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top