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

5241
21
10-16-2012 04:23 AM
ScottChang
New Contributor II
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
ArkadiuszMatoszka
Occasional Contributor II
Hi,
Looking at attached file, I think coordinates format is invalid. To create features in WGS coordinates have to be in decimal degrees and in your file they aren't.
Another thing is what you want to achieve by creating lyr on event layer?
If you want to save event layer as featureclass use CopyFeatuers_management instead.

Cheers
Arek
0 Kudos
ScottChang
New Contributor II
Hi Arek,  Thanks for your nice response.

1)  I used the UTM <=> Lat/Long Decimal Degrees converter to change the X,Y-coordinates of 10 points in UTM Zone 18 (NAD 83) to the new X,Y-coordinates of same 10 points in World WGS 1984 - see the attached xls file. Then I executed my scMakeXYlayer.py in the Python Window of my ArcGIS 10.0:
>>> # scMakeXYlayer.py   for 10 points at APG-RI-MMRP site  
... # WGS 1984: 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:  17 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\ApgRImmrpWGS.csv'
...     xc = "X"
...     yc = "Y"
...     
...     out_Layer = "BHsWellEdgewood_layer"
...     saved_Layer = r"c:\TEMP\BHsWellEdgewood.lyr"
...  
...     # Set the spatial reference
...     # spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 18N.prj"
...     spRef = r"Coordinate Systems\Geographic Coordinate System\World\WGS 1984.prj" 
...  
...     # 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.
>>> 

I got the same Errors 000622 and 000628 again.   I wonder why my scMakeXYlayer.py with the "UTM" XY-coordinates worked before, but my new shcMakeXYlayer.py with the "World WGS 1984" XY-coordinates did not work!!!???  Please kindly help and enlighten me on this strange matter.

2)  I don't understand your second thing you mentioned and I don't know how to implement it.  Please give me the detailed instructions of writing the Python code for doing it.

Thanks,
Scott Chang
0 Kudos
ArkadiuszMatoszka
Occasional Contributor II
I made few changes to your code and test it with xls you've attached, and it seems to be working fine.
You may want to check is everything is ok with your wgs 84.prj, and path to it. Also i recommend to skip setting env, unless you wanne use it. Below code with my modifications, also should explain how to use CopyFeatures instead of SaveToLayerFile.


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 = 'D:\\ApgRImmrpWGS.xls\\ApgRImmrpWGS$'
    xc = "X"
    yc = "Y"
    
    out_Layer = "BHsWellLocations_layer"
    saved_Layer = r"c:\Tmp\BHsWellLocations.shp"
 
    # 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.CopyFeatures_management(out_Layer, saved_Layer)
 
except:
    # If an error occurred print the message to the screen
    print arcpy.GetMessages()


Regards
Arek
0 Kudos
ScottChang
New Contributor II
Hi Arek, Thanks for your nice response.

I modified my Python script as you instructed to do CopyFeatures. In the Python Window of my ArcGIS 10.0 (Desktop), I executed the following code:
>>> # 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 uses CopyFeatures to save it to a layer file
... # Author: ESRI - modified by Scott Chang per Arkadiusz Matoszka (Date:  24 Oct 2012)
... # import system modules 
... import arcpy
... from arcpy import env
... # Set environment settings
... # env.workspace = 'C:\TEMP\BS_Test.gdb'  # New!!!
...  
... try:
...     # Set the local variables
...     # in_Table = "firestations.csv"
...     tb = 'C:\TEMP\WritingGeometries\arekAPGriMMRP.xls\APGriMMRP$'
...     xc = "X"
...     yc = "Y"
...     
...     out_Layer = "Pointlocations_layer"
...     saved_Layer = r"c:\TEMP\arekAPGriMMRPLocations.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)
...  
...     # 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!!!
... except:
...     # If an error occurred print the message to the screen
...     print arcpy.GetMessages()
... 
Executing: MakeXYEventLayer C:\TEMP\WritingGeometries rekAPGriMMRP.xls\APGriMMRP$ X Y Pointlocations_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: Wed Oct 24 08:12:45 2012
Failed to execute. Parameters are not valid.
ERROR 000732: XY Table: Dataset C:\TEMP\WritingGeometries rekAPGriMMRP.xls\APGriMMRP$ does not exist or is not supported
Failed to execute (MakeXYEventLayer).
Failed at Wed Oct 24 08:12:45 2012 (Elapsed Time: 0.00 seconds)
>>> 

I don't know why it does not work for me. I have ArcGIS Desktop 10.0 - it is not a very sophiscated version of ArcGIS 10 (I feel). I wonder: Did you use a more sophiscated/advanced version of ArcGIS 10 system to do your "CopyFeatures" Python programming? I really like to use the xls file and the "CopyFeatures" code staement to do the "Make XY Event Layer" Python programming like the manual way to get the "Point" featurs.
Please kindly help and advise again.

Thanks,
Scott Chang
0 Kudos
T__WayneWhitley
Frequent Contributor
Your problem is not with Copy Features but with reading the table pathname for Make XY Event.

You have done this:
>>> tb = 'C:\TEMP\WritingGeometries\arekAPGriMMRP.xls\APGriMMRP$'

>>> # which returns a faulty pathname because '\' is read as an escape character by Python
>>> print tb
C:\TEMP\WritingGeometriesrekAPGriMMRP.xls\APGriMMRP$


...and should have followed the sample given you by Arek more closely since it is easy to make a minor error to foul the whole works:

>>> # as given you by arekmatoszka: 
>>> tb = 'C:\\TEMP\\WritingGeometries\\arekAPGriMMRP.xls\\APGriMMRP$'

>>> print tb
C:\TEMP\WritingGeometries\arekAPGriMMRP.xls\APGriMMRP$


>>> # or do this:
>>> tb = r'C:\TEMP\WritingGeometries\arekAPGriMMRP.xls\APGriMMRP$'

>>> print tb
C:\TEMP\WritingGeometries\arekAPGriMMRP.xls\APGriMMRP$
0 Kudos
ScottChang
New Contributor II
Hi Wayne,  Thanks for your nice response.

1) I corrected my mistake in tb = r"C:\TEMP\...\...xls\ApgRImmrpWGS$" as you pointed out. It worked and I got the right output and Map. But, in addition to ID, Pt_ID, X, Y, I saw there are  blank F5, F6 and F7 columns that appear in the Attribute Table also - see the attached file.   I don't know why they (i.e. blank F5, F6 and F7) appear in the Attribute Table. Can you tell me how I can avoid them to appear in the Attribute Table?

2) Can I use the .txt file for input of ID, Pt_ID, X, Y via tb = r"C:\TEMP\....txt\...?  If it can be done this way, please give me the detailed code statement for  tb = r"C:\TEMP\....txt\...

Please kindly help and respond again.

Thanks,
Scott Chang

P.S.  In doing "WritingGeometries" ArcPy-Python programming before, I used the following code blindly:
infile = r"C:\TEMP\WritingGeometries\WritingGeometries_12Points.txt"
I did/do not understand "infile" at all.  Could you please enlighten me on infile and its usage for me?
0 Kudos
T__WayneWhitley
Frequent Contributor
Looks to me like you've got 'extra' columns defined in your Excel worksheet for the table, even though they are blank....so when processing they automatically get written.  Change this by 'redefining' the range in Excel.  Also, I think an easy way is to define the print range which shows up as a separate 'table' in ArcGIS, so you can use that too.  Any questions, you can experiment with defining ranges in Excel to see how that in turn is read in ArcGIS...just be careful with file locking.

Anyway, looks like you are pretty much there with what I'd call successful output!
EDIT:  By the way, thanks to Arek for the provided code that answers your basic initial question.

If you want to use a text file instead, you can look into that later - not sure the tools such as Make XY Event Layer work as well (or directly) with text files.  Incidentally (if this is more convenient), as in 'intermediary' agent, you can use Excel to read native text data formatted in a saved xls (or xlsx, etc.) which in turn can be read directly by ArcGIS - no need to change the script you are now using.

As far as the 'infile' text file code in the sample, the reading of the file is done line by line using Python's methods from 'fileinput' module (not using arcpy's search cursor).  Going this route will involve dealing directly with the input file's structure, the delimiter used, parsing the strings into appropriate variables, etc.
0 Kudos
ScottChang
New Contributor II
Hi Wayne,
1) I went to the "Home" manu => clicked on "Clear" to delete F5, F6 and F7 columnns of my xls file. Then I saved it and I executed the Python script in the Python Window of my ArcGIS 10.0.  It worked and I got the right output without the blank F5, F6 and F7 columns in the Attribute Table.
2) I added a new column "Z" and the values for the 10 points.  Then I executed the newly revised script:
>>> # scMakeXYlayer.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 (Date:  31 Oct 2012)
... # import system modules 
... import arcpy
... from arcpy import env
... # Set environment settings
... # env.workspace = r"C:\TEMP\BS_Test.gdb"  # New!!!
...  
... try:
...     # Set the local variables
...     # in_Table = "firestations.csv"
...     tb = r"C:\TEMP\WritingGeometries\ApgRImmrpWGS.xls\ApgRImmrpWGS$"
...     xc = "X"
...     yc = "Y"
...     zc = "Z"
...     out_Layer = "Pointlocations_layer"
...     saved_Layer = r"c:\TEMP\APGriMMRPBHsWell.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)
...  
...     # 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!!!
... except:
...     # If an error occurred print the message to the screen
...     print arcpy.GetMessages()
... 
Executing: MakeXYEventLayer C:\TEMP\WritingGeometries\ApgRImmrpWGS.xls\ApgRImmrpWGS$ X Y Pointlocations_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: Wed Oct 31 13:31:34 2012
Failed to execute. Parameters are not valid.
ERROR 000725: Layer Name or Table View: Dataset Pointlocations_layer already exists.
Failed to execute (MakeXYEventLayer).
Failed at Wed Oct 31 13:31:34 2012 (Elapsed Time: 0.00 seconds)
>>> 


It did not work at all. I am lost now.  Please help and advise again.

Thanks,
Scott Chang
0 Kudos
ScottChang
New Contributor II
Hi Wayne,
I tried to use the right spRef=r"........\World\WGS 1984" and arcpy.MakeXYEventLayer_management(tb, xc, yc, zc, out_layer, spRef):
>>> # scMakeXYlayer.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 (Date:  31 Oct 2012)
... # import system modules 
... import arcpy
... from arcpy import env
... # Set environment settings
... # env.workspace = r"C:\TEMP\BS_Test.gdb"  # New!!!
...  
... 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, zc, 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)
...     arcpy.CopyFeatures_management(out_Layer, saved_Layer) # New!!!
... 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.
>>> 


I got the new errors: Errors 000622 & 000628!!!

Please help and advise again.

Thanks,
Scott Chang
0 Kudos