Select to view content in your preferred language

ArcGIS10.0-PythonWindow:Make XY Event Layer- .csv & WGS 1984: Errors 000622 & 000628?

6319
21
10-16-2012 04:23 AM
ScottChang
Deactivated User
Hi all,
In the Excel 2007, I created a .csv file of the XY-coordinates for 10 points of my sampling locations at Edgewood, Maryland - see the attached file.  In the Python Window of my ArcGIS 10.0, I executed the following Python script:
>>> # scMakeXYlayer.py   for 12 points  Just X- & Y-coord, but no Z-coord in the csv & the .py file
... # Description: Creates an XY layer and exports it to a layer file
... # Author: ESRI - modified by Scott Chang per Chris Thompson's New No-Z (Date:  16 Oct 2012)
... # import system modules 
... import arcpy
... from arcpy import env
... # Set environment settings
... env.workspace = 'C:\TEMP\BS_Test.gdb'
...  
... try:
...     # Set the local variables
...     # in_Table = "firestations.csv"
...     tb = r'C:\TEMP\WritingGeometries\APGriMMRP.csv'
...     xc = "X"
...     yc = "Y"
...     
...     out_Layer = "BHsWellLocations_layer"
...     saved_Layer = r"c:\TEMP\BHsWellLocations.lyr"
...  
...     # Set the spatial reference
...     # spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj"
...     spRef = r"Coordinate Systems\Geographic Coordinate System\World\WGS 1984" 
...  
...     # Make the XY event layer...
...     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()
... 
ERROR 000622: Failed to execute (Make XY Event Layer). Parameters are not valid.
ERROR 000628: Cannot set input into parameter spatial_reference.
>>> 


Please kindly help and advise me why I got these 2 errors and how to fix them.

Thanks,
Scott Chang
Tags (2)
0 Kudos
21 Replies
DarrenWiens2
MVP Honored Contributor
The order of parameters from the help is (note that the z-field is last):

MakeXYEventLayer_management (table, in_x_field, in_y_field, out_layer, {spatial_reference}, {in_z_field})

So, your call should be:
arcpy.MakeXYEventLayer_management(tb, xc, yc, out_Layer, spRef, zc)
0 Kudos
ScottChang
Deactivated User
Hi Darren,  Thanks for your valuable response.
I followed your instruction and added the "zc" to the last place of arcpy.MakeXYEventLayer_management(....., zc). I also checked my .xls file for the "zc" data, etc. - see the attched .xls file.
I executed my revised Python script in the Python Window of my ArcGIS 10.0:
>>> # scMakeXYlayerZ.py   for 10 points of ApgRImmrp:   X-, Y-, and Z-coord in the xls & the .py file
... # Description: Creates an XY layer and uses CopyFeatures to save it to a layer file
... # Author: ESRI - modified by Scott Chang per Arkadiusz Matoszka, Wayne Whitley and Darren Wiens 
... # (Date:  1 Nov 2012)
... # import system modules 
... import arcpy
... from arcpy import env
... # Set environment settings
... # env.workspace = r"C:\TEMP\BS_Test.gdb"         # New!!!  (per Arek)
...  
... try:
...     # Set the local variables
...     # in_Table = "firestations.csv"
...     tb = r"C:\TEMP\WritingGeometries\ApgRImmrpWGSxyz.xls\ApgRImmrpWGS$"
...     xc = "X"
...     yc = "Y"
...     zc = "Z"
...     out_Layer = "Pointlocations_layer"
...     saved_Layer = r"c:\TEMP\APGriMMRPBHsWellZ.shp"     # not .layer!!!
...  
...     # Set the spatial reference
...     # spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj"
...     spRef = r"Coordinate Systems\Geographic Coordinate System\World\WGS 1984" 
...  
...     # Make the XY event layer...
...     arcpy.MakeXYEventLayer_management(tb, xc, yc, out_Layer, spRef, zc)  # zc should be last (per Darren)
...  
...     # Print the total rows
...     print arcpy.GetCount_management(out_Layer)
...  
...     # Save to a layer file
...     # arcpy.SaveToLayerFile_management(out_Layer, saved_Layer)
...     arcpy.CopyFeatures_management(out_Layer, saved_Layer)      # New!!! (per Arek)
... except:
...     # If an error occurred print the message to the screen
...     print arcpy.GetMessages()
... 
ERROR 000622: Failed to execute (Make XY Event Layer). Parameters are not valid.
ERROR 000628: Cannot set input into parameter spatial_reference.
>>> 


