I'm attempting to automate some web map updates on ArcGIS Online through the use of the arcrest module. The following two methods are intended to act as the interface between local data sources and AGOL. The first of the two methods, "TruncateWebLayer" works as intended and removes all of the existing records from the specified feature layer. The second method, "AddFeaturesToWebLayer" always results in an error.
#This always works correctly
def TruncateWebLayer(agolID = '', lyrName = ''):
securityinfo = {}
securityinfo['security_type'] = 'Portal'
securityinfo['username'] = 'username'
securityinfo['password'] = 'password'
securityinfo['org_url'] = 'https://myportal.maps.arcgis.com'
securityinfo['proxy_url'] = None
securityinfo['proxy_port'] = None
securityinfo['referer_url'] = None
securityinfo['token_url'] = None
securityinfo['certificatefile'] = None
securityinfo['keyfile'] = None
securityinfo['client_id'] = None
securityinfo['secret_id'] = None
fst = featureservicetools.featureservicetools(securityinfo)
fs = fst.GetFeatureService(itemId=agolID,returnURLOnly=False)
fl = fst.GetLayerFromFeatureService(fs=fs,layerName=lyrName,returnURLOnly=False)
fst.DeleteFeaturesFromFeatureLayer(fl.url, '1=1')
#This always fails on the AddFeatures line
def AddFeaturesToWebLayer(addFeatures, agolID = '', lyrName = ''):
securityinfo = {}
securityinfo['security_type'] = 'Portal'
securityinfo['username'] = 'username'
securityinfo['password'] = 'password'
securityinfo['org_url'] = 'https://myportal.maps.arcgis.com'
securityinfo['proxy_url'] = None
securityinfo['proxy_port'] = None
securityinfo['referer_url'] = None
securityinfo['token_url'] = None
securityinfo['certificatefile'] = None
securityinfo['keyfile'] = None
securityinfo['client_id'] = None
securityinfo['secret_id'] = None
fst = featureservicetools.featureservicetools(securityinfo)
fs = fst.GetFeatureService(itemId=agolID,returnURLOnly=False)
fl = fst.GetLayerFromFeatureService(fs=fs,layerName=lyrName,returnURLOnly=False)
#This always fails..
fl.addFeatures(fc=addFeatures, attachmentTable=None)
#I've tried this too and it fails with the same error message because it references addFeatures also.
#fst.AddFeaturesToFeatureLayer(r'url to feature layer', addFeatures, chunksize=0, lowerCaseFieldNames=False)
The error message I always receive is as follows:
Traceback (most recent call last):
File "<string>", line 181, in <module>
File "<string>", line 74, in AddFeaturesToWebLayer
File "C:\xxxxx\xxxxx\xxxxx\xxxxx\xxxx\xxxx\site-packages\arcrest\agol\services.py", line 2330, in addFeatures
for chunk in chunks:
File "C:\xxxxx\xxxxx\xxxxx\xxxxx\xxxx\xxxx\site-packages\arcrest\agol\services.py", line 1972, in _chunks
l.sort()
TypeError: '<' not supported between instances of 'dict' and 'dict'
This looks like the error has something to do with sorting of the chunk dictionaries in the the services.py module. I cannot make sense of this. Is this maybe not the correct method for doing what I'm intending it to do? I have noticed that running these methods from an ArcGIS Pro session and replacing the addFeatures line with an arcpy.append_management works and everything gets uploaded to the web layer, however, it takes an very long time when dealing with feature layers with thousands of records.