Solved! Go to Solution.
import arcpy from arcpy import env # Set environment settings env.workspace = r"C:\Users\mbs7038\Documents\ArcGIS\matDEM" try: # Set the local variables in_Table = "LatLonElev.txt" x_coords = "Lon" y_coords = "Lat" z_coords = "Elev" out_Layer = "ElevPts_layer" saved_Layer = "ElevPts.lyr" # Set the spatial reference print "Set spatial reference" spRef = arcpy.SpatialReference("WGS 1984") # Make the XY event layer print "Make XY event layer" arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, z_coords) # Save to a layer file print "Saving layer file" arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) #=============================================================================== # Copy features to shapefile print "Copying features to shapefile" arcpy.CopyFeatures_management(saved_Layer, "ElevPts.shp") #=============================================================================== except: print arcpy.GetMessages()
spRef = arcpy.SpatialReference(4326)
spRef = arcpy.SpatialReference("WGS 1984")
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, 4326, z_coords)
import arcpy from arcpy import env # Set environment settings env.workspace = r"C:\Users\mbs7038\Documents\ArcGIS\floodtest" try: # Set the local variables #INPUTS in_Table = "TEST.txt" x_coords = "Lon" y_coords = "Lat" z_coords = "wlevel" #OUTPUTS out_Layer = "TEST_Layer" #saved_Layer = "TEST1.lyr" fc=r"C:\Users\mbs7038\Documents\ArcGIS\floodtest\AWESOME.gdb\TEST1" #=========================================================================== # Set the spatial reference----DID NOT WORK WHEN DEFINING spRef. # USE COORDINATE SYSTEM CODE FOR "WGS 84" (4326) IN THE SCRIPT FOR MAKE XY EVENT LAYER #print "Set spatial reference" #spRef = arcpy.SpatialReference(4326) #=========================================================================== #=========================================================================== # Make the XY event layer # MakeXYEventLayer_management (table, in_x_field, in_y_field, out_layer, {spatial_reference}, {in_z_field}) print "Make XY event layer" arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, 4326, z_coords) #=========================================================================== #=========================================================================== # Save to a layer file----DO NOT NEED TO PROCESS THIS STEP. CAN SKIP TO COPY FEATURES #print "Saving layer file" #arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) #=========================================================================== #=========================================================================== # Copy features to feature class print "Copying features to feature class" arcpy.CopyFeatures_management(out_Layer,fc) #=========================================================================== except: print arcpy.GetMessages()
Hi all,
I have a similar script where I am going through a file and converting all .txt files into events layers, and finally into points files. The points are X and Y coords. I have tried changing all manner of things yet I still get a Runtime error: object: error in executing tool message. Any ideas where the script is going wrong. I know it's something in the MakeXYEventLayer_management but cannot figure out where... Any help will be welcomed.
-------------------------------------------------------------------
import arcpy, sys, os
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True #Set the script to be able to overwrite files
Path_table = "J:/Annual_time_series/NDVI_images/Beni1/Centrelines/" #path
for root, dirs, files in os.walk(Path_table):
for name in files:
beni3_reclass = os.path.join(root,name) #name
if beni3_reclass.endswith('_CL.txt') == True:
tilename = name[0:-4] #changed to keep my filenames
print tilename + " being processed."
table = Path_table + name
in_x_field = "cl_x"
in_y_field = "cl_y"
out_layer = Path_table + tilename + "_layer"
#saved_layer = Path_table + tilename + ".lyr"
#Convert txt file table to an events layer
arcpy.MakeXYEventLayer_management (table, in_x_field, in_y_field, out_layer, {"J:/Annual_time_series/NDVI_images/coordinate_system/WGS 1984 UTM Zone 19N.prj"}, {})
print arcpy.GetMessages()
#save to featureclass - this makes it a permenant shape points file
Path_points = "J:/Annual_time_series/NDVI_images/Beni1/Centrelines/CL_coords"
in_features = out_layer
out_featureclass = Path_points + tilename + "_CL_pts.shp"
arcpy.CopyFeatures_management (in_features, out_feature_class, {}, {}, {}, {})
-------------------------------------------------------------------------
The error message is:
Traceback (most recent call last):
File "E:/CLtxt_to_points.py", line 22, in <module>
arcpy.MakeXYEventLayer_management (table, in_x_field, in_y_field, out_layer, {"J:/Annual_time_series/NDVI_images/coordinate_system/WGS 1984 UTM Zone 19N.prj"}, {})
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6348, in MakeXYEventLayer
raise e
RuntimeError: Object: Error in executing tool
Thanks,
Josh