方法

ArcGIS API for Python を使用して ArcGIS Online からフィーチャ サービス アイテムをダウンロードする

Last Published: October 17, 2022

サマリー

ArcGIS Online でフィーチャ サービスを操作しているときに、すべてのフィーチャ サービスのコピーを作成すると、バックアップとして、または格納領域に制限がある場合に、役立ちます。 各フィーチャ サービスを個別にダウンロードするのは、特に量が多い場合に、時間がかかる可能性があります。 次の Python スクリプトを使用して、すべてのフィーチャ サービス アイテムのコピーをダウンロードできます。 それらのアイテムは、処理の完了後に安全に削除できます。

手順

次のスクリプトは、ユーザーのフィーチャ サービス アイテムの検索を実行し、アイテムを単一ファイルとして目的の形式でエクスポートします。 ArcGIS Online でファイルを作成した後に、そのファイルを、スクリプトのダウンロード セクションで指定したファイル パスにダウンロードできます。

  1. Python で、必要なライブラリをインポートします。
import arcgis from arcgis.gis import GIS
  1. ログイン認証情報を定義します。
gis = GIS(None,'username', 'password', verify_cert=False)
  1. ダウンロード形式および特定の出力ファイル パスを定義します。
def downloadUserItems(owner, downloadFormat): try: # Search items by username items = gis.content.search('owner:{0}'.format(owner)) print(items) # Loop through each item and if equal to Feature service then download it for item in items: if item.type == 'Feature Service': result = item.export('sample {}'.format(item.type), downloadFormat) result.download(r'file path of where to store the download')   # Delete the item after it downloads to save space (OPTIONAL)   result.delete() except Exception as e: print(e)
  1. 生成されたファイルをダウンロードします。
downloadUserItems('username', downloadFormat='Shapefile')

以下に、完全なサンプル スクリプトを示します。

import arcgis from arcgis.gis import GIS gis = GIS(None,'username', 'password', verify_cert=False) # Download all data from a user def downloadUserItems(owner, downloadFormat): try: # Search items by username items = gis.content.search('owner:{0}'.format(owner)) print(items) # Loop through each item and if equal to Feature service then download it for item in items: if item.type == 'Feature Service': result = item.export('sample {}'.format(item.title), downloadFormat) result.download(r'file path of where to store the download')   # Delete the item after it downloads to save on space   result.delete() except Exception as e: print(e) # Function takes in two parameters. ユーザー名およびダウンロード形式のタイプ downloadUserItems('username', downloadFormat='Shapefile')

downloadUserItems 関数は、次の 2 つのパラメーターを受け取ります。

  • owner[string] - ユーザー名
  • downloadFormat[string] - ダウンロードの出力ファイルの形式
注意: 出力のファイル形式は、シェープファイル (SHP)、CSV、KML、ファイル ジオデータベース、フィーチャ コレクションなど、複数ありますが、これらに限定されません。 「ArcGIS API for Python の API リファレンス」を参照して、エクスポート方法まで下にスクロールしてください。

記事 ID:000018909

ArcGIS の専門家からヘルプを受ける

テクニカル サポートへのお問い合わせ

Esri Support アプリのダウンロード

ダウンロード オプションに移動

関連情報

このトピックについてさらに調べる