python - 如何在 Python 中向值表 (ArcPy) 添加行?

标签 python arcgis arcpy arcmap

我正在学习如何使用 Python 创建在 ArcMap (10.1) 中运行的脚本。 下面的代码让用户选择 shapefile 所在的文件夹,然后遍历 shapefile 以创建仅包含以“landuse”开头的那些 shapefile 的值表。

我不确定如何向值表添加行,因为这些值是在参数中选择的,并且文件夹不能直接放入代码中。请参阅下面的代码...

#imports
import sys, os, arcpy 

#arguments
arcpy.env.workspace = sys.argv[1] #workspace where shapefiles are located

#populate a list of feature classes that are in the workspace
fcs = arcpy.ListFeatureClasses()

#create an ArcGIS desktop ValueTable to hold names of all input shapefiles
#one column to hold feature names
vtab = arcpy.ValueTable(1)

#create for loop to check for each feature class in feature class list
for fc in fcs:
    #check the first 7 characters of feature class name == landuse
    first7 = str(fc[:7])
    if first7 == "landuse":
        vtab.addRow() #****THIS LINE**** vtab.addRow(??)

最佳答案

for循环中,fc将是列表fcs中每个要素类的字符串名称。因此,当您使用 addRow 方法时,您将传递 fc 作为参数。

下面是一个可能有助于澄清的示例:

# generic feature class list
feature_classes = ['landuse_a', 'landuse_b', 'misc_fc']

# create a value table
value_table = arcpy.ValueTable(1)

for feature in feature_classes:       # iterate over feature class list
    if feature.startswith('landuse'): # if feature starts with 'landuse'
        value_table.addRow(feature)   # add it to the value table as a row

print(value_table)

>>> landuse_a;landuse_b

关于python - 如何在 Python 中向值表 (ArcPy) 添加行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24051793/

相关文章:

python - 如何使用crawlspider跳转到下一页?

python - Openstack python-novaclient

javascript - 单击要素图层上的图形对象时,有没有办法禁用突出显示边界?

python - python中的字符串只接受字母数字字符和下划线

python - 无法为 arcpy 中的给定多边形输入选择图层

python - 从 NumPy 数组创建光栅图像

python - 在 Vim 中键入时如何获得数组选项的自动建议?

python - 使用 python 访问 Outlook 文件夹

javascript - ESRI/ArcGIS : "Error: Services Directory has been disabled."

python - 初学者网络 GIS 制图