It did not work at all-ERRORS 000622 and 000628 again.  Please kindly help and advise again.

Thanks in advance,
Scott Chang
0 Kudos
T__WayneWhitley
Honored Contributor
Uh, this might sound uninformed, but I'm just curious - does the WGS84 coord sys even support Z coordinates?

Apparently, yes.  Just tested this with WGS 84, using lat/lon points, 4 of them with the Make XY Event Layer Z parameter ranging from -25 to 25.  Probably meters is assumed, I'm not certain and haven't tested much at all with this.  It may depend on whether you've defined your vertical datum (if you have one).
0 Kudos
DarrenWiens2
MVP Honored Contributor
It looks like there's a problem with how you're specifying your coordinate system. Apparently, there are 3 ways to properly create a spatial reference:
1.) Use the name of the coordinate system (I couldn't get it to work with "GCS_WGS_1984" or "WGS_1984", so I'm not sure what it's looking for)
2.) Use a projection file (.prj) (I didn't try this)
3.) Use a coordinate system's factory code (or authority code) (this works)

Try making spRef = 4326

This works for me:

arcpy.MakeXYEventLayer_management("H:/GIS_Data/ApgRImmrpWGSxyz.xls/ApgRImmrpWGS$", "X", "Y", "outputlayer",4326, "Z")
0 Kudos
ScottChang
Deactivated User
Hi Darren, Thanks for your nice and valuable response.
I revised the input information in the arcpyMakeXYEventLayer_management(....) as you instructed. Then I executed my revised Python script in the Python Window of my ArcGIS 10.0 - see the attached docx file. It worked. But It gave me (i) outputlayer only, (ii) no out_Layer and saved_Layer, and (iii) ERROR 000732.  I think that (i), (ii) and (iii) can be improved/corrected. Please kindly help and advise me how to improve/correct (i), (ii) and (iii).
Thanks again,
Scott Chang
0 Kudos
T__WayneWhitley
Honored Contributor
I'm sorry for your pain - but you've introduced a new layer name as output, "outputlayer".

Naturally this is going to 'break the chain'.  You using 2 more tools trying to access out_Layer (a variable reference to "Pointlocations_layer")

Your fix should be to ust the out_Layer variable (no quotes).
0 Kudos
ScottChang
Deactivated User
Hi Wayne, Thanks for your nice, valuable response.
I changed the "outputlayer" to out_Layer as you instructed.  I executed the newly revised Python script.  It worked beautifully.  I got no errors and 2 right output/Layers  (APGriMMRPBHsWellZ and Pointlocation_layer) in TOC-see the attached file.  One final questions to ask you: I guess that APGriMMRPBHsWellZ is a shapfile and Pointlocation_layer is NOT a shapefile (just a layer). Do I guess it right? Why are they different? How can I tell the difference between these 2 output?   Please help and respond.

Thanks,
Scott Chang
0 Kudos
T__WayneWhitley
Honored Contributor
Yes, you guessed right...the one with the shp file extension is the shapefile.

The main difference is shapefile or feature class, etc. is stored separate from your map.  A 'feature layer' (and a 'table view') are 'virtual' -- they can be added to your map but essentially when your map is deleted, or when your ArcGIS session is ended either without saving or without the option to 'add outputs to display', then the output is lost.

That's basically it - usually it's better to save data outside the map doc so at least you can access it from another doc, if you wish.  At the very least, although you shouldn't be losing mxds, data tends to be safer in a shapefile library or in gdb(s).

Hope that helps.  And hope you're keeping your sense of humor working through some of these problems.  Now, make sure you award points to everyone who helped you!  🙂
0 Kudos
ScottChang
Deactivated User
Hi Wayne, Thanks for your response.

Please let me know how I can award the points to everyone who helped me in this Make XY Layer Event Python pergramming.

Thanks,
Scott Chang
0 Kudos
T__WayneWhitley
Honored Contributor
See what I will call the 'toggle button' over to the upper right of the post - fiddle with that, up arrow awards points....  I forget exactly how you 'check mark' a response for the answer but you can probably figure it out (or maybe in FAQ?) - thing is, I believe you can only award 1 correct answer.  Points, on the other hand, can be applied 'sprinkling' onto several posts, if you will.

Thanks for participating and keeping us on our toes!

- Wayne

EDIT:  See the pic at the top of the page:
http://forums.arcgis.com/index.php
0 Kudos