Has anyone used the Python API to create Views of a hosted feature service on ArcGIS Online?
I have a hosted feature service (type = feature layer collection) and want to automate creation of Views. The arcgis.gis module has a method called create_service with an optional parameter to specify if the service is a View.
I've tested this on a dummy feature service. See the python below that results in an error ('Item' object has no attribute 'create_service').
from arcgis.gis import GIS
from arcgis.gis import ContentManager
mygis = GIS("https://www.arcgis.com", "username", "password")
GMitem = mygis.content.get('itemID')
GMitem.create_service(name = "GM_COPY_Reg1",is_view = TRUE)
Solved! Go to Solution.
Unwanted reply…
How can I be unsubscribed from this thread?
De : Xabier Velasco Echeverría
Envoyé : lundi 29 octobre 2018 15:40
À : Kacenelen Yann
Objet : Re: - Re: Create View of Hosted Feature Service using Python API
GeoNet <https://community.esri.com/?et=watches.email.thread>
Re: Create View of Hosted Feature Service using Python API
reply from Xabier Velasco Echeverría<https://community.esri.com/people/NASUVINSA?et=watches.email.thread> in ArcGIS Online - View the full discussion<https://community.esri.com/message/809323-re-create-view-of-hosted-feature-service-using-python-api?commentID=809323&et=watches.email.thread#comment-809323>
Hi Xabier,
Thank you for your answer. Creating the view and then updating its definition is the good the solution for my Python script.
Thanks again for your help,
Regards,
Gaëtan.
Hi,
Currently it is not possible to create a view from a hosted table using the ArcGIS Python API. That is the answer I got from ESRI. I suggested an ArcGIS Idea, feel free to vote for it
https://community.esri.com/ideas/16757-python-api-create-view-for-hosted-table
De: José Antonio Anta Viguera
Enviado el: miércoles, 16 de octubre de 2019 16:05
Para: Velasco Echeverria, Xabier (NASUVINSA)
Asunto: Re: - Re: Create View of Hosted Feature Service using Python API
GeoNet, The Esri Community | GIS and Geospatial Professional Community <https://community.esri.com/?et=watches.email.thread>
Re: Create View of Hosted Feature Service using Python API
reply from José Antonio Anta Viguera<https://community.esri.com/people/joseantonio.antaesri-es-esridist?et=watches.email.thread> in ArcGIS Online - View the full discussion<https://community.esri.com/message/884687-re-create-view-of-hosted-feature-service-using-python-api?commentID=884687&et=watches.email.thread#comment-884687>
thank you very much
I will solve my project using Javascript with the REST API directly
I found this thread very helpful, I just needed to create a hosted view that had a definition query, very simple and just a few lines of code.
make sure you have the feature layer collection referenced
<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