当前位置:   article > 正文

【ArcGIS自定义脚本工具】批量导出栅格属性表_raster to geodatabase

raster to geodatabase

一、功能介绍1-1

二、脚本代码
大部分代码引用自https://www.cnblogs.com/geozho/p/10167957.html

# -*- coding: utf-8 -*-

import arcpy
import os

# Script arguments
in_rasters = arcpy.GetParameterAsText(0)
in_dbf = arcpy.GetParameterAsText(1)
out_csv = arcpy.GetParameterAsText(2)
arcpy.AddMessage(in_rasters)
# Local variables:
out_dbf = in_rasters
arcpy.RasterToGeodatabase_conversion(in_rasters, in_dbf, "")

ws = in_dbf
arcpy.env.workspace = ws
rasters = arcpy.ListRasters("*")
for raster in rasters:
    rasloc = ws + os.sep + raster
    fields = "*"
    try:
        lstFlds = arcpy.ListFields(rasloc)
        header = ''
        header += ",{0}".format(lstFlds[0].name)+",{0}".format(lstFlds[1].name)
        if len(lstFlds) != 0:
            f = open(out_csv, 'a')
            header = header[0:] + ',RasterName\n'
            f.write(header)
            with arcpy.da.SearchCursor(rasloc, fields) as cursor:
                for row in cursor:
                    f.write(str(row).replace("(", "").replace(")", "") + "," + raster + '\n')
            f.close()
    except Exception as e:
        print (e)
del row
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

三、工具参数
3-1
3-2
新建一个地理数据库步骤如下图:
3-3
四、工具界面
4-1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/310594
推荐阅读
相关标签
  

闽ICP备14008679号