Friday, 13 February 2015

arcpy - Adding data to a feature layer on ArcGIS Online using arcrest and arcresthelper.featureservicetools?


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 "", line 181, in
File "", 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.



Answer



I was using an outdated method for adding features to the portal. After leveraging the new ArcGIS Python API, adding items to the portal and publishing them worked fine. This involved understanding that the old ArcRest module and ArcRestHelper module are essentially now built into the new API where everything is handled under the arcgis.gis.GIS object.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...