Add feature collection as item in the GIS

240
1
08-31-2021 11:56 PM
lightpro
New Contributor III

I am trying to add a feature collection as an item in the GIS without much success. I've an existing layer that I query to get a subset of the features. From this I create a feature collection as in the code below. No problems here.

feat_set = mylyr.query(where="OBJECTID>500")
feat_collect = arcgis.features.FeatureCollection.from_featureset(feat_set)
feat_collect

 I then try to add this as a new item in the GIS by inserting as a text item. 

item_properties = {'title': 'Temp',
                        'description':'Temp',
                        'tags': 'temp',
                        'text':feat_collect.properties,
                        'type':'Feature Collection'}
append_featurecollection_item = gis.content.add(item_properties)
append_featurecollection_item

This kind of works. The item is created and appears in the GIS and I can see the data table is populated. When I try to view the item in the map viewer I get the following message however. 

lightpro_0-1630479282490.png

Clearly I'm missing something which I suspect is related to the JSON I'm adding to the item as text. I'm guessing my JSON is incomplete as I'm just adding my featurecollection.properties. I haven't been able to figure out the correct format however. 

Does anyone know what I'm missing? 

 

0 Kudos
1 Reply
MehdiPira1
Esri Contributor

Hi @lightpro ,

It should work.

You also have the option to add spatial reference to the item properties.

item_properties = {'title': 'Temp',
                    'description':'Temp',
                    'tags': 'temp',
                    'text':feat_collect.properties,
                    'type':'Feature Collection',
                    'spatialReference':'WGS_1984_Web_Mercator'}
append_featurecollection_item = gis.content.add(item_properties)

 alternatively, you can test it on another feature layer.

0 Kudos