How to create a feature layer view in AGOL

5278
20
Jump to solution
04-12-2017 11:14 PM
by Anonymous User
Not applicable

Does anyone know how you would, using the Python API, create a feature layer view in ArcGIS Online (or Portal 10.5 for that matter I guess)?

I'm referring here to the new views capability that arrived in AGOL back in December, that allows you to create a view of an existing hosted feature layer, but with different editing capabilities, field visibility, filtered features etc.

Cheers,

-Paul

20 Replies
RobertMEIER
Occasional Contributor

Here's a very simple example of just creating a view with a definition query.

 

<item_id> is the item number of the hosted feature layer you want to create the view from.

 

from arcgis.gis import GIS
from arcgis.features import FeatureSet, Feature, FeatureLayer,FeatureCollection,FeatureLayerCollection

 

username = <uname>
password = <pwd>
gis = GIS(<agol_url>, username, password)

 

expItem = gis.content.get(<item_id>)
flc = FeatureLayerCollection.fromitem(expItem)

theVw = flc.manager.create_view(name="<layer_name>",capabilities='Query',view_layers=[flc.layers[0]])

theVw.layers[0].manager.update_definition({'viewDefinitionQuery': 'placename is not null'})

 

I hope people find this simple example helpful

-bert

0 Kudos