Select to view content in your preferred language

Overwriting several ArcGIS Online layers with python?

1065
1
10-07-2016 01:12 AM
unica360
Deactivated User

How can I update my layers in ArcGIS Online using Python?

From the platform I can upload one to one by overwrite tool. However, I'd like to know if there is some way by python to automate this task. At first, I've tried to update a shapefile in this way, but I want to update several shapefiles:

from arcgis.gis import *gis = GIS("url", "username", "password")data = "C:\\xc\\Data\SDs\\states_21basic.zip"shpfile = gis.content.add({}, data)

and then to publish it:

shpfile.publish()
0 Kudos
1 Reply
unica360
Deactivated User
Using this code, I managed to upgrade the different attributes containing my feature service, but not update the feature layer.
In the data_path, I've written the path where the file is updated. However, when I run the code does not update the layer.

from arcgis.gis import *
gis = GIS("url", "username", "password")
data = "C:\\xc\\Data\\Shps\\states_21basic.zip"
shpfile = gis.content.add({}, data)
#and then to publish it:
shpfile.publish()

shpPublisher = "url my service"
shpPublisher = gis.content.search('states_21basic')[0]
shpPublisher

#Now I'd like to update my feature service
data_path = "C:\\xc\\Data\\Shps_Update\\states_21basic.zip"
item_properties = {
 "description":"Change description",
 "title":"states_21basic", #the same title
 "tags":"hello, byebye",
 "type":"shapefile",
 "typeKeywords":"shapefile",
 "data":"file/zip"
 }
shpPublisher.update(item_properties, data=data_path)
display(shpPublisher)
0 Kudos