0

In an external system, I plan to invoke an HTTP GET request.

I would like the HTTP GET request to be routed through a Python function on it's way to/from AGOL.


Steps:

  1. Invoke the HTTP GET request from the external system.
  2. A Python function would process the HTTP GET request, and it would send a subsequent HTTP GET request to AGOL.
  3. AGOL would receive the request and return a response to the Python function.
  4. The Python function would process the AGOL response and send a response of its own to the external system.

Question:

Is there a mechanism in AGOL (or ArcGIS Hub) where the Python function could be stored/accessed via HTTP?

3
  • The name of this type of application is a proxy. It's less than a dozen lines of code in Java, depending on what you want the proxy to do. There's no reason you couldn't do it with Python with the right networking code. but it certainly wouldn't be my first language choice for that sort of task.
    – Vince
    Aug 8, 2020 at 18:44
  • Good to know. What if I wanted the script to perform spatial operations with ArcPY (or some other spatial Python libraries). Would a proxy still be the weapon of choice?
    – User1974
    Aug 8, 2020 at 18:57
  • No. By definition, a proxy's principal role is that of a simple fast wrapper that does some value-added operation. Once you start involving complex tasks, it becomes a server in its own right. Using ArcPy in this manner is forbidden by the Desktop license agreement, and falls into the domain of ArcGIS Server. Again, Python is the wrong tool for the task. I've created Server Object Extensions that serviced GP-like requests, but that was done in Java, with ArcObjects Java.
    – Vince
    Aug 8, 2020 at 19:17

1 Answer 1

1

Neither ArcGIS Online nor ArcGIS hub allow you to run Python code in this fashion. The only thing close to this would be either:

  • A GP Service, which has a RESTful endpoint that you can hit. This would execute your Python code. Note this is only available from an on premise ArcGIS Server. You cannot publish GP Services to AGOL
  • Possibly ArcGIS Notebooks. You can send a POST request to execute a Notebook for your on-premise Notebook. This doesn't look possible yet with the ArcGIS.com Hosted Notebooks.

I’d look into Azure Functions. There is a slight learning curve but you can write and publish Python code that responds to an HTTPTrigger. IE it creates a URL that functions as a RESTful API that you trigger by sending HTTP requests too. I’ve found the Azure pricing very reasonable. If you want to get a sense of what’s involved, you can browse the code I wrote that works on a TimerTrigger (ie run at a given interval). This code makes requests to AGOL and based on the response sends an email. From my understanding of your project, not terribly different.

10
  • A related post here: HTTP request -to- AWS Lambda Python function -to- AGOL
    – User1974
    Aug 9, 2020 at 2:53
  • 1
    Cool! Didn't know that existed. That might provide you the mechanism you need?
    – KHibma
    Aug 11, 2020 at 11:22
  • 1
    @wwnde No - you wont be able to install arcpy into an Azure function. arcpy is just a wrapper on ArcObjects. AO's are part of core Esri software (ArcMap, ArcGIS Pro, ArcGIS Server). Essentially you'd need to put all of the full product into the Azure Function (which you know is impossible). So arcpy is not an option for Azure. You'll need to find another Python package that does what you want or write your own.
    – KHibma
    Dec 10, 2020 at 13:05
  • 1
    @KHibma in SouthPole and so enjoying much more sunshine than you are I guess... Dozed of .... Found out I can search feature service or use feature service id to extract feature. Use the python API to find centroid. Basically from arcgis.features.find_locations import find_centroids;poly_to_point = find_centroids(item.layers[0], output_name="Centroids").This publishes Centroids on Portal. Can then extract coordinates in right projection. In my case, I need to dissolve the polygons before find_centroids. Investigating how I can get that done within the arcgis API
    – wwnde
    Dec 11, 2020 at 3:04
  • 1
    If needed to dissolve before extracting centroid; from arcgis.features.manage_data import dissolve_boundaries; point_centroid = dissolve_boundaries(item.layers[0], dissolve_fields, output_name="dissolved")
    – wwnde
    Dec 11, 2020 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.