2

I tried to run a python script for getting the coordinate system of a feature/shapefile as follow

>>> import arcpy  
>>> from arcpy import env  
>>> env.workspace="D:\data"  
>>> fc="river.shp"  
>>> dsc=arcpy.Describe(fc)  
>>> dsc.spatialReference.Name  
>>> print dsc  

i'm getting following error at line 5

Attributeerror:'NoneType' object has no attribute Name.

1 Answer 1

2

Replacing this line:

env.workspace="D:\data"

with:

env.workspace=r"D:\data"

or

env.workspace="D:/data"

or

env.workspace="D:\\data"

should enable it to work but, if you are using ArcGIS 10.1 like me, you will also need to use ".Name" without the capital i.e. ".name".

My working test code:

import arcpy
from arcpy import env
env.workspace=r"C:\temp"
fc="test2.shp"
dsc=arcpy.Describe(fc)
print dsc.spatialReference.name

returns this (as expected):

GCS_GDA_1994

6
  • I tried in that way also, but no change in error Commented Jul 5, 2013 at 11:15
  • Does your shapefile have a *.prj ? An undefined coordinate system would probably explain the error you are seeing which I do not.
    – PolyGeo
    Commented Jul 5, 2013 at 11:19
  • yes it had .prj file. if i tried to run the above code i'm getting an Attributeerror that: 'NoneType' object has no attribute 'Name' Commented Jul 5, 2013 at 11:29
  • if the shapefile does not have a .prj file associated with it, dsc.spatialReference.name should return "Unknown". Check that the path to your data is referenced correctly.
    – Nxaunxau
    Commented Jul 5, 2013 at 11:31
  • 1
    You have Name when it should be name - case sensitive.
    – PolyGeo
    Commented Jul 5, 2013 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.