操作方法

操作方法:在 ArcGIS Online 或 Portal for ArcGIS 中计算托管要素图层中附件的总大小

Last Published: January 18, 2024

描述

在发布到 ArcGIS Online 或 Portal for ArcGIS 之前,可以在 ArcGIS Pro 中将附件添加至图层,如以下文档 ArcGIS Pro:添加或移除文件附件中所述。 当图层包含多个附件时,手动计算这些附件的总大小可能会比较繁琐。 此外,考虑到在磁盘中、发布期间以及从字节转换到千字节时的不同大小,总大小可能会有所不同。 本文提供了在独立 Python 脚本或者 ArcGIS Notebooks 中使用 ArcGIS API for Python 来计算总大小的步骤。

解决方案或解决方法

  1. 导入所需的模块。
import arcgis
from arcgis import GIS
import pandas as pd
  1. 连接到 ArcGIS Online 或 Portal for ArcGIS。
#For ArcGIS Online
gis = GIS('https://arcgis.com', 'username', 'password')
print("Connected")

#For Portal for ArcGIS
gis = GIS('https://<machine>.<domain>/<web adaptor name>', 'username', 'password', verify_cert=False)
print("Connected")
  1. 根据托管要素图层 ID 获取所需图层。
item = '<item_ID>'
layer = gis.content.get(item)
ids = layer.layers[0]
fs = ids.query(where="1=1")
oids = [f.attributes["OBJECTID"] for f in fs.features]
Note:
Edit the index value in 'ids = item.layers[0]' based on the layers that hold the attachments. For example, to calculate the total attachment size in the second layer, replace 0 with 1 in the code.
  1. 打印所有带有附件的属性。
attached = [ids.attachments.get_list(oid=oid) for oid in oids]
print(attached)
  1. 计算附件的总大小并将其显示在结果控制台中。
print("Total size: " + str(ids.attachments.search(as_df=True)['SIZE'].sum()))

#If additional word is unnecessary, the following line can be used:
print(ids.attachments.search(as_df=True)['SIZE'].sum())

以下是一个工作示例脚本和结果控制台。 计算的文件大小以字节为单位。

import arcgis
from arcgis import GIS
import pandas as pd

gis = GIS('https://arcgis.com', 'user1', 'password1!')
print("Connected")

item = '80d00e2301844ou2435p9284fu87bf'
layer = gis.content.get(item)
ids = layer.layers[0]
fs = ids.query(where="1=1")
oids = [f.attributes["OBJECTID"] for f in fs.features]

attached = [ids.attachments.get_list(oid=oid) for oid in oids]
print (attached)

print("Total size: " + str(ids.attachments.search(as_df=True)['SIZE'].sum()))
结果控制台显示了附件的总大小

文章 ID: 000031782

获得人工智能支持

使用 Esri Support AI Chatbot 快速解决您的问题。

立即开始聊天

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

立即开始聊天

转至下载选项