Describe().SpatialReference.Name with period in file name

577
4
03-09-2011 07:59 AM
DanWakefield1
New Contributor II
Hello,

I'm running ArcGIS 9.3.1 and I have a shapefile with a period in the name, such as "Test.2.shp", which I can not use Describe to get the projection for. When I try to use gp.Describe('Test.2.shp').SpatialReference.Name, I get the error "RuntimeError: DescribeData: Method SpatialReference does not exist."

Here is my code:

import arcgisscripting, sys

gp = arcgisscripting.create(9.3)
gp.SetProduct("ArcInfo")
gp.workspace = 'D:/Temp'

print 'Test1.shp Name: '+gp.Describe('Test1.shp').Name
print 'Test.2.shp Name: '+gp.Describe('Test.2.shp').Name

print 'Test1 Prj: '+gp.Describe('Test1.shp').SpatialReference.Name
print 'Test.2 Prj: '+gp.Describe('Test.2.shp').SpatialReference.Name


And this is the result from the command line:

Test1.shp Name: Test1.shp
Test.2.shp Name: Test.2.shp
Test1 Prj: NAD_1983_StatePlane_Illinois_East_FIPS_1201
Traceback (most recent call last):
  File "D:\Temp\test.py", line 11, in <module>
    print 'Test.2 Prj: '+gp.Describe('Test.2.shp').SpatialReference.Name
RuntimeError: DescribeData: Method SpatialReference does not exist


Both Test1.shp and Test.2.shp have the same projection. Am I doing something wrong, or does anyone have a suggestion for me? I'd prefer not to have to rename the files.

Thanks,
Dan
Tags (2)
0 Kudos
4 Replies
ChrisSnyder
Regular Contributor III
Generally speaking:

1) Only name GIS datasets using letters, numbers, or an "_".
2) Always start the name (database names, rasters, featureclasses, field names too!, etc.) with a letter (not a number or an underscore).
3) Avoid spaces and special characters (such as a ".", "&", "#", etc.).
4) If you can help it, keep names <= 10 characters. There are many exceptions of course, but...

I have followed these four basic rules for 12 years, and have never gone wrong. Sorry, but I think you will have to rename your shapefile to get this to work (maybe reformat to a FGDB, and the "." may be supported in that format?).
0 Kudos
ChrisSnyder
Regular Contributor III
Did you try making a feature layer from the unfortunately-named shapefile and then try the describe on that?

For example:

fc = r"C:\temp\test.badname.shp"
gp.MakeFeatureLayer(fc,"fl")
dscObj = gp.describe("fl")
srObj = dscObj.spatialreference
print srObj.name
0 Kudos
DanWakefield1
New Contributor II
Chris,

Thanks for the help. I tried making the the shapefile into a layer,

gp.MakeFeatureLayer('D:/Temp/Test.2.shp','t2')


and received this:
ERROR 000732: Input Features: Dataset D:/Temp/Test.2.shp does not exist or is not supported


I think my best bet is going to be to rename the offending files.

Thanks for the help,
Dan
0 Kudos
ChrisSnyder
Regular Contributor III
Hmm...

Another option (assuming this works), would be to temporarily rename the shapefile (use the Rename tool), use the describe, and then rename it back.

Yet another option: There is a .prj file that accompanies the .shp (assuming there is a defined projection). Instead of using the describe method directly, maybe just have Python look for/read the .prj file. The prj string can then be loaded into a SR object using the "loadFromString" method.
0 Kudos