首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:“NoneType”对象不可迭代。(arcpy.ListFeatureClasses)

TypeError:“NoneType”对象不可迭代。(arcpy.ListFeatureClasses)
EN

Stack Overflow用户
提问于 2014-02-26 02:40:39
回答 1查看 2.2K关注 0票数 0

我正在尝试将任何未知的投影形状文件更改为"NAD 1983 Alaska Albers“投影。

代码语言:javascript
复制
# 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()
EN

回答 1

Stack Overflow用户

发布于 2014-03-07 03:55:05

函数arcpy.ListFeatureClasses()提供当前工作空间(可以使用arcpy.env.workspace获取或设置)中所有要素类的列表。它不需要任何参数,除非您希望使用通配符、要素类型或特定的地理数据库要素数据集来过滤结果。如果引用help,您将看到传递给ListFeatureClasses的参数与它的参数不对齐。这就是为什么它返回None,而您的for语句不能遍历None。如果你不需要做任何过滤,这是可行的:

代码语言:javascript
复制
arcpy.env.workspace = 'C:/Users/Elvis/Desktop/Spring/Geog376/Lab03/erase'
for infc in arcpy.ListFeatureClasses():

如果您只想迭代三个特定的数据集,那么只需显式地设置它们(您仍然可以使用工作区环境来避免键入完整的路径名):

代码语言:javascript
复制
arcpy.env.workspace = 'C:/Users/Elvis/Desktop/Spring/Geog376/Lab03/erase'
for infc in ['2004perimeters', 'AK_tundra', 'AK_taiga']:

ListFeatureClasses函数也不属于对项目的调用。此外,似乎Project工具并不是您所需要的工具。投影工具可将数据从一个坐标系投影到另一个坐标系。相反,请看一下Define Projection工具。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22023278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档