Select to view content in your preferred language

How to use a Spatial Analysis Service - FindNearest with JS api

4899
13
Jump to solution
03-04-2014 12:10 PM
deleted-user-VeZur_n9o0OZ
Deactivated User
Hello all,

I've seen similar questions to this but nothing with my specific symptoms so I've started a new thread. I'm trying to use the FindNearest Spatial Analysis Service. I have an AGOL org account, and am using a private webmap which requires me to login.

https://developers.arcgis.com/rest/analysis/api-reference/find-nearest.htm
https://developers.arcgis.com/javascript/jsapi/geoprocessor-amd.html#submitjob

Through a combination of the above resources I've put together some code to submit a job. My job fails with the following errors relating to my input params...

ERROR 000735: analysisLayer: Value is required arcgis.js:62 ERROR 000735: nearLayer: Value is required arcgis.js:62 Failed. 


What am I doing wrong?

 var gp = new Geoprocessor("http://analysis.arcgis.com/arcgis/rest/services/tasks/GPServer/FindNearest");             var _params = {                 "analysisLayer": {                     "url": "https://services1.arcgis.com/fcrLbZIfZI20fNqr/arcgis/rest/services/rig_subset_4326/FeatureServer/0"                     //"url": "http://10.4.164.20:6080/arcgis/rest/services/RigPlanner/RigPlanner_server/MapServer/0"                     //"filter" : "filter"                 },                 "NearLayer": {                     "layerDefinition": {                         "geometryType": "esriGeometryPoint",                         "fields": [                             {                                 "name": "Id",                                 "type": "esriFieldTypeOID",                                 "alias": "Id"                             }                         ]},                     "featureSet": {                         "geometryType": "esriGeometryPoint",                         "spatialReference": {                             "wkid": 4326                         },                         "features": [                             {                                 "geometry": {                                     "x": -94.00,                                     "y": 28.00                                 },                                 "attributes": {                                     "Id": 1                                 }                             }                         ]}                 },                 "maxCount": 10,                 "measurementType": "StraightLine",                 //"searchCutoff": 44,                 //"searchCutoffUnits": "Kilometers"                 "f": "json"             }             gp.submitJob(_params, completeCallback, statusCallback, errorCallback);


Also, how would I get the required authentication if I make my webmap and feature service public? Portal class?


Thanks,
James
0 Kudos
13 Replies
deleted-user-VeZur_n9o0OZ
Deactivated User
You can see my app for a limited period here: http://deloittegeospatial.github.io/
Code here: https://github.com/DeloitteGeospatial/deloittegeospatial.github.io/blob/master/js/arcgis.js

Getting published GP services to work is a whole different problem set. I'm sure you've seen these documents but I would start here:
http://resources.arcgis.com/en/help/main/10.2/index.html#/Analyzing_a_geoprocessing_service/00570000...
0 Kudos
GaneshSolai_Sambandam
Regular Contributor
HI James
Once agian, thank you very much for the code and working sample. Unfortunately, when I tried to play with your application, it didn't allow me, as it require AGOL account to log on to view the result. Other, than the application seems stunning and i could lot of points data near the gulf mexico and one tower image as well.

anyway thank you for your help.

To let you know, I have solved geoprocessing problem i have with my model. Actually, When I publish the model alone as a geprocessing service, it reports that  the near layer data are not found.

When I include the model in the Arcmap mxd document and published them as a geoprocessing service with result map service, the model tries to work and it could get the results for my near features in the rest end point.

To be honest, I really don't know why the model works when it is published as a geoprocessing with result map service and why it doesn't work when it is published just a model and basically, it is mystery.

Now, my next step is to integrate my geoprocessing result map service into web application to see how it works. I have to write my javascript code and it is a real challenge here to see how it works.


Regards
Ganesh

You can see my app for a limited period here: http://deloittegeospatial.github.io/
Code here: https://github.com/DeloitteGeospatial/deloittegeospatial.github.io/blob/master/js/arcgis.js

Getting published GP services to work is a whole different problem set. I'm sure you've seen these documents but I would start here:
http://resources.arcgis.com/en/help/main/10.2/index.html#/Analyzing_a_geoprocessing_service/00570000...
0 Kudos
deleted-user-VeZur_n9o0OZ
Deactivated User
Yeah like a said before you need an AGOL account, as you do with all of the Spatial Analyst Services. esri charge you credits to use them. You can however sign up for a free developer account and get 200 free credits. My app only queries one feature at a time and so barely consumes credits. Analysis is one credit per 1000 features. Sign up and use my app to see working code.

http://www.arcgis.com/features/free-trial.html
http://www.esri.com/software/arcgis/arcgisonline/credits
0 Kudos
GaneshSolai_Sambandam
Regular Contributor
Hi James
Thank you once again for your support. I have created my AGOL account and logged on to your application to see how it works. It was really good.

If I want to use the Spatial analysis service within AGOL where should I look within account to create an application similar to the one you created. Not sure exactly where to look for the spatial anlaysis service within AGOL?  Any help would be much helpful.

Regards
Ganesh
0 Kudos