こんにちは!ホスト フィーチャ レイヤーに Trees と RemovedTrees という2つのレイヤーがあります。AGOL Notebooks(Python 3 Standard-14.0)で、Trees レイヤーから削除済みとしてマークされた樹木を検索し、RemovedTrees レイヤーにコピーするスクリプトを作成しようとしています。
添付ファイル以外は動作しています。添付ファイルもコピーしたいのですが、スクリプトを実行すると正常に完了するようで、RemovedTrees レイヤーを確認するとコピーされたフィーチャに添付ファイルが表示されますが、実際の画像はありません。
Python はまだ勉強を始めたばかりで、特に AGOL 環境には不慣れです。添付ファイルについて見つけられる情報はすべて読みましたが、かえって混乱してしまいました。
これを実現する方法について、何かアドバイスをいただけると助かります。ありがとうございます!
コードはこちらです:
from arcgis.gis import GIS
gis = GIS("home")
trees_layers = gis.content.get('383df5bd920f4a6fb12cd475042923c7')
# Trees レイヤーにアクセス
treeslyr = trees_layers.layers[0]
# RemovedTrees レイヤーにアクセス
removedTreeslyr = trees_layers.layers[1]
# Trees レイヤーから削除済みとしてマークされた樹木の FeatureSet を作成
treeslyr_fset = treeslyr.query(where= "Condition = 'Removed'", return_geometry=True)
# FeatureSet からフィーチャのリストを作成
feat_list = treeslyr_fset.features
# 各フィーチャの添付ファイルを格納する変数
attachments_adds = []
for feature in feat_list:
source_guid = feature.get_value("GlobalID")
if not source_guid:
continue
source_oid = feature.get_value("OBJECTID")
if source_oid is None:
continue
source_attachments = treeslyr.attachments.get_list(oid=source_oid)
for att in source_attachments:
attachments_adds.append(
{
"globalId": att.get("globalId"),
"parentGlobalId": source_guid,
"name": att.get("name"),
"contentType": att.get("contentType"),
"attachmentId": att.get("id")
}
)
add_result = removedTreeslyr.edit_features(
adds=treeslyr_fset,
use_global_ids=True,
rollback_on_failure=False,
attachments={"adds": attachments_adds}
)
add_result
Trees と RemovedTrees では添付ファイルが有効になっています。
supportsApplyEditsWithGlobalIds は True です。