I am trying to import data from a CSV file and write a script that will generate points on a new shapefile. I am running into issues for when I try to update the InsertCursor. I get an error of "not enough quota is available to process this command". I am fairly new to Python; does anyone have any idea of what is wrong with my code?
#Import a csv file and take the coordinates of each ASOS and create a polypoint output
import csv
import arcpy
import os
from arcpy import env
#Lets you write over the shape file if needed
arcpy.env.overwriteOutput = True
targetFolder = "C:\\GEOG485\\FinalProject\\OutPut"
env.workspace = targetFolder
#csv file that we are importing
asosFile = "C:\\GEOG485\\FinalProject\\isd-history.csv"
targetState = 'NJ'
try:
#Create the featureclass ASOS shapefile, 4326 is the factory code for the required coordinate system of the file
asosStations = arcpy.CreateFeatureclass_management("C:\\GEOG485\\FinalProject\\","ASOS","POINT",'','',"ENABLED",4326)
print ("success")
#add a new field called "Station Name", "CTRY", "STATE" and "END"
arcpy.AddField_management(asosStations,"STATION_NAME", "TEXT")
arcpy.AddField_management(asosStations,"CTRY","TEXT")
arcpy.AddField_management(asosStations,"STATE","TEXT")
arcpy.AddField_management(asosStations,"ICAO","TEXT")
arcpy.AddField_management(asosStations,"END","TEXT")
print ("success")
except:
print ("error")
#asos dictinary
asos = {}
try:
#Use the with statement to open the csv file and r to read mode
with open(asosFile, 'r') as csvv:
#Reading the csv file with DictReader which takes the first row of the file and uses them as keys
reader = csv.DictReader(csvv)
#Loops through the csv file
for row in reader:
#Dictionary to see what asos's have a key in the dictionary and append the asos location with the coordinates
if row['ICAO'] not in asos:
asos[row['ICAO']] = []
asos[row['ICAO']].append((row['LAT'],row['LON']))
print ("success2")
except:
print ("error2")
try:
#Takes the points that we just appended to each asos station and adds them to the shapefile
with arcpy.da.InsertCursor(asosStations, ["ICAO","SHAPE@XY"]) as cur:
#Loop checks for keys (file headers) and values (asos's inside the dictionary)
for key,value in asos.items():
print key,value
#creates a point with the points for each asos station in the shape file
for coords in value:
point = arcpy.Point(*coords)
#Takes all the keys with the same names and adds all the associated points to them
row2 = (key,point)
cur.insertRow(row2)
print ("success3")
except:
print ("error3")
try:except:... Stop it, seriously! By all means add error handling once your script (or a specific section of script) is working correctly, but until then, just don't. That way you can provide the full exception traceback, formatted as code{}in your question and people don't yell at you for only asking half a question ;). Oh, and just use MakeXYEventLayer and FeatureClassToShapefile as suggested in the answer below. – user2856 Apr 18 '19 at 03:04try/exceptblocks is incompatible with asking for coding help in GIS SE, since you can't report where the error occurs. – Vince Apr 18 '19 at 10:48