Feature Collection JSON doesn't have 'layers'

787
3
Jump to solution
10-03-2018 08:46 AM
Marco_E_Cadario
New Contributor II

Hi,

I've a problem to import data from a pandas data frame on ArcGIS OnLine.

I followed the documentation scrupulously on Accessing and creating content | ArcGIS for Developers  paragraph "importing data from a pandas data frame".

But when I do:

myEvents = pd.read_excel(myXlsx)

myEvents_fc = myGis.content.import_data(myEvents)
myEvents_fc_dict = dict(myEvents_fc.properties)
myEvents_json = json.dumps(myEvents_fc_dict)
myEvents_item_properties = {'title': 'zzmcada_events_df',
                                                'description': 'test to import pabdas dataframe',
                                                'tags': 'zzmcada test, arcgis python api, pandas, xlsx',
                                                'text':myEvents_json,
                                                'type':'Feature Collection'}

myEvents_item = myGis.content.add(myEvents_item_properties)

I receive a 

RuntimeError: Error while analyzing Feature Collection, Feature Collection JSON doesn't have 'layers'
(Error Code: 406)

Columns data type are

eventID              object
eventName        object
eventPriority      int64
eventPlanned    bool
eventType          object
eventAddress    object
Latitude             float64
Longitude          float64
dtype: object

Can someone help me to understand what is wrong?

Many thanks

Marco

0 Kudos
1 Solution

Accepted Solutions
simoxu
by MVP Regular Contributor
MVP Regular Contributor

It seems the instructions is outdated or wrong at the first place. Please try this:

Replace

myEvents_json = json.dumps(myEvents_fc_dict)

With

myEvents_json = json.dumps({"featureCollection": {"layers": [dict(myEvents_fc.layer)]}}) ‍‍‍

I referenced this example:

Html table to pandas data frame to portal item | ArcGIS for Developers 

View solution in original post

3 Replies
simoxu
by MVP Regular Contributor
MVP Regular Contributor

It seems the instructions is outdated or wrong at the first place. Please try this:

Replace

myEvents_json = json.dumps(myEvents_fc_dict)

With

myEvents_json = json.dumps({"featureCollection": {"layers": [dict(myEvents_fc.layer)]}}) ‍‍‍

I referenced this example:

Html table to pandas data frame to portal item | ArcGIS for Developers 

View solution in original post

Marco_E_Cadario
New Contributor II

It works.

Thank you

Marco

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If Simo's comment answered your question, please mark it correct to close out this question.

0 Kudos