Python error: "Method RasterFieldName does not exist"

535
4
07-29-2010 05:55 AM
KateParks
New Contributor II
Hi,

I'm trying to write a python script that will print the name of a raster dataset to screen. I copied the example code from the Desktop Help and changed the raster object to match the path to my dataset:

import arcgisscripting
gp = arcgisscripting.create()

raster = "C:\data_all\AltLatGrids\ArcGISGrids\alb8__22"

# Create a describe object
#
desc = gp.Describe(raster)

# Print the RasterFieldName property
#
print desc.RasterFieldName

When I ran the script I received the error message "Method RasterFieldName does not exist". I am using ArcGIS 9.3 with an ArcInfo license, and Python 2.5.4.

Any help gratefully received!
Kate.
0 Kudos
4 Replies
GerryGabrisch
Occasional Contributor III
Python is backslash sensitive.  Try:

raster = "C:\\data_all\\AltLatGrids\\ArcGISGrids\\alb8__22"

or

raster = r"C:\data_all\AltLatGrids\ArcGISGrids\alb8__22"
0 Kudos
KateParks
New Contributor II
I tried both of those, but still get the same error. 

Out of interest, what does the 'r' before your second suggestion do?
0 Kudos
GerryGabrisch
Occasional Contributor III
Ah,
RasterFieldName is not returning the name of the raster it returns the name of a field in a raster catalog.  See

http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=1053&pid=980&topicname=Raster_Catalog_propert...

Try this

import arcgisscripting
gp = arcgisscripting.create()
raster = r"C:\Temp\lidar"
# Create a describe object
desc = gp.Describe(raster)
# Print the name of the raster
print desc.Name

Backslashes are special characters, for example
print "Foo\nbar"  would print
foo
bar
to the screen.  The r sets the string to a raw string so r"Foo\nbar" would print
Foo\nbar
0 Kudos
KateParks
New Contributor II
Thanks a lot for your help, that works now.
0 Kudos