Basic Python Question

1169
6
Jump to solution
04-27-2017 06:53 AM
TiffanyRufo
Occasional Contributor II

How do you get the script you are writing to look at data in an AGOL feature layer?

I am brand new to Python and am trying to write a script that will send out an email notification to specific departments and individuals based on the type of report/complaint. I know that I need it to:

  1. query the database for new reports
  2. Sort the new reports based on report type 
  3. Send a notification to specific individuals based on that report type. (Example:if it is a pothole complaint send it to our street department guys)

I have seen several different threads about this same thing with snippets of code here and there, but I haven't found anything about how you direct python to an AGOL feature layer to get the data to start with.

I know that this is a pretty in-depth scripting project for an absolute beginner, but I don't really want anyone to write it for me I would very much like to learn how to write this myself if possible. 

I found this GITS :: Code :: mailer  that I would like to use for the email portion, I just need to write the query section.

Any help or direction to resources would be greatly appreciated. I don't think I know the correct keywords to search for to find what I need.... Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
TiffanyRufo
Occasional Contributor II

Found out how to do it (get a script to search a feature Layer in AGOL) Download and use ArcREST.

import arcrest


#get reference to your feature layer Rest endpoint

fl = arcrest.agol.FeatureLayer(url='your/urlrestendpoint/0')

View solution in original post

0 Kudos
6 Replies
JoshuaBixby
MVP Esteemed Contributor

I would start by spending some time reading up on and getting familiar with the ArcGIS API for Python:

Script and automate your Web GIS

The ArcGIS API for Python lets ArcGIS Online and ArcGIS Enterprise users, analysts, developers and administrators script and automate tasks ranging from performing big data analysis to content management and administration of their web GIS. The API integrates well with the Jupyter Notebook and the SciPy stack and enables academics, data scientists, and GIS analysts to share programs and reproducible research with others.

RebeccaStrauch__GISP
MVP Emeritus

I second Joshua's comment on the ArcGIS API for Python.  I would check out some of the tech session/presentations available (free)

E360 Video Search | Esri Videos 

The nice thing about this API and the Jupyter Notebook is you can try it out online first, without installing.  I have only played with the administration side for AGOL, but it looks like it has a lot of potential for future use. (my opinion)

JakeSkinner
Esri Esteemed Contributor

Hi Tiffany,

The Python API will definitely make accessing the service easier, but also here is a post on how to do this using Python 2.x:

https://community.esri.com/message/675306 

RandyBurton
MVP Alum

I would suggest looking at the ArcGIS REST API.  (To query, see the Query (Feature Service/Layer) in the Your Services >> Feature Service section.)  You may also find the github ArcREST files helpful.  This thread may also be of help: ArcREST vs ArcGIS Python API

TiffanyRufo
Occasional Contributor II

Thank you to everyone for your help! I don't know that the API is an option just yet but I am still reading through all of the information on it as well as the links Randy and Jake were kind enough to share with me. I have gathered a few snippets of code here and there that I hope to stitch together into a working script. I will update back here when there are developments.

Thanks again!

0 Kudos
TiffanyRufo
Occasional Contributor II

Found out how to do it (get a script to search a feature Layer in AGOL) Download and use ArcREST.

import arcrest


#get reference to your feature layer Rest endpoint

fl = arcrest.agol.FeatureLayer(url='your/urlrestendpoint/0')
0 Kudos