# MakeXYLayer.py # Description: Creates an XY layer and exports it to a layer file # import system modules import arcpy from arcpy import env # Set environment settings env.workspace = "C:/data" try: # Set the local variables in_Table = "firestations.dbf" x_coords = "POINT_X" y_coords = "POINT_Y" z_coords = "POINT_Z" out_Layer = "firestations_layer" saved_Layer = r"c:\output\firestations.lyr" # Set the spatial reference spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj" # Make the XY event layer... arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, z_coords) # Print the total rows print arcpy.GetCount_management(out_Layer) # Save to a layer file arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) except: # If an error occurred print the message to the screen print arcpy.GetMessages()
import arcpy from arcpy import env env.workspace = r'C:TEMP\BS_Test.gdb'
my_csv = r'C:\TEMP\WritingGeometries\sc12points.csv' arcpy.MakeXYEventLayer_management(my_csv, x_coords, y_coords, out_Layer, spRef, z_coords) is the same as: arcpy.MakeXYEventLayer_management(r'C:\TEMP\WritingGeometries\sc12points.csv' , x_coords, y_coords, out_Layer, spRef, z_coords)
x_coords = "x-coord" y_coords = "y-coord"
>>> # chrisMakeXYlayer.py for 12 points ... # Description: Creates an XY layer and exports it to a layer file ... # Author: ESRI - modified by Scott Chang per Christopher Thompson (Date: 11 Oct 2012) ... # import system modules ... import arcpy ... from arcpy import env ... # Set environment settings per Chris T. ... env.workspace = r'C:\TEMP\BS_Test.gdb' ... ... try: ... # Set the local variables ... # in_Table = "firestations.csv" ... my_csv = r'C:\TEMP\WritingGeometries\sc12points.csv' ... ... x_coords = "x-coord" ... y_coords = "y-coord" ... z_coords = "z-coord" ... out_Layer = "firestations_layer" ... saved_Layer = r"c:\TEMP\firestations.lyr" ... ... # Set the spatial reference ... spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj" ... ... # Make the XY event layer... ... arcpy.MakeXYEventLayer_management(my_csv, x_coords, y_coords, out_Layer, spRef, z_coords) ... ... # Print the total rows ... print arcpy.GetCount_management(out_Layer) ... ... # Save to a layer file ... arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) ... ... except: ... # If an error occurred print the message to the screen ... print arcpy.GetMessages() ... Executing: MakeXYEventLayer C:\TEMP\WritingGeometries\sc12points.csv x-coord y-coord firestations_layer "PROJCS['NAD_1983_UTM_Zone_11N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-117.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision" z-coord Start Time: Thu Oct 11 14:40:20 2012 Failed to execute. Parameters are not valid. ERROR 000728: Field x-coord does not exist within table ERROR 000728: Field y-coord does not exist within table ERROR 000728: Field z-coord does not exist within table Failed to execute (MakeXYEventLayer). Failed at Thu Oct 11 14:40:20 2012 (Elapsed Time: 0.00 seconds)
Failed to execute. Parameters are not valid.
ERROR 000728: Field x-coord does not exist within table
ERROR 000728: Field y-coord does not exist within table
ERROR 000728: Field z-coord does not exist within table
x_coords = "x-coord" y_coords = "y-coord" z_coords = "z-coord"
>>> # chrisMakeXYlayer.py for 12 points ... # Description: Creates an XY layer and exports it to a layer file ... # Author: ESRI - modified by Scott Chang per Christopher Thompson (Date: 12 Oct 2012) ... # import system modules ... import arcpy ... from arcpy import env ... # Set environment settings per Chris T. ... env.workspace = r'C:\TEMP\BS_Test.gdb' ... ... try: ... # Set the local variables ... # in_Table = "firestations.csv" ... my_csv = r'C:\TEMP\WritingGeometries\sc12points.csv' ... ... x_coords = "X" ... y_coords = "Y" ... z_coords = "Z" ... out_Layer = "firestations_layer" ... saved_Layer = r"c:\TEMP\firestations.lyr" ... ... # Set the spatial reference ... spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj" ... ... # Make the XY event layer... ... arcpy.MakeXYEventLayer_management(my_csv, x_coords, y_coords, out_Layer, spRef, z_coords) ... ... # Print the total rows ... print arcpy.GetCount_management(out_Layer) ... ... # Save to a layer file ... arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) ... ... except: ... # If an error occurred print the message to the screen ... print arcpy.GetMessages() ... Executing: MakeXYEventLayer C:\TEMP\WritingGeometries\sc12points.csv X Y firestations_layer "PROJCS['NAD_1983_UTM_Zone_11N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-117.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision" Z Start Time: Fri Oct 12 07:54:15 2012 Failed to execute. Parameters are not valid. ERROR 000732: XY Table: Dataset C:\TEMP\WritingGeometries\sc12points.csv does not exist or is not supported Failed to execute (MakeXYEventLayer). Failed at Fri Oct 12 07:54:16 2012 (Elapsed Time: 1.00 seconds)
>>> # chrisMakeXYlayer.py for 12 points ... # Description: Creates an XY layer and exports it to a layer file ... # Author: ESRI - modified by Scott Chang per Christopher Thompson (Date: 12 Oct 2012) ... # import system modules ... import arcpy ... from arcpy import env ... # Set environment settings per Chris T. ... env.workspace = r'C:\TEMP\BS_Test.gdb' ... ... try: ... # Set the local variables ... # in_Table = "firestations.csv" ... my_xls = r'C:\TEMP\WritingGeometries\sc12points.xls' ... ... x_coords = "X" ... y_coords = "Y" ... z_coords = "Z" ... out_Layer = "firestations_layer" ... saved_Layer = r"c:\TEMP\firestations.lyr" ... ... # Set the spatial reference ... spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj" ... ... # Make the XY event layer... ... arcpy.MakeXYEventLayer_management(my_xls, x_coords, y_coords, out_Layer, spRef, z_coords) ... ... # Print the total rows ... print arcpy.GetCount_management(out_Layer) ... ... # Save to a layer file ... arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) ... ... except: ... # If an error occurred print the message to the screen ... print arcpy.GetMessages() ... Executing: MakeXYEventLayer C:\TEMP\WritingGeometries\sc12points.xls X Y firestations_layer "PROJCS['NAD_1983_UTM_Zone_11N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-117.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision" Z Start Time: Fri Oct 12 09:56:38 2012 Failed to execute. Parameters are not valid. ERROR 000732: XY Table: Dataset C:\TEMP\WritingGeometries\sc12points.xls does not exist or is not supported Failed to execute (MakeXYEventLayer). Failed at Fri Oct 12 09:56:38 2012 (Elapsed Time: 0.00 seconds) >>>
tb = r'C:\Documents and Settings\cthompson\My Documents\pythonstuff\testdata\test_data.csv' xc = 'X' yc = 'Y' spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj" xytab = arcpy.MakeXYEventLayer_management(tb,xc,yc,'csv_tab',spRef)
tb = r'C:\Documents and Settings\cthompson\My Documents\pythonstuff\testdata\test_data.csv' xc = 'X' yc = 'Y' zc = 'Z' spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj" xytab = arcpy.MakeXYEventLayer_management(tb,xc,yc,'csv_tab',spRef,zc)
>>> # chrisMakeXYlayer.py for 12 points: Just X- and Y-coordinate (No Z-coordinate in the input table) ... # Description: Creates an XY layer and exports it to a layer file ... # Author: ESRI - modified by Scott Chang per Christopher Thompson (Date: 115 Oct 2012) ... # import system modules ... import arcpy ... from arcpy import env ... # Set environment settings per Chris T. ... env.workspace = r'C:\TEMP\BS_Test.gdb' ... ... try: ... # Set the local variables ... # in_Table = "firestations.csv" ... tb = r'C:\TEMP\WritingGeometries\sc12points.xls' ... ... xc = "X" ... yc = "Y" ... ... out_Layer = "firestations_layer" ... saved_Layer = r"c:\TEMP\firestations.lyr" ... ... # Set the spatial reference ... spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj" ... ... # Make the XY event layer... ... xytab = arcpy.MakeXYEventLayer_management(tb, xc, yc, out_Layer, spRef) ... ... # Print the total rows ... print arcpy.GetCount_management(out_Layer) ... ... # Save to a layer file ... arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) ... ... except: ... # If an error occurred print the message to the screen ... print arcpy.GetMessages() ... Executing: MakeXYEventLayer C:\TEMP\WritingGeometries\sc12points.xls X Y firestations_layer "PROJCS['NAD_1983_UTM_Zone_11N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-117.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision" # Start Time: Mon Oct 15 13:59:51 2012 Failed to execute. Parameters are not valid. ERROR 000732: XY Table: Dataset C:\TEMP\WritingGeometries\sc12points.xls does not exist or is not supported Failed to execute (MakeXYEventLayer). Failed at Mon Oct 15 13:59:51 2012 (Elapsed Time: 0.00 seconds)