I am taking a CSV file and importing it with the XY Event feature layer. I then am trying to use the Copy Feature tool to get "Object ID" assigned to each row in order to run an attribute query. My issues is that I can't get the Copy Feature layer to work properly. I believe that the issue is with the feature class I am trying to make using the tool.
I am new to python and can't seem to get this to work right. I am sure I have other issues with my code, but one step at a time.
When I do the try/expect the code works till the copy features layer, so I know that is probably my first of many issues.
#Import a CSV file that will show you what ASOS weather stations are in the state. import arcpy import os #Lets you write over the shape file if needed arcpy.env.overwriteOutput = True arcpy.env.workspace = "C:\\GEOG485\\FinalProject" #Latitude and Longitude Coordinates xFieldName = 'LON' yFieldName = 'LAT' #Output folder outFolder = "C:\\GEOG485\\FinalProject\\Output" #ASOS stations layer eventLayer = "ASOS" outPutlayer = "CurrentStations.shp" #Spatial Reference spatialRef = arcpy.SpatialReference(4326) #CSV file that will be imported into ArcMap csvFilePath = "C:\\GEOG485\\FinalProject\\isd-history.csv" #Select state of interest targetState = 'NJ' #Date of file last updated targetEnd = '20190329' try: #import csv file using the xy event layer tool arcpy.MakeXYEventLayer_management(csvFilePath, xFieldName, yFieldName, eventLayer, spatialRef) #Copy features from the XY Event Layer in order to asign Object ID's to the rows in the file arcpy.CopyFeatures_management(eventLayer, outPutlayer) #Select Attribute management to narrow down the state of interest arcpy.SelectLayerByAttribute_management("currentasos", "NEW_SELECTION", '"STATE" = ' + "'" + targetState + "'") arcpy.SelectLayerByAttribute_management("currentasos", "SUBSET_SELECTION", '"END" = ' + "'" + targetEnd + "'") print ("success") except: print ("error") try: mxd = arcpy.mapping.MapDocument("C:\\GEOG485\\FinalProject\\basemap.mxd") df = arcpy.mapping.ListDataFrame(mxd, "*") newLayer = arcpy.mapping.Layer("currentasos") arcpy.mapping.Layer(df, newLayer, "Bottom") except: print ("error4")