操作方法
在发布到 ArcGIS Online 或 Portal for ArcGIS 之前,可以在 ArcGIS Pro 中将附件添加至图层,如以下文档 ArcGIS Pro:添加或移除文件附件中所述。 当图层包含多个附件时,手动计算这些附件的总大小可能会比较繁琐。 此外,考虑到在磁盘中、发布期间以及从字节转换到千字节时的不同大小,总大小可能会有所不同。 本文提供了在独立 Python 脚本或者 ArcGIS Notebooks 中使用 ArcGIS API for Python 来计算总大小的步骤。
import arcgis from arcgis import GIS import pandas as pd
#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")
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.
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()))
#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
获取来自 ArcGIS 专家的帮助
立即开始聊天