<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic arcpy.MakeXYEventLayer Help in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-makexyeventlayer-help/m-p/248889#M19241</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good Day. I have a csv file with weather stations and precipitation amounts by month. I want my code to ask which months the user would like to plot, open the csv file, add the precip data, and then plot the appropriate data on a map using ArcGIS 10.1 and python 2.7.&amp;nbsp; The code I have so far is listed below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# ------------------------------------------------------------------------------------ # GISClimateMapping.py # Modified and Updated by Rex Morgan; Original Max Min Precip Snow .py by Josh Barnwell # Description: Creates GIS maps for Temperatures, and Rain and Snow Amounts. # ------------------------------------------------------------------------------------ # A Work in progress code 2-17-2013 1020 AM # Removed print statements # User Input of Month, Day, and what Variable to be plotted # Not sure why the test9-1.py failed. I originally believed that to be due to the&amp;nbsp; #&amp;nbsp; non capitalization of the Lat and Long variable but that seems to not be the #&amp;nbsp; case, as I have capitalized the variable.&amp;nbsp; import time import csv import array from time import gmtime, strftime print strftime("%Y-%m-%d %H:%M:%S", gmtime())&amp;nbsp;&amp;nbsp; print ' ' print '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ARCGIS Climate Data Mapping Program' print ' '&amp;nbsp; fname = 'Z:\\Desktop\\COOP_rainfall2.csv'&amp;nbsp; # read the data file data_list = [] for line in open(fname): &amp;nbsp;&amp;nbsp;&amp;nbsp; # remove trailing newline char &amp;nbsp;&amp;nbsp;&amp;nbsp; line = line.rstrip() &amp;nbsp;&amp;nbsp;&amp;nbsp; # create a list &amp;nbsp;&amp;nbsp;&amp;nbsp; line_list = line.split(',') &amp;nbsp;&amp;nbsp;&amp;nbsp; data_list.append(line_list)&amp;nbsp;&amp;nbsp; # create a months dictionary with month:index pairs mdict = {} for ix, item in enumerate(data_list[0]):&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if ix &amp;gt; 8: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mdict[item] = ix&amp;nbsp;&amp;nbsp; #Gathering input from user&amp;nbsp; month1=raw_input('Input the 3 letter ID of beginning month&amp;nbsp; ')#getting input data from user month2=raw_input('Input the 3 letter ID of ending month&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ')#getting input data from user&amp;nbsp; #assigning beginning and ending month here&amp;nbsp; month_start = month1 month_end = month2&amp;nbsp; #Create a new list new_list = [] outgroup = file("Z:\\Desktop\\test.csv", 'w') #this file is initially in the wrong format. for item in data_list[1:]:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; station = item[0] &amp;nbsp;&amp;nbsp;&amp;nbsp; lat = item[2] #Remembe to change this value if altering the structure of the input file Z:\\Desktop\\COOP_rainfall2.csv &amp;nbsp;&amp;nbsp;&amp;nbsp; long = item[3] &amp;nbsp;&amp;nbsp;&amp;nbsp; start = mdict[month_start] &amp;nbsp;&amp;nbsp;&amp;nbsp; end = mdict[month_end]+1 &amp;nbsp;&amp;nbsp;&amp;nbsp; plist = [float(x) for x in item[start : end] if x] #having trouble with blanks &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if plist: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mysum = sum(plist) &amp;nbsp;&amp;nbsp;&amp;nbsp; new_list.append([station, lat, long, mysum])&amp;nbsp;&amp;nbsp; for item in new_list:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; outgroup.write(str(item)) #this does produce a file with the info contained therein but not quite what I want &amp;nbsp;&amp;nbsp;&amp;nbsp; #new_file.write("%s\n" % item) f= open("Z:\\Desktop\\test2.csv", 'w') # This file needs to be different than the one in line 35 of code.&amp;nbsp;&amp;nbsp; for row in new_list: &amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(','.join(map(str,row))+'\n')&amp;nbsp;&amp;nbsp;&amp;nbsp; new_list.insert(0,['Station', 'Lat', 'Long', 'mysum']) # this ran without errors and did add the values to the beginning of list ## this line added at 2-17-2013 933 AM&amp;nbsp; f= open("Z:\\Desktop\\test3.csv", 'w') for row in new_list: &amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(','.join(map(str,row))+'\n')&amp;nbsp;&amp;nbsp; print '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This is the end of the test6.py file.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Now for the rest of it. '&amp;nbsp; Rex = 'Z:\\Desktop\\test3.csv'&amp;nbsp; ### Hack this part back in Precip=[] #creating an array named Precip inp = open (Rex,"r") # Rex defined in line 22 of code for line in inp.readlines():&amp;nbsp; line.split(',')&amp;nbsp; Precip.append(line) file.close(inp) ##### The part above hacked back in&amp;nbsp; print ' ' print 'This will take about 2 to 5 minutes...'&amp;nbsp; month = month1 + ' through ' + month2 months = month usermonth = "[" + months + "]"&amp;nbsp; # Import arcpy module import arcpy import arcpy.mapping&amp;nbsp; # Check out any necessary licenses arcpy.CheckOutExtension("spatial")&amp;nbsp; import sys, string, os&amp;nbsp; # Directories tempdir = 'CSV\\' directory = 'N:\\climate\\ClimateSheets\\' + str(tempdir) TopoToR = 'R:\\ArcGIS\\default.gdb\\TopoToR'&amp;nbsp;&amp;nbsp; # Local variables:&amp;nbsp; GGW_Counties = "R:\\fxc\\Western Region FXC Packet\\GGW.shp" Var_layer = months # variable assigned in line 40 of code Var_shp = str(directory) + 'Var.shp' Var_new = str(directory) + 'Varnew.shp' Var_img = str(directory) + 'Var.img' Var100_img = str(directory) + 'Var100.img' Vari100 = str(directory) + 'Vari100' Varcontour_shp = str(directory) + 'Varcontour.shp' Output_stream_polyline_features = "" Output_remaining_sink_point_features = "" Output_diagnostic_file = "" Output_parameter_file = "" TopoToRasterExtent= "-108.891024 46.540403 -104.041596 49.000027" spRef = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" print 'Made it through Local variables'&amp;nbsp;&amp;nbsp; import arcview import sys, string, os, arcgisscripting gp = arcgisscripting.create(10.1) gp.SetProduct("ArcView") # or ArcEditor or ArcInfo gp.overwriteoutput = 1 #arcpy.overwriteOutput = True print 'Made it through import arcview'&amp;nbsp; ### Getting error in the arcpy.MakeXYEventLayer_management ---- "Long" does not extist "Lat" does not exist # Process: Make XY Event Layer arcpy.MakeXYEventLayer_management(Rex, "Long", "Lat", Var_layer, spRef, "") #Rex is defined in line 90 of code as Z:\\Desktop\\test3.csv print 'Make XY Event Layer Done'&amp;nbsp;&amp;nbsp; # Process: Copy Features arcpy.CopyFeatures_management(Var_layer, Var_shp, "", "0", "0", "0") print 'Copy Features Done'&amp;nbsp;&amp;nbsp; # Process: Topo to Raster from arcpy import env env.extent = "-108.891024 46.540403 -104.041596 49.000027"&amp;nbsp; from arcpy.sa import * outTTR = TopoToRaster([TopoPointElevation([[Var_shp, Var_layer]])], "0.003", "", "20", "", "", "ENFORCE", "CONTOUR", "", "", "", "", "", "") outTTR.save(TopoToR) print 'Topo To Raster Done'&amp;nbsp;&amp;nbsp; # Process: Clip arcpy.Clip_management(TopoToR, "-108.891024 46.540403 -104.041596 49.000027", Var_img, GGW_Counties, "", "ClippingGeometry") print 'Clip Done'&amp;nbsp;&amp;nbsp; # Process: Define Projection for Shapefile in order to plot record values correctly ggw_shp = 'R:\\fxc\\Western Region FXC Packet\\GGW.shp' dsc = arcpy.Describe(ggw_shp) coord_sys = dsc.SpatialReference arcpy.DefineProjection_management(Var_shp, coord_sys) print 'Define Projection Done' print strftime("%Y-%m-%d %H:%M:%S", gmtime())&amp;nbsp; print 'Exporting Map' from datetime import date now = date.today().isoformat() mxd1 = arcpy.mapping.MapDocument(r"R:\EventData\CoopPrecip1024.mxd") mxd3 = arcpy.mapping.MapDocument(r"R:\EventData\CoopPrecip13.mxd") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #newtitle = arcpy.mapping.ListLayoutElements(mxd3, "TEXT_ELEMENT", "title")[0]&amp;nbsp; if 'YTD' in months: #months defined in line 20 &amp;nbsp; print 'if statement' &amp;nbsp; newtitle = arcpy.mapping.ListLayoutElements(mxd1, "TEXT_ELEMENT", "title")[0] &amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd1): &amp;nbsp;&amp;nbsp; if lyr.name == "Var": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("LABELCLASSES"): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass = lyr.labelClasses[0] #this is the Default label class. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass.expression = usermonth &amp;nbsp; newtitle.text = 'Annual COOP Precipitation Year to Date' &amp;nbsp; arcpy.mapping.ExportToPNG(mxd1, r'R:\\Maps\\' + months + str(now) + '.png', resolution=100) #months defined in line 20 else: &amp;nbsp; print 'else statement' &amp;nbsp; newtitle = arcpy.mapping.ListLayoutElements(mxd3, "TEXT_ELEMENT", "title")[0] &amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd3): &amp;nbsp;&amp;nbsp; if lyr.name == "Var": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("LABELCLASSES"): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass = lyr.labelClasses[0] #this is the Default label class. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass.expression = usermonth &amp;nbsp; newtitle.text = 'Monthly COOP Precipitation for ' + month # month defined in line 40 &amp;nbsp; arcpy.mapping.ExportToPNG(mxd3, r'R:\\Maps\\' + months + str(now) + '.png', resolution=100) #months defined in line 20&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Map is Complete and located in R:\Maps'&amp;nbsp; print strftime("%Y-%m-%d %H:%M:%S", gmtime())&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem I have is that I am getting an error in the MakeXYEventLayer. I will quote it below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Traceback (most recent call last):&lt;BR /&gt;&amp;nbsp; File "\home\rex.morgan\Desktop\Temp\test9-3.py", line 151, in &amp;lt;module&amp;gt; arcpy.MakeXYEventLayer_management(Rex, "Long", "Lat", Var_layer, spRef, "")&lt;BR /&gt;&lt;BR /&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py" line 6322, in MakeXYEventLayer raise e&lt;BR /&gt;&lt;BR /&gt;acrgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000728: Field Long does not exist within table&lt;BR /&gt;ERROR 000728: Field Lat does not exist within table&lt;BR /&gt;Failed to execute (MakeXYEventlayer).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas would be greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 17 Feb 2013 17:03:50 GMT</pubDate>
    <dc:creator>RexMorgan</dc:creator>
    <dc:date>2013-02-17T17:03:50Z</dc:date>
    <item>
      <title>arcpy.MakeXYEventLayer Help</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-makexyeventlayer-help/m-p/248889#M19241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good Day. I have a csv file with weather stations and precipitation amounts by month. I want my code to ask which months the user would like to plot, open the csv file, add the precip data, and then plot the appropriate data on a map using ArcGIS 10.1 and python 2.7.&amp;nbsp; The code I have so far is listed below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# ------------------------------------------------------------------------------------ # GISClimateMapping.py # Modified and Updated by Rex Morgan; Original Max Min Precip Snow .py by Josh Barnwell # Description: Creates GIS maps for Temperatures, and Rain and Snow Amounts. # ------------------------------------------------------------------------------------ # A Work in progress code 2-17-2013 1020 AM # Removed print statements # User Input of Month, Day, and what Variable to be plotted # Not sure why the test9-1.py failed. I originally believed that to be due to the&amp;nbsp; #&amp;nbsp; non capitalization of the Lat and Long variable but that seems to not be the #&amp;nbsp; case, as I have capitalized the variable.&amp;nbsp; import time import csv import array from time import gmtime, strftime print strftime("%Y-%m-%d %H:%M:%S", gmtime())&amp;nbsp;&amp;nbsp; print ' ' print '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ARCGIS Climate Data Mapping Program' print ' '&amp;nbsp; fname = 'Z:\\Desktop\\COOP_rainfall2.csv'&amp;nbsp; # read the data file data_list = [] for line in open(fname): &amp;nbsp;&amp;nbsp;&amp;nbsp; # remove trailing newline char &amp;nbsp;&amp;nbsp;&amp;nbsp; line = line.rstrip() &amp;nbsp;&amp;nbsp;&amp;nbsp; # create a list &amp;nbsp;&amp;nbsp;&amp;nbsp; line_list = line.split(',') &amp;nbsp;&amp;nbsp;&amp;nbsp; data_list.append(line_list)&amp;nbsp;&amp;nbsp; # create a months dictionary with month:index pairs mdict = {} for ix, item in enumerate(data_list[0]):&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if ix &amp;gt; 8: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mdict[item] = ix&amp;nbsp;&amp;nbsp; #Gathering input from user&amp;nbsp; month1=raw_input('Input the 3 letter ID of beginning month&amp;nbsp; ')#getting input data from user month2=raw_input('Input the 3 letter ID of ending month&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ')#getting input data from user&amp;nbsp; #assigning beginning and ending month here&amp;nbsp; month_start = month1 month_end = month2&amp;nbsp; #Create a new list new_list = [] outgroup = file("Z:\\Desktop\\test.csv", 'w') #this file is initially in the wrong format. for item in data_list[1:]:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; station = item[0] &amp;nbsp;&amp;nbsp;&amp;nbsp; lat = item[2] #Remembe to change this value if altering the structure of the input file Z:\\Desktop\\COOP_rainfall2.csv &amp;nbsp;&amp;nbsp;&amp;nbsp; long = item[3] &amp;nbsp;&amp;nbsp;&amp;nbsp; start = mdict[month_start] &amp;nbsp;&amp;nbsp;&amp;nbsp; end = mdict[month_end]+1 &amp;nbsp;&amp;nbsp;&amp;nbsp; plist = [float(x) for x in item[start : end] if x] #having trouble with blanks &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if plist: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mysum = sum(plist) &amp;nbsp;&amp;nbsp;&amp;nbsp; new_list.append([station, lat, long, mysum])&amp;nbsp;&amp;nbsp; for item in new_list:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; outgroup.write(str(item)) #this does produce a file with the info contained therein but not quite what I want &amp;nbsp;&amp;nbsp;&amp;nbsp; #new_file.write("%s\n" % item) f= open("Z:\\Desktop\\test2.csv", 'w') # This file needs to be different than the one in line 35 of code.&amp;nbsp;&amp;nbsp; for row in new_list: &amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(','.join(map(str,row))+'\n')&amp;nbsp;&amp;nbsp;&amp;nbsp; new_list.insert(0,['Station', 'Lat', 'Long', 'mysum']) # this ran without errors and did add the values to the beginning of list ## this line added at 2-17-2013 933 AM&amp;nbsp; f= open("Z:\\Desktop\\test3.csv", 'w') for row in new_list: &amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(','.join(map(str,row))+'\n')&amp;nbsp;&amp;nbsp; print '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This is the end of the test6.py file.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Now for the rest of it. '&amp;nbsp; Rex = 'Z:\\Desktop\\test3.csv'&amp;nbsp; ### Hack this part back in Precip=[] #creating an array named Precip inp = open (Rex,"r") # Rex defined in line 22 of code for line in inp.readlines():&amp;nbsp; line.split(',')&amp;nbsp; Precip.append(line) file.close(inp) ##### The part above hacked back in&amp;nbsp; print ' ' print 'This will take about 2 to 5 minutes...'&amp;nbsp; month = month1 + ' through ' + month2 months = month usermonth = "[" + months + "]"&amp;nbsp; # Import arcpy module import arcpy import arcpy.mapping&amp;nbsp; # Check out any necessary licenses arcpy.CheckOutExtension("spatial")&amp;nbsp; import sys, string, os&amp;nbsp; # Directories tempdir = 'CSV\\' directory = 'N:\\climate\\ClimateSheets\\' + str(tempdir) TopoToR = 'R:\\ArcGIS\\default.gdb\\TopoToR'&amp;nbsp;&amp;nbsp; # Local variables:&amp;nbsp; GGW_Counties = "R:\\fxc\\Western Region FXC Packet\\GGW.shp" Var_layer = months # variable assigned in line 40 of code Var_shp = str(directory) + 'Var.shp' Var_new = str(directory) + 'Varnew.shp' Var_img = str(directory) + 'Var.img' Var100_img = str(directory) + 'Var100.img' Vari100 = str(directory) + 'Vari100' Varcontour_shp = str(directory) + 'Varcontour.shp' Output_stream_polyline_features = "" Output_remaining_sink_point_features = "" Output_diagnostic_file = "" Output_parameter_file = "" TopoToRasterExtent= "-108.891024 46.540403 -104.041596 49.000027" spRef = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" print 'Made it through Local variables'&amp;nbsp;&amp;nbsp; import arcview import sys, string, os, arcgisscripting gp = arcgisscripting.create(10.1) gp.SetProduct("ArcView") # or ArcEditor or ArcInfo gp.overwriteoutput = 1 #arcpy.overwriteOutput = True print 'Made it through import arcview'&amp;nbsp; ### Getting error in the arcpy.MakeXYEventLayer_management ---- "Long" does not extist "Lat" does not exist # Process: Make XY Event Layer arcpy.MakeXYEventLayer_management(Rex, "Long", "Lat", Var_layer, spRef, "") #Rex is defined in line 90 of code as Z:\\Desktop\\test3.csv print 'Make XY Event Layer Done'&amp;nbsp;&amp;nbsp; # Process: Copy Features arcpy.CopyFeatures_management(Var_layer, Var_shp, "", "0", "0", "0") print 'Copy Features Done'&amp;nbsp;&amp;nbsp; # Process: Topo to Raster from arcpy import env env.extent = "-108.891024 46.540403 -104.041596 49.000027"&amp;nbsp; from arcpy.sa import * outTTR = TopoToRaster([TopoPointElevation([[Var_shp, Var_layer]])], "0.003", "", "20", "", "", "ENFORCE", "CONTOUR", "", "", "", "", "", "") outTTR.save(TopoToR) print 'Topo To Raster Done'&amp;nbsp;&amp;nbsp; # Process: Clip arcpy.Clip_management(TopoToR, "-108.891024 46.540403 -104.041596 49.000027", Var_img, GGW_Counties, "", "ClippingGeometry") print 'Clip Done'&amp;nbsp;&amp;nbsp; # Process: Define Projection for Shapefile in order to plot record values correctly ggw_shp = 'R:\\fxc\\Western Region FXC Packet\\GGW.shp' dsc = arcpy.Describe(ggw_shp) coord_sys = dsc.SpatialReference arcpy.DefineProjection_management(Var_shp, coord_sys) print 'Define Projection Done' print strftime("%Y-%m-%d %H:%M:%S", gmtime())&amp;nbsp; print 'Exporting Map' from datetime import date now = date.today().isoformat() mxd1 = arcpy.mapping.MapDocument(r"R:\EventData\CoopPrecip1024.mxd") mxd3 = arcpy.mapping.MapDocument(r"R:\EventData\CoopPrecip13.mxd") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #newtitle = arcpy.mapping.ListLayoutElements(mxd3, "TEXT_ELEMENT", "title")[0]&amp;nbsp; if 'YTD' in months: #months defined in line 20 &amp;nbsp; print 'if statement' &amp;nbsp; newtitle = arcpy.mapping.ListLayoutElements(mxd1, "TEXT_ELEMENT", "title")[0] &amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd1): &amp;nbsp;&amp;nbsp; if lyr.name == "Var": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("LABELCLASSES"): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass = lyr.labelClasses[0] #this is the Default label class. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass.expression = usermonth &amp;nbsp; newtitle.text = 'Annual COOP Precipitation Year to Date' &amp;nbsp; arcpy.mapping.ExportToPNG(mxd1, r'R:\\Maps\\' + months + str(now) + '.png', resolution=100) #months defined in line 20 else: &amp;nbsp; print 'else statement' &amp;nbsp; newtitle = arcpy.mapping.ListLayoutElements(mxd3, "TEXT_ELEMENT", "title")[0] &amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd3): &amp;nbsp;&amp;nbsp; if lyr.name == "Var": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("LABELCLASSES"): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass = lyr.labelClasses[0] #this is the Default label class. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass.expression = usermonth &amp;nbsp; newtitle.text = 'Monthly COOP Precipitation for ' + month # month defined in line 40 &amp;nbsp; arcpy.mapping.ExportToPNG(mxd3, r'R:\\Maps\\' + months + str(now) + '.png', resolution=100) #months defined in line 20&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Map is Complete and located in R:\Maps'&amp;nbsp; print strftime("%Y-%m-%d %H:%M:%S", gmtime())&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem I have is that I am getting an error in the MakeXYEventLayer. I will quote it below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Traceback (most recent call last):&lt;BR /&gt;&amp;nbsp; File "\home\rex.morgan\Desktop\Temp\test9-3.py", line 151, in &amp;lt;module&amp;gt; arcpy.MakeXYEventLayer_management(Rex, "Long", "Lat", Var_layer, spRef, "")&lt;BR /&gt;&lt;BR /&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py" line 6322, in MakeXYEventLayer raise e&lt;BR /&gt;&lt;BR /&gt;acrgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000728: Field Long does not exist within table&lt;BR /&gt;ERROR 000728: Field Lat does not exist within table&lt;BR /&gt;Failed to execute (MakeXYEventlayer).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas would be greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Feb 2013 17:03:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-makexyeventlayer-help/m-p/248889#M19241</guid>
      <dc:creator>RexMorgan</dc:creator>
      <dc:date>2013-02-17T17:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.MakeXYEventLayer Help</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-makexyeventlayer-help/m-p/248890#M19242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK. So this mostly works. One problem that I am having is getting M for missing to be ignored rather that treated as a 0 but I will get that resolved eventually. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#! /usr/bin/python # #&amp;nbsp; Format a csv for further processing #&amp;nbsp; #import time import csv import array import decimal decimal.getcontext().prec = 4 from time import gmtime, strftime print strftime("%Y-%m-%d %H:%M:%S", gmtime())&amp;nbsp; # Create an unordered MON to column number dictionary and get user data mdict = {'MAR': 11, 'FEB': 10, 'AUG': 16, 'SEP': 17, 'APR': 12, 'JUN': 14, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'JUL': 15, 'JAN': 9, 'MAY': 13, 'NOV': 19, 'DEC': 20, 'OCT': 18}&amp;nbsp;&amp;nbsp; month_start = raw_input('Input the 3 letter ID of beginning month: ') month_end = raw_input('Input the 3 letter ID of ending month: ') month_start = month_start.upper() month_end = month_end.upper() mon_layer_name = month_start + ' through ' +month_end user_month = '[' + mon_layer_name + ']' start_num = mdict[month_start] end_num = mdict[month_end]+1&amp;nbsp; new_list = [['Station', 'Lat', 'Long', 'mysum']]&amp;nbsp; with open('R:\\COOP\\temp\\COOP_rainfall2.csv', 'rb') as csvfile: #with open('Z:\\Desktop\\COOP_rainfall2.csv', 'rb') as csvfile: &amp;nbsp;&amp;nbsp;&amp;nbsp; filereader = csv.reader(csvfile) &amp;nbsp;&amp;nbsp;&amp;nbsp; filereader.next() #skip header line &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in filereader: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sta = row[0] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lat = row[2] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lon = row[3] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tot = decimal.Decimal(0) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for x in row[start_num:end_num]: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x == '' : x = 0 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif x == 'M': x = 0 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tot = tot + decimal.Decimal(x) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if tot == 0: continue&amp;nbsp; # No zeros allowed so don't append line &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else: new_list.append([sta, lat, lon, str(tot)])&amp;nbsp; with open('R:\\COOP\\temp\\output.csv', 'wb') as csvout:&amp;nbsp;&amp;nbsp; #with open('Z:\\Desktop\\output.csv', 'wb') as csvout: &amp;nbsp;&amp;nbsp;&amp;nbsp; filewriter = csv.writer(csvout) &amp;nbsp;&amp;nbsp;&amp;nbsp; for line in new_list: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filewriter.writerow(line) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Rex = 'R:\\COOP\\temp\\output.csv' Precip=[] #creating an array named Precip inp = open (Rex,"r")&amp;nbsp; for line in inp.readlines():&amp;nbsp; line.split(',')&amp;nbsp; Precip.append(line) file.close(inp) COOP = 'R:\\COOP\\temp\\output.csv'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # # ARCGIS Processing begins here # # # Determine Max, Min, and Diff Values templist = [] data = open (COOP, 'r') lines = str(data.read()).splitlines() for line in lines: &amp;nbsp;&amp;nbsp;&amp;nbsp; if 'Lat,Long' not in line: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line = line.split(',') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = line[int(3)] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; templist.append(float(value)) maxV = max(templist) minV = min(templist) diff = float(maxV) - float(minV) #print 'MAX ' + str(maxV) #print 'MIN ' + str(minV) #print 'DIFF ' + str(diff)&amp;nbsp; month = month_start + ' through ' + month_end months = month usermonth = "[" + months + "]"&amp;nbsp; # Import arcpy module import arcpy import arcpy.mapping&amp;nbsp; # Check out any necessary licenses arcpy.CheckOutExtension("spatial") import sys, string, os&amp;nbsp; # Directories ClipShape = "R:/fxc/Western Region FXC Packet/GGW.shp" webdir = 'R:/COOPImages/' tempdir = 'CSV\\' directory = 'N:\\climate\\ClimateSheets\\' + str(tempdir)&amp;nbsp; # Local variables: GGW_Counties = "R:\\fxc\\Western Region FXC Packet\\GGW.shp" Var_layer = 'mysum' Var_shp = str(directory) + 'Var.shp' spRef = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" print 'Made it through Local variables'&amp;nbsp; # Import Arcview import arcview import sys, string, os, arcgisscripting gp = arcgisscripting.create(10.1) gp.SetProduct("ArcView") # or ArcEditor or ArcInfo gp.overwriteoutput = 1 arcpy.overwriteOutput = True print 'Made it through import arcview'&amp;nbsp; # Process: Make XY Event Layer long = 'Long' lat = 'Lat' arcpy.MakeXYEventLayer_management(COOP, long, lat, Var_layer, spRef, "") #COOP is defined in line 103 of code as Z:\\Desktop\\test3.csv #edited 3-15-2013 print 'Make XY Event Layer Done'&amp;nbsp; # Process: Copy Features arcpy.CopyFeatures_management(Var_layer, Var_shp, "", "0", "0", "0") print 'Copy Features Done'&amp;nbsp; # created the COOP folder on the R drive COOPdir = 'R:/COOP/' COOPtempdir = COOPdir + 'temp/' contour = 'Y'&amp;nbsp;&amp;nbsp; # Conduct remaining code if grid contains values greater than zero if float(maxV) &amp;gt; 0.00:&amp;nbsp; &amp;nbsp;&amp;nbsp; # Execute Interpolation &amp;nbsp;&amp;nbsp; outRaster = COOPtempdir + 'Pre' &amp;nbsp;&amp;nbsp; outContourRaster = COOPtempdir + 'Pre' + 'CRas' &amp;nbsp;&amp;nbsp; from arcpy import env &amp;nbsp;&amp;nbsp; env.extent = "-108.891024 46.540403 -104.041596 49.000024" &amp;nbsp;&amp;nbsp; from arcpy.sa import * &amp;nbsp;&amp;nbsp; #make sure 'mysum' is named correctly when copying over &amp;nbsp;&amp;nbsp; outTTR = TopoToRaster([TopoPointElevation([[Var_shp, 'mysum']])], "0.01", "", "20", "", "", "NO_ENFORCE", "SPOT", "", "", "", "", "", "")&amp;nbsp;&amp;nbsp; #make sure 'mysum' is named correctly &amp;nbsp;&amp;nbsp; outTTR.save(outRaster) &amp;nbsp;&amp;nbsp; outTTR = TopoToRaster([TopoPointElevation([[Var_shp, 'mysum']])], "0.1", "", "20", "", "", "NO_ENFORCE", "SPOT", "", "", "", "", "", "") &amp;nbsp;&amp;nbsp; outTTR.save(outContourRaster) &amp;nbsp;&amp;nbsp; print 'Interpolation Done' &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; #Execute Clip of Raster &amp;nbsp;&amp;nbsp; FinalGridImage = COOPtempdir + 'PrecipTotal.img' &amp;nbsp;&amp;nbsp; arcpy.Clip_management(outRaster, "", FinalGridImage, ClipShape, "", "ClippingGeometry") &amp;nbsp;&amp;nbsp; print 'Raster Clip Done' &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; #Calculate Contour Interval and Layer Value &amp;nbsp;&amp;nbsp; # Contour Interval &amp;nbsp;&amp;nbsp; if contour == 'Y': &amp;nbsp; if float(diff) &amp;lt; 0.25: &amp;nbsp;&amp;nbsp; interval = '0.01' &amp;nbsp; if float(diff) &amp;gt;= 0.25 and float(diff) &amp;lt;= 0.50: &amp;nbsp;&amp;nbsp; interval = '0.05' &amp;nbsp; if float(diff) &amp;gt;= 0.50 and float(diff) &amp;lt;= 1.00: &amp;nbsp;&amp;nbsp; interval = '0.10' &amp;nbsp; if float(diff) &amp;gt;= 1.01 and float(diff) &amp;lt;= 3.00: &amp;nbsp;&amp;nbsp; interval = '0.25' &amp;nbsp; if float(diff) &amp;gt;= 3.01 and float(diff) &amp;lt;= 5.00: &amp;nbsp;&amp;nbsp; interval = '0.50' &amp;nbsp; if float(diff) &amp;gt;= 5.01: &amp;nbsp;&amp;nbsp; interval = '1.00' &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; # Layer Value &amp;nbsp;&amp;nbsp; if&amp;nbsp; float(maxV) &amp;lt; 0.25: &amp;nbsp; imagelayer = 'Precip_0.25' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 0.25 and float(maxV) &amp;lt;= 0.50: &amp;nbsp; imagelayer = 'Precip_0.50' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 0.50 and float(maxV) &amp;lt;= 1.00: &amp;nbsp; imagelayer = 'Precip_1' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 1.00 and float(maxV) &amp;lt;= 2.00: &amp;nbsp; imagelayer = 'Precip_2' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 2.00 and float(maxV) &amp;lt;= 3.00: &amp;nbsp; imagelayer = 'Precip_3' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 3.00 and float(maxV) &amp;lt;= 4.00: &amp;nbsp; imagelayer = 'Precip_4' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 4.00 and float(maxV) &amp;lt;= 6.00: &amp;nbsp; imagelayer = 'Precip_6' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 6.00 and float(maxV) &amp;lt;= 8.00: &amp;nbsp; imagelayer = 'Precip_8' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 8.00 and float(maxV) &amp;lt;= 10.00: &amp;nbsp; imagelayer = 'Precip_10' &amp;nbsp;&amp;nbsp; if float(maxV) &amp;gt; 10.00: &amp;nbsp; imagelayer = 'Precip_12'&amp;nbsp; &amp;nbsp;&amp;nbsp; if contour == 'Y': &amp;nbsp; # Execute Contours &amp;nbsp; print 'Contouring Using Interval: ' + str(interval) &amp;nbsp; outContours = COOPtempdir + 'PrecipContours.shp' # still need to create the PrecipContours.shp file &amp;nbsp; Contour(outContourRaster, outContours, interval, '0') &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; # Assign mxd variable &amp;nbsp;&amp;nbsp; # Created the PrecipTotal.mxd file &amp;nbsp;&amp;nbsp; mxd1 = arcpy.mapping.MapDocument(COOPdir + 'PrecipTotal.mxd') &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; # Activate Correct Layer &amp;nbsp;&amp;nbsp; print 'Image Layer: ' + imagelayer &amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd1): &amp;nbsp; layername = str(lyr) &amp;nbsp; if str(imagelayer) in layername: &amp;nbsp;&amp;nbsp; print 'Using Scale: ' + str(layername) &amp;nbsp;&amp;nbsp; lyr.visible = True &amp;nbsp;&amp;nbsp; break &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; print '-Exporting Precip Graphic-' &amp;nbsp;&amp;nbsp; outputpathfull = webdir + months + ".png" &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPNG(mxd1, outputpathfull, resolution=100)&amp;nbsp;&amp;nbsp; # Process: Define Projection for Shapefile in order to plot record values correctly ggw_shp = 'R:\\fxc\\Western Region FXC Packet\\GGW.shp' dsc = arcpy.Describe(ggw_shp) coord_sys = dsc.SpatialReference arcpy.DefineProjection_management(Var_shp, coord_sys) print 'Define Projection Done' print 'Exporting Map' from datetime import date now = date.today().isoformat() mxd1 = arcpy.mapping.MapDocument(COOPtempdir + 'PrecipTotal.mxd') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #newtitle = arcpy.mapping.ListLayoutElements(mxd3, "TEXT_ELEMENT", "title")[0]&amp;nbsp; print 'Map is complete and located at ' + outputpathfull &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope that this helps someone or inspires someone to so something similar.&amp;nbsp; I could not have made it this far without the help of Josh Barnwell and Rob Oslund, Thanks guys. I have added an image created.&amp;nbsp; I am still battling small things that would make this a little nicer but it does work somewhat.;)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Apr 2013 17:50:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-makexyeventlayer-help/m-p/248890#M19242</guid>
      <dc:creator>RexMorgan1</dc:creator>
      <dc:date>2013-04-26T17:50:19Z</dc:date>
    </item>
  </channel>
</rss>

