I am attempting this simple workflow.
1) Adding an XY event layer of lat/lon points with z values from a text file.
2) Save the event layer to a layer file.
3) Copy the saved layer file to a new shapefile or feature class in geodatabase.
Now, I know the event layer that is created when you use the "create XY features" tool is a temporary file. I am having issues at the 2nd and 3rd step. The script completes, BUT the new layer file and shapefile are nowhere to be found. I have defined the
workspace path to my local machine but the files are not there after the script completes. Any advice would be greatly
appreciated.
Here is my code :
# MakeXYLayer.py
# Description: Creates an XY Event layer and saves it to a layer file then copies
# the layer file to a shapefile
# import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = "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 = r"C:\Users\mbs7038\Documents\ArcGIS\matDEM\ElevPts.lyr"
# Set the spatial reference
spRef = r("GCS_WGS_1984")
# Make the XY event layer
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, z_coords)
# Save to a layer file
arcpy.SaveToLayerFile_management(out_Layer, saved_Layer)
#===============================================================================
# Copy features to shapefile
arcpy.CopyFeatures_management("C:\Users\mbs7038\Documents\ArcGIS\matDEM\ElevPts.lyr", "C:\Users\mbs7038\Document s\ArcGIS\matDEM\ElevPts.shp")
#===============================================================================
except:
# If an error occurred print the message to the screen
print arcpy.GetMessages()
print 'script complete!!!!!'
1) Adding an XY event layer of lat/lon points with z values from a text file.
2) Save the event layer to a layer file.
3) Copy the saved layer file to a new shapefile or feature class in geodatabase.
Now, I know the event layer that is created when you use the "create XY features" tool is a temporary file. I am having issues at the 2nd and 3rd step. The script completes, BUT the new layer file and shapefile are nowhere to be found. I have defined the
workspace path to my local machine but the files are not there after the script completes. Any advice would be greatly
appreciated.
Here is my code :
# MakeXYLayer.py
# Description: Creates an XY Event layer and saves it to a layer file then copies
# the layer file to a shapefile
# import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = "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 = r"C:\Users\mbs7038\Documents\ArcGIS\matDEM\ElevPts.lyr"
# Set the spatial reference
spRef = r("GCS_WGS_1984")
# Make the XY event layer
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, z_coords)
# Save to a layer file
arcpy.SaveToLayerFile_management(out_Layer, saved_Layer)
#===============================================================================
# Copy features to shapefile
arcpy.CopyFeatures_management("C:\Users\mbs7038\Documents\ArcGIS\matDEM\ElevPts.lyr", "C:\Users\mbs7038\Document s\ArcGIS\matDEM\ElevPts.shp")
#===============================================================================
except:
# If an error occurred print the message to the screen
print arcpy.GetMessages()
print 'script complete!!!!!'