2014-02-25 97 views
0

我試圖將任何未知的投影形狀文件更改爲 「NAD 1983阿拉斯加阿爾伯斯」投影。TypeError:'NoneType'對象不可迭代。 (arcpy.ListFeatureClasses)

# import arcypy and from arcpy, import os to change directory 
import arcpy 
from arcpy import os 

# set working directory to workspace 
os.chdir('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase') 

# Copy all dataset in working directory ###Need to change this back into my s drive 
arcpy.CopyFeatures_management('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/lab03_data/2004 _af.shp','C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase/2004_af.shp') 
arcpy.CopyFeatures_management('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/lab03_data/2004perimeters.shp','C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase/2004perimeters.shp') 
arcpy.CopyFeatures_management('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/lab03_data/AK_tundra.shp','C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase/AK_tundra.shp') 
arcpy.CopyFeatures_management('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/lab03_data/AK_taiga.shp','C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase/AK_taiga.shp') 

# find what projection 2004_af.shp, 2004perimets.shp, AK_tundra, and AK_taiga.shp 
# change the projections to the correct one (2004_af.shp) 

# 2004_af.shp 
desc_af =  arcpy.Describe('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase/2004_af.shp') 
sr_af = desc_af.spatialReference 
print "projection name: "+sr_af.PCSname 


# 2004perimeters.shp 
desc_perimeters = arcpy.Describe('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase/2004perimeters.shp') 
sr_perimeters = desc_perimeters.spatialReference 
print "projection name: "+sr_perimeters.PCSname 

# AK_tundra.shp 
desc_tundra = arcpy.Describe('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase/AK_tundra.shp') 
sr_tundra = desc_tundra.spatialReference 
print "projection name: "+sr_tundra.PCSname 

# AK_taiga.shp 
desc_taiga = arcpy.Describe('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase/AK_taiga.shp') 
sr_taiga = desc_taiga.spatialReference 
print "projection name: "+sr_taiga.PCSname 


# Here is where I got an error: arcpy.ListFeatureClasses 

for infc in arcpy.ListFeatureClasses('2004perimeters', 'AK_tundra', 'AK_taiga'): 
    desc = arcpy.Describe(infc) 
    if desc.spatialReference.PCSname == "Unknown": 
     outfc = os.path.join('C://Users/Elvis/Desktop/Spring/Geog376/Lab03/erase', infc) 
     # Set output coordinate system 
     outcs = arcpy.SpatialReference('NAD 1983 Alaska Albers') 
     # run project tool 
     arcpy.Project_management(arcpy.ListFeatureClasses(infc, outfc, outcs)) 
     # check messages 
     print arcpy.GetMessages() 

回答

0

功能arcpy.ListFeatureClasses()提供當前工作空間中的所有要素類(你可以得到或使用arcpy.env.workspace設置)的列表。除非要使用通配符,要素類型或特定地理數據庫要素數據集過濾結果,否則不需要任何參數。如果您參考help,則會看到您傳遞給ListFeatureClasses的參數與其參數不匹配。這就是爲什麼它返回None,並且您的for語句不能遍歷None。如果你不需要做任何過濾,這將工作:

arcpy.env.workspace = 'C:/Users/Elvis/Desktop/Spring/Geog376/Lab03/erase' 
for infc in arcpy.ListFeatureClasses(): 

如果你只是想遍歷三種特殊的數據集,然後只將它們明確(你仍然可以使用工作區環境保存自己從鍵入完整路徑名稱):

arcpy.env.workspace = 'C:/Users/Elvis/Desktop/Spring/Geog376/Lab03/erase' 
for infc in ['2004perimeters', 'AK_tundra', 'AK_taiga']: 

ListFeatureClasses函數也不屬於對Project的調用。此外,無論如何,這似乎並不是項目工具所需要的。 Project工具將數據從一個座標系投影到另一個座標系。相反,看看Define Projection工具。