HOW TO
Beim Arbeiten mit Feature-Services in ArcGIS Online ist es nützlich, eine Kopie aller Feature-Services in ArcGIS Online als Sicherungskopie oder als Alternative bei Speicherplatzbeschränkungen zu erstellen. Das einzelne Herunterladen jedes Feature-Service kann recht zeitaufwendig sein, insbesondere bei großen Volumina. Das folgende Python-Skript ermöglicht dem Benutzer das Herunterladen einer Kopie aller Feature-Service-Elemente. Wenn der Prozess abgeschlossen ist, können diese Elemente gelöscht werden.
Das folgende Skript sucht nach Feature-Service-Elementen des Benutzers und exportiert sie als einzelne Datei im gewünschten Format. Wenn die Datei in ArcGIS Online erstellt wurde, kann sie an den Dateipfad, der im Download-Abschnitt des Skripts angegeben ist, heruntergeladen werden.
import arcgis from arcgis.gis import GIS
gis = GIS(None,'username', 'password', verify_cert=False)
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)
downloadUserItems('username', downloadFormat='Shapefile')
Nachfolgend finden Sie ein vollständiges Skript als Beispiel:
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.type), 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. Username and the type of download format
downloadUserItems('username', downloadFormat='Shapefile')
Die Funktion downloadUserItems verwendet zwei Parameter:
Hinweis : Für die Ausgabe gibt es mehrere Dateiformate. Einige davon sind: Shapefile (SHP), CSV, KML, FGDB, Feature-Sammlung.
Artikel-ID: 000018909
Unterstützung durch ArcGIS-Experten anfordern
Beginnen Sie jetzt mit dem Chatten