2

ArcGIS工具 - 统计工具数量 - 为源地理

 1 year ago
source link: https://www.cnblogs.com/wygeo/p/17038463.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ArcGIS工具 - 统计工具数量

ESRI作为GIS行业中的龙头,代表产品ArcGIS也在不断地优化和升级,从10.0开始已发布了8个版本,其工具箱(ToolBox)是它一个特色,每个版本的工具箱数量是不相同的,为源地理来教您如何统计工具箱和工具个数和名称。

使用统计工具数量工具,可统计ArcMap中默认的工具箱和工具个数。工具界面如下:

img

如果不设置路径,仅输出日志。

img

如果设置输出文件路径,则可输出当前版本的工具箱和工具全部名称。

img

统计工具数量工具的完整代码如下:

# -- coding:cp936 --
# ---------------------------------------------------------------------------
# 名称:PrintToolCount
# 功能:统计ArcMap中默认的工具箱和工具个数。
# 作者:为源地理
# 日期:2023.1.5
# 支持:wygis2022 1811335143
# 说明:同一软件版本,如果安装了其他扩展模块,统计的结果可能不同。
# ---------------------------------------------------------------------------

from imp import reload
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
import codecs
import csv
import arcpy

try:
    # 参数1:输出CSV文件
    csv_file = arcpy.GetParameterAsText(0)

    f = None
    if len(csv_file) != 0:
        f = codecs.open(csv_file, 'w','utf_8_sig')
        csv_writer=csv.writer(f)
        
        # 写入标题行
        title=['工具箱名称','工具箱简称','工具名称']
        csv_writer.writerow(title)
    
    # 获取当前版本
    version= u"当前版本"
    infos = arcpy.GetInstallInfo()
    for key,value in infos.items():
        if key=="Version":
           version=  u"ArcMap{}".format(value)

    # 工具箱和工具数量统计
    toolboxes = arcpy.ListToolboxes()
    tools = arcpy.ListTools()
    arcpy.AddMessage(u"=========================")
    arcpy.AddMessage(u"{}共有{}个工具箱、{}工具。".format(version,len(toolboxes),len(tools)))
    arcpy.AddMessage(u"=========================")

    # 工具箱数量统计
    toolbox_dic={}
    arcpy.AddMessage(u"工具箱:")
    for toolbox in toolboxes:
        first=toolbox.index("(") 
        last = toolbox.index(")")
        toolboxName=toolbox[0:first]
        toolboxAlias=toolbox[first+1:last]
        toolbox_dic[toolboxAlias] =toolboxName 
        arcpy.AddMessage(u"工具箱:{0},别名:{1}".format(toolboxName,toolboxAlias))
    
    # 工具数量统计
    arcpy.AddMessage(u"工具:")
    for tool in tools:
        first=tool.index("_")
        toolName=tool[0:first]
        toolAlias=tool[first+1:]
        if toolAlias in toolbox_dic:
            arcpy.AddMessage(u"{}:{}".format(toolbox_dic[toolAlias],toolName))
            if len(csv_file) != 0:
                result=[toolbox_dic[toolAlias],toolAlias,toolName]
                csv_writer.writerow(result)
        else:
            arcpy.AddMessage(u"未知工具箱:{}".format(toolName))
            if len(csv_file) != 0:
                result=[u"未知工具箱","",toolName]
                csv_writer.writerow(result)
except arcpy.ExecuteError: 
    arcpy.AddError(arcpy.GetMessages(2))    
except: 
    e = sys.exc_info()[1]
    arcpy.AddError(e.args[0])  

不同的人对版本需求和认识不同,下面仅代表我个人的观点:

  • 9.3:非常稳定,经典,英文版,有中文补丁,但淘汰;
  • 10.0:第一个中文版,最不稳定;
  • 10.2.2:功能全面,性能稳定,比较普遍之一;
  • 10.4:不太稳定。
  • 10.8:最后一个版本,不再有ArcMap10.9,解决了高分辨率屏显示、标注窗口卡顿问题;
  • Pro:全新的64位架构,话说会取代Desktop,但这个时间可能会有点久。就像CAD都出2023了,还是有人在使用CAD 2007.

如果项目使用推荐:10.2.2 > 10.8 > 10.1

如果学生使用推荐:10.8 、 Pro


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK