Select to view content in your preferred language

Python API add multiple typeKeywords

2539
7
11-24-2016 01:45 AM
by Anonymous User
Not applicable

Hi,

I am trying the ArcGIS Python API. What I want to achieve is to create copies of ArcGIS Online maps, and update filters for different users for use in Collector. Part one works, but getting the map appear in Collector does now work. A map in ArcGIS needs one of the typeKeywords to be 'Collector' and I need the keyword 'Offline' there as well so users can use the download and sync functionality (Which is the same as the 'Enable offline mode.' tickbox in the map settings in ArcGIS online). 

My script is copied and adapted from the example: Clone Portal Users, Groups and Content | ArcGIS for Developers

The problem I have, is that the typeKeywords of the original map are not copied correctly to the new maps. The typeKeywords of the original and copied map are: 

print(sourceMap.typeKeywords)

['ArcGIS Online', 'Collector', 'Data Editing', 'Explorer Web Map', 'Map', 'Offline', 'Online Map', 'Web Map']

print(targetMap.typeKeywords)

["'Collector'", "'Data Editing'", "'Explorer Web Map'", "'Map'", "'Offline'", "'Online Map'", "'Web Map']", "['ArcGIS Online'", 'ArcGIS Online', 'Explorer Web Map', 'Map', 'Online Map', 'Web Map']

This list of keywords is a mess, and the resulting map does not show in Collector. 

I can partly solve the problem by setting a single extra typeKeyword as follows:

targetMap.update({'typeKeywords': 'Collector'})

print(targetMap.typeKeywords)

['ArcGIS Online', 'Collector', 'Explorer Web Map', 'Map', 'Online Map', 'Web Map']

This adds the Collector keyword successfully and the map shows up in Collector, but cannot be synced. If I add the additional Offline keyword the same way, the Collector keyword is removed and I can't use the map in Collector:

targetMap.update({'typeKeywords': 'Collector'})

targetMap.update({'typeKeywords': 'Offline'})

print(targetMap.typeKeywords)

['ArcGIS Online', 'Explorer Web Map', 'Map', 'Offline', 'Online Map', 'Web Map']

If I add them in one command, I end up with faulty typeKeywords and the map is not available in Collector:

targetMap.update({'typeKeywords': ['Collector', 'Offline']})

print(targetMap.typeKeywords)

["'Offline']", "['Collector'", 'ArcGIS Online', 'Explorer Web Map', 'Map', 'Online Map', 'Web Map']

How do I add both Collector and Offline keywords without destroying the typeKeywords field? (Or how do I copy typeKeywords successfully?) 

0 Kudos
7 Replies
NeilAyres
MVP Alum

Have you tried something like :

targetMap['typeKeywords'].append(['Collector', 'Offline'])
0 Kudos
by Anonymous User
Not applicable

Thanks for the suggestion Neil. I tried this, but unfortunately it does not solve the problem. It adds the keywords to the item in Python, but after updating the map in ArcGIS online the extra keyword is dropped again. 

targetMap.typeKeywords.append('Offline')
print(targetMap.typeKeywords)
['ArcGIS Online', 'Collector', 'Explorer Web Map', 'Map', 'Online Map', 'Web Map', 'Offline']
targetMap.update()
print(targetMap.typeKeywords)
['ArcGIS Online', 'Collector', 'Explorer Web Map', 'Map', 'Online Map', 'Web Map']
0 Kudos
NeilAyres
MVP Alum

My original should be :

targetMap['typeKeywords'].extend(['Collector', 'Offline'])

Where you are adding to the list in the dict key "typeKeywords".

But you are saying that the targetMap object doesn't "remember" these settings.

Are these settings read/write or only read?

0 Kudos
by Anonymous User
Not applicable

The keywords are successfully added to the targetMap object, using either extend or append two times, that part works. But the added keywords are are lost when pushing the changes to ArcGIS online with the update() command. This part could be intended as the documentation does not suggest this approach, but it was worth trying.

Interestingly, adding the a new keyword is no problem using the recommended / documented command targetMap.update({'typeKeywords': 'Offline'}). The problem is that a second addition is not stored.

Using one command for two keywords, targetMap.update({'typeKeywords': [ 'Offline', 'Collector']}), results in a mess (as shown in opening post).

0 Kudos
by Anonymous User
Not applicable

Wouter Marra, can you verify if your web map meets all the data requirements specified in this Collector for ArcGIS documentation. Further, if you want to use sync capability in Collector, at least one of your feature layers should have the 'sync' capability enabled.

0 Kudos
by Anonymous User
Not applicable

Wouter Marra‌ in addition to the requirements in the previous comment, the typeKeywords need to be added as a comma separated string. Hence in your case, you need to add it as

 'ArcGIS Online, Explorer Web Map, Map, Offline, Online Map, Web Map, Collector'
You can write your update code as
webmap_item.update({'typeKeywords':
                    'ArcGIS Online, Explorer Web Map, Map, Offline, Online Map, Web Map, Collector'})
PeterKnoop
MVP Regular Contributor

While get_data() returns a list for the typeKeywords property, update() is expecting it to be provided as a comma separated string. That turned out to be what was tripping me up trying to use same cloning example code you referenced. The example doesn't handle the typeKeywords property correctly, as it will simply tries to pass to update() what it got from get_data(), so the copied item ends up corrupted. 

0 Kudos