0

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.

  • 1
    What is your version of Python? Python 3 'tightened' the requirements on comparisons with such operators as '<', so that l.sort on objects in the chunking method chokes. Use Python 2.x if you can....or upgrade to the new ArcGIS Python API. – T. Wayne Whitley Jan 8 at 0:29
  • 1
    I'm using Python 3. After your comment and some research it definitely seems like the ArcGIS Python API is the best and most current approach. – GeoJohn Jan 8 at 18:05
2

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.

  • You should mark your own answer as The Answer. – T. Wayne Whitley Jan 9 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.