Select to view content in your preferred language

ArcGIS10.0-PythonWindow:Make XY Event Layer-How to set Workspace Environment Setting?

4457
10
10-10-2012 09:45 AM
ScottChang
Deactivated User
Hi all,
I want to use the tutorials "Make XY Event Layer" example (stand-alone Python script) and Using environment settings in Python of ArcGIS 10.0 to create a 12-Point feature and its msd Map for my ArcGIS project.  The following is the stand-alone Python script of  "Make XY Event Layer" from the HELP of ArcGIS 10.0:
# 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()

////////////////////////////////////////////////////////////////////////////
I made a csv file (ID, Lot_ID, x-coords, y-coords, z-coords) for my 12 points (saved as sc12points.xls and sc12points.csv) in my C:/TEMP/WritingGeometries/ folder. Also I have a geodatabase "BS_Test" in my C:/TEMP folder.  In  the Using environment settings in Python of ArcGIS 10.0, I saw env.workspace = "c:/St_Johns/data.gdb".  I know that I have to do/process the sc12points.csv file in the C:/TEMP/WritingGeometries to my C:/TEMP/BS_Test geodatabase - see the attached file.  But, (1) I have no ideas how to complete this process. (2) I have 2 more questions to ask: (2a) is in_Table = "sc12points.csv" right to use in my case? (2b) are x_coords = "POINT_X" and y_coords = "POINT_Y" right to use in my case? 

Please kindly help and advise.

Thanks,
Scott Chang
Tags (2)
0 Kudos
10 Replies
ChristopherThompson
Frequent Contributor
Question #1: Why 2) did not work for the .xls file? Please explain this for me. In the regular Make XY Layer case, the .xls input file is OK.

Generally, reading and writing to excel files is a pain in the butt and my general practice is to avoid that - copy the data you need into a csv or other data format and work with that.  The problem with excel files is partly that they can contain so much crap that ArcGIS doesn't deal with - formatting, forumulas, multiple worksheets, named ranges.. the list goes on.  There are modules that you can import and use to make those more readable, but in most cases I don't think its worth the trouble.

Question #2: In the future, I need the Z_coordinate to be input in my real projects

The reason it fails currently is because the Z values in your table are all NULL - there simply isn't data there.. or worse there are spaces that you can't see evidence of.  Populate that column with zeros (0) or a numeric value, and it works fine (i've tested this with your script) and it should work fine.
0 Kudos