Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

Wrap layer query with call to analysis service #135

Closed DShokes closed 8 years ago

DShokes commented 8 years ago

I'm having a tough time converting the results of a feature layer query to the input for analysis service tools. For example I'm trying to call field calculate on the features object returned by query.features. it would also be great to create a buffer or run drive time analysis on queried features. I didn't see a sample that leveraged your analysis module in this way. Would this be easy to create or could someone point me to the functions and types of arguments required?

achapkowski commented 8 years ago

@DShokes - The analysis services are just GP tasks, so let's say you query a service and it returns a Feature as JSON, you can convert that to a GPFeatureRecordSetLayer object (the class is located in the arcrest\ags_gpobjects.py file). You would then pass that in to buffer, etc...

For buffer, I would recommend using the geometry service operations instead found here: arcrest\geometryservice\geometryservice.py

DShokes commented 8 years ago

Thanks Andrew. I was only looking in the agol module as I only work with hosted services. My end goal is creating a button that calculates field C as field A * field B for features with A and B, but not C.

DShokes commented 8 years ago

I ended up using https://developers.arcgis.com/rest/analysis/api-reference/programmatically-accessing-analysis-services.htm#ESRI_SECTION1_05B0C9E863C045CB975DCB674874FA38 In one test I ran the fieldCalculator Task with the parameter { 'inputLayer': { 'url':feature_layer, 'filter':"Size IS NULL"}, 'expressions': [{ 'field': {"name" : "Size"}, "expression":"!shape.geodesicArea@squarefeet!" }] }. The analysis service returned a success message and a featureset. However, the actual features aren't updated on the hosted service. Is this expected behavior to have to manually update a featurelayer with the task's resulting featureset? It just seems odd.