Select to view content in your preferred language

Stuck on getting getResultImageLayer

4358
27
Jump to solution
10-24-2012 11:22 AM
SmaranHarihar
Deactivated User
I am getting back the success from the GP Tool but for some reason, when I execute the,

gp.getResultImageLayer(jobInfo.jobId,"final_shp", imageParams, function(gpLayer) {    map.addLayer(gpLayer);     });


I am receiving an error on the map.addLayer(gpLayer). The error is,

Network Error: 500 Internal Server Error - <complete path of the job directory where the final.shp is created>. What is causing the layer not to be added to the Map? This is the link.

This is my code,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>          <head>         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />         <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />         <!--The viewport meta tag is used to improve the presentation and behavior         of the samples on iOS devices-->         <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"         />         <title>GP Viewshed Task</title>         <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/dojo/dijit/themes/claro/claro.css">         <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css"         />         <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2compact"></script>         <script type="text/javascript">             dojo.require("esri.map");             dojo.require("esri.tasks.gp");             dojo.require("esri.layers.FeatureLayer");             dojo.require("esri.dijit.Popup");             dojo.require("dijit.TooltipDialog");              var map, gp, featureLayer, dialog;              /*Initialize map, GP*/             function init() {                 var startExtent = new esri.geometry.Extent({                     "xmin": -13644840.338547781,                     "ymin": 4529944.368315823,                     "xmax": -13614265.527233753,                     "ymax": 4552875.476801345,                     "spatialReference": {                         "wkid": 102100                     }                 });                  map = new esri.Map("mapDiv", {                     extent: startExtent                 });                 var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");                 map.addLayer(streetMap);                 //http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons (Drive Time Polygons)                 gp = new esri.tasks.Geoprocessor("http://webgis.arizona.edu/ArcGIS/rest/services/webGIS/Shock_Models/GPServer/Income_Log");                  gp.setOutputSpatialReference({                     wkid: 102100                 });                 dojo.connect(map, "onClick", computeViewShed);                 }              function computeViewShed(evt) {                 map.graphics.clear();                 if (map.graphicsLayerIds.length >= 1) {                     map.removeLayer(map.getLayer(map.graphicsLayerIds[0]));                 }                 var pointSymbol = new esri.symbol.SimpleMarkerSymbol();                 pointSymbol.setSize(20);                 pointSymbol.setOutline(new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), 1));                 pointSymbol.setColor(new dojo.Color([0, 0, 255, 0.25]));                  var graphic = new esri.Graphic(evt.mapPoint, pointSymbol);                 map.graphics.add(graphic);                  var features = [];                 features.push(graphic);                 var featureSet = new esri.tasks.FeatureSet();                 featureSet.features = features;                 var params = {                     "Input_Feature_Layer": featureSet,                     "Expression": "50"                 };                 //gp.execute(params, drawViewshed);                 gp.submitJob(params, completeCallback, statusCallback, function (error) {                     alert(error);                     //esri.hide(loading);                 });              }              function completeCallback(jobInfo) {                 if (jobInfo.jobStatus !== "esriJobFailed") {                     //gp.getResultData(jobInfo.jobId,"Output_Polygons", downloadFile);                     var imageParams = new esri.layers.ImageParameters();                     imageParams.imageSpatialReference = map.spatialReference;                     gp.getResultImageLayer(jobInfo.jobId, "final.shp", imageParams, function (gpLayer) {                         map.addLayer(gpLayer);                     });                 }             }               function statusCallback(jobInfo) {                 var status = jobInfo.jobStatus;                 if (status === "esriJobFailed") {                     alert(status);                     //esri.hide(loading);                 } else if (status === "esriJobSucceeded") {                     console.log("Success");                     //esri.hide(loading);                 }             }              dojo.addOnLoad(init);         </script>     </head>          <body class="claro">         <div id="mapDiv" style="width:800px; height:600px; border:1px solid #000;"></div>Click on map to execute my GP Task.</body>  </html>
0 Kudos
27 Replies
SmaranHarihar
Deactivated User
Well I am happy for you!
If I have understand your question: see this sample http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jssamples/map_dialog.html


Hi ciava,

It seems now I am stuck on another problem. I have the results layer back on to the Map but it seems that none of the data is coming back. The url of the gpLayer that is coming back shows none of the fields that I need the output layer to have.

This is what the url output of the gpLayer looks like. As you can see there is no info about the layers that the layer is suppose to have, which can be seen in the final_shp layer that can be seen in the jobs folder.

Is this normal? How can I retrieve the info of the layer?
0 Kudos
nicogis
MVP Alum
If I understand your question: yes, using result map service you return a image. It's rendered using map service and data in job folder but I don't see request rest passing from map server for get info on data.
(...If the GP service is associated with a result map service, the default output for GPRasterDataLayer and GPFeatureSetLayer parameters is a map image ...)

you have two solution:
you don't use result map service and you use only gp and render on client the output of gp
or
you use result map service but you must create a soe (server object extension) where you pass id of job and so you get on server your data  (feature class, raster ect) and return on client the info that you need.
I have done a similar  solution for a result map service yet set and so I don't want modify resutl map service (render complex) so I create a soe that from jobID (sent from client) I get feature class from server and serialize in json for js api esri.
0 Kudos
SmaranHarihar
Deactivated User
If I understand your question: yes, using result map service you return a image. It's rendered using map service and data in job folder but I don't see request rest passing from map server for get info on data.
(...If the GP service is associated with a result map service, the default output for GPRasterDataLayer and GPFeatureSetLayer parameters is a map image ...)

you have two solution:
you don't use result map service and you use only gp and render on client the output of gp
or
you use result map service but you must create a soe (server object extension) where you pass id of job and so you get on server your data  (feature class, raster ect) and return on client the info that you need.
I have done a similar  solution for a result map service yet set and so I don't want modify resutl map service (render complex) so I create a soe that from jobID (sent from client) I get feature class from server and serialize in json for js api esri.


Yes I also need the data which is there in the jobs folder on the server. How can I create this SOE to obtain the feature class from server? Can you pls share an example?
0 Kudos
SmaranHarihar
Deactivated User
If I understand your question: yes, using result map service you return a image. It's rendered using map service and data in job folder but I don't see request rest passing from map server for get info on data.
(...If the GP service is associated with a result map service, the default output for GPRasterDataLayer and GPFeatureSetLayer parameters is a map image ...)

you have two solution:
you don't use result map service and you use only gp and render on client the output of gp.


How can I render the output of gp on the client side? That is what I was trying initially remember, but I was getting the 500 Internal Server Error. Using the same gp tool when I used it with Map Service it worked fine.

So How can I render the output of the gp without the Map Service?
0 Kudos
SmaranHarihar
Deactivated User
I tried using,

gp.getResultData(jobInfo.jobId,"final_shp", imageParams, addResults);
function addResults(results) {
  console.log(results);
  var features = results.value.features;
 }


But it keeps giving me the error,

TypeError: results.value is undefined


Is this the method to get feature info request from the data?
0 Kudos
nicogis
MVP Alum
Ok, getResultData but you have a imageParams (old paste/cut) from remove ...

fix your code so

gp.getResultData(jobInfo.jobId,"final_shp", addResults, errResults);

function addResults(results) {
   console.log(results);
   var features = results.value.features;
   // do render ...
}
0 Kudos
SmaranHarihar
Deactivated User
Ok, getResultData but you have a imageParams (old paste/cut) from remove ...

fix your code so

gp.getResultData(jobInfo.jobId,"final_shp", addResults, errResults);

function addResults(results) {
   console.log(results);
   var features = results.value.features;
   // do render ...
}


Sorry about that. I corrected the code to,

gp.getResultData(jobInfo.jobId,"final_shp", addResults, errResults);

function addResults(results) {
  console.log(results);
  var features = results.value.features;
 }
 
 function errResults(err) {
  console.log(err);
 }


The problem is that results.value.features returns empty array. The feature count is zero.

Still not getting back the results. This is my application.
0 Kudos
nicogis
MVP Alum
The problem is that you use a gp with set A map so result is a image and not a recordset so you need change your gp in tab parameters and in "The tools exposed by Geoprocessing Service are stored in":
select radio button A toolbox and select toolbox.
0 Kudos
SmaranHarihar
Deactivated User
The problem is that you use a gp with set A map so result is a image and not a recordset so you need change your gp in tab parameters and in "The tools exposed by Geoprocessing Service are stored in":
select radio button A toolbox and select toolbox.


But in your blog you have given this image, which helps get back the Map which is overlaid on the baselayer in my application.

I changed the parameter to A toolbox and now I am niether receiving the output Map Layer nor am I getting any results. The results.value.features still returns an empty array.

This is my application.
0 Kudos
nicogis
MVP Alum
I have in response featureset with a exceededTransferLimit property. This property is true so the number of records exceeds the maximum number configured on you server. (I Have final.shp exceeded transfer limit of 1000 ).

If you have switch on toolbox you comment "gp.getResultImageLayer(j ..." and use only "gp.getResultData(.."
0 Kudos