Select to view content in your preferred language

Extract Data Task GP Not Extracting Features - PLEASE HELP!!!

5939
20
12-26-2011 08:58 AM
IanWint
Deactivated User
I created a geoprocessing (GP) task to extract features from a SDE geodatabase.  I created the GP task and added it to my MXD using the instructions from this video:  http://www.youtube.com/watch?v=HsMK9ZtYN5k.

I then re-created the "clip and ship" javascript api sample using the instructions posted here:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm.  I used my mxd and ArcGIS Server services when I created my version of the sample posted here:  http://gis.fortlauderdale.gov/DataDownloads/esriSample.html.

The GP works as expected when initiated from ArcMap by right clicking on the "Extract Data Task," selecting "Open," then interactively drawing a graphic for clipping the features.  However, the GP does not clip the features when initiated from my sample website (http://gis.fortlauderdale.gov/DataDownloads/esriSample.html).  It initiates the GP but the resulting files that are downloaded only contain the structure of the files.  They do not include any features.  It is almost as if the application is ignoring my interactive graphic.  This is getting frustrating as I've spent several days trying to figure out the problem.  I am hoping someone will please chime in to provide some assistance.

Thanks in advance.
0 Kudos
20 Replies
HemingZhu
Frequent Contributor
Thanks Heming. I applied your code to my js file. I think everything is good above the start of function extractData(). Nothing happens when I use Chrome to click the "Extract" button. At least IE gave the following error: 

Message: 'spatialReference.wkid' is null or not an object 
Line: 48 
Char: 427431 
Code: 0 
URI:   http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.6

Boy, this is going to ruin my new year's eve weekend 😞 

Question: for the line that reads "var outSR = new esri.SpatialReference ( { wkid : 2236});" does wkid need to be quoted so it is written ad "wkid"? 

Thanks again for your help. I'll do some research over the weekend while following the path you set out. At the same time, if something jumps out at you I would appreciate feedback. Here is my code at the moment: 

dojo.require("dijit.dijit");
// optimize: load dijit layer
dojo.require("dijit.layout.BorderContainer");
dojo.require("dojox.layout.FloatingPane");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.form.CheckBox");
dojo.require("dijit.form.ComboBox");
dojo.require("esri.map");
dojo.require("esri.dijit.Popup");
dojo.require("esri.geometry");

/*------------------------------------*/
// GLOBAL VARIABLES
/*-----------------------------------*/
var gp, map;
var loading;
var selectionToolbar;
//hzhu added
var gsvc;

function init() {
 //configure map zoom animation to be slower (Gives a cool effect, almost similar to the Flex Viewer zoom)
 //The default for zoomDuration in milliseconds is 250
 //Default for zoomRate is 25
 esri.config.defaults.map.zoomDuration = 1000;
 esri.config.defaults.map.zoomRate = 50;

 //configure map pan animation to be slower
 //time in milliseconds; default panDuration:250
 //refresh rate of zoom animation; default panRate:25
 esri.config.defaults.map.panDuration = 1000;
 esri.config.defaults.map.panRate = 50;
 
 //esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
 esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
 loading = dojo.byId("loadingImg");
 var initialExtent = new esri.geometry.Extent({"xmin":-8931399.85128929,"ymin":3006918.03708705,"xmax":-8913140.86444157,"ymax":3026297.04737907,"spatialReference":{"wkid":102100}});
 map = new esri.Map("map", {
  extent: initialExtent
 });
 dojo.connect(map, 'onLoad', function(map) {
  initSelectionToolbar();
  //resize the map when the browser resizes
  dojo.connect(dijit.byId('map'), 'resize', map, map.resize);
 });
  
 var basemapUrl = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
 var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemapUrl);
 map.addLayer(basemap);
 //var FortLaudMapLayers = new esri.layers.ArcGISDynamicMapServiceLayer("http://gis.fortlauderdale.gov/ArcGIS/rest/services/AppsITS/DataExtractionDownloads/MapServer");
 var FortLaudMapLayers = new esri.layers.ArcGISDynamicMapServiceLayer("http://gis.fortlauderdale.gov/ArcGIS/rest/services/AppsITS/DataExtraction/MapServer");
 map.addLayer(FortLaudMapLayers);
 //hzhu added
 gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
 //gp = new esri.tasks.Geoprocessor("http://gis.fortlauderdale.gov/ArcGIS/rest/services/AppsITS/DataExtractionDownloads/GPServer/Extract%20Data%20Task");
 gp = new esri.tasks.Geoprocessor("http://gis.fortlauderdale.gov/ArcGIS/rest/services/AppsITS/DataExtraction/GPServer/Extract%20Data%20Task");

}

function initSelectionToolbar(myMap) {
 selectionToolbar = new esri.toolbars.Draw(map);
 dojo.connect(selectionToolbar, "onDrawEnd", function(geometry) {
  selectionToolbar.deactivate();
  var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
  var graphic = new esri.Graphic(geometry, symbol);
  map.graphics.add(graphic);
 });
}

function activateTool(type) {
 selectionToolbar.activate();
}

function extractData() {
 //hzhu added
 var outSR = new esri.SpatialReference({
  wkid : 2236
 });
 //hzhu added
 gsvc.project([map.graphics.graphics[0]], outSR, function(graphics) {
  //hzhu added
  var graphic = graphics[0];
  //get clip layers
  var clipLayers = [];
  if(dijit.byId('layer0').checked) {
   clipLayers.push('Bridges (Moveable)');
  }
  if(dijit.byId('layer1').checked) {
   clipLayers.push('Building Permits');
  }
  if(dijit.byId('layer2').checked) {
   clipLayers.push('Businesses');
  }
  if(dijit.byId('layer3').checked) {
   clipLayers.push('Fire Stations');
  }
  if(dijit.byId('layer4').checked) {
   clipLayers.push('Lifeguard Towers');
  }
  if(dijit.byId('layer5').checked) {
   clipLayers.push('Ocean Buoys');
  }
  if(dijit.byId('layer6').checked) {
   clipLayers.push('Section Points (Florida PLSS)');
  }
  if(dijit.byId('layer7').checked) {
   clipLayers.push('Survey Benchmarks');
  }
  if(dijit.byId('layer8').checked) {
   clipLayers.push('City Limits (Fort Lauderdale)');
  }
  //hzhu modified
  if(clipLayers.length === 0 || graphics.length === 0) {
   alert('Select layers to extract and area of interest');
   return;
  }
  var features = [];
  features.push(graphic);
  var featureSet = new esri.tasks.FeatureSet();
  featureSet.features = features;

  var params = {
   "Layers_to_Clip" : clipLayers,
   "Area_of_Interest" : featureSet,
   "Feature_Format" : dijit.byId('formatBox').value
  }
  esri.show(loading);
  gp.submitJob(params, completeCallback, statusCallback, function(error) {
   alert(error);
   esri.hide(loading);
  });
 });
}

function completeCallback(jobInfo) {
 if(jobInfo.jobStatus !== "esriJobFailed") {
  gp.getResultData(jobInfo.jobId, "Output_Zip_File", downloadFile);
 }
}

function statusCallback(jobInfo) {
 var status = jobInfo.jobStatus;
 if(status === "esriJobFailed") {
  alert(status);
  esri.hide(loading);
 } else if(status === "esriJobSucceeded") {
  esri.hide(loading);
 }
}

function downloadFile(outputFile) {
 map.graphics.clear();
 var theurl = outputFile.value.url;
 window.location = theurl;
}

//show map on load
dojo.addOnLoad(init);


You could try add "" on wkid. Theoretically { wkid : 2236} should be a json and should be written as {"wkid": 2236}. I just copy the outSR statement from one of my project and it does not cause any problems for me. I guess i have to take a second look when i add codes on forum!
0 Kudos
IanWint
Deactivated User
This problem was resolved a while ago after getting some help from someone at ESRI.  I forgot to come back to the forum to share the solution so here I am doing that now.   The problem seems to be an issue with versions of the javascript API at least up until version 2.8 (hopefully ESRI fixes this after version 2.8).  The problem doesn't exist with the Flex or Silverlight API.  Below I left a description of the cause of the problem, followed by the solution:

ISSUE

When executing or submitting a gptool, the JavaScript API writes the JSON similar to the one below:



{"sr":{"wkid":3857},"geometryType":"esriGeometryPolygon","features":[{"geometry":{"rings":[[[-10022778.439878229,3842809.5414813654],[-9969272.520078585,3842809.5414813654],[-9969272.520078585,3789303.621681722],[-10022778.439878229,3789303.621681722],[-10022778.439878229,3842809.5414813654]]],"spatialReference":{"wkid":3857}}}]}



The Flex and Silverlight API uses the term "spatialReference" at the beginning instead of "sr". In some gptools, using sr causes the program to not work correctly.



SOLUTION/WORKAROUND

Manually change the JSON to add the spatialReference variable.



        esri.setRequestPreCallback(function(ioargs){

        if(ioargs.content.Area_of_Interest){

            var aoijson = dojo.fromJson( ioargs.content.Area_of_Interest);

      

            aoijson.spatialReference = aoijson.sr;

            ioargs.content.Area_of_Interest = dojo.toJson(aoijson);

            console.log('test');

    

          }

          return ioargs;

        });
0 Kudos
Reynaldde_Castro
Deactivated User
this format actually works.  it may be something else.  I too am having problems creating the clip and ship site.  I can manually enter the parameters through the REST interface.  Your 'Area of Interest' syntax format works for me.  Do you have it working?
0 Kudos
IanWint
Deactivated User
this format actually works.  it may be something else.  I too am having problems creating the clip and ship site.  I can manually enter the parameters through the REST interface.  Your 'Area of Interest' syntax format works for me.  Do you have it working?


Yes it's been working for us for quite some time now.  Here is the link:  http://gis.fortlauderdale.gov/DataExtraction/

And here is the solution I referenced above:
Manually change the JSON to add the spatialReference variable.



esri.setRequestPreCallback(function(ioargs){

if(ioargs.content.Area_of_Interest){

var aoijson = dojo.fromJson( ioargs.content.Area_of_Interest);



aoijson.spatialReference = aoijson.sr;

ioargs.content.Area_of_Interest = dojo.toJson(aoijson);

console.log('test');



}

return ioargs;

});
0 Kudos
Reynaldde_Castro
Deactivated User
just tried your site and received a job failed message.
0 Kudos
IanWint
Deactivated User
just tried your site and received a job failed message.


If you get a chance try it again.  I restarted the geoprocessing service and the mapservice.  That action apparently did the trick.  I'm not sure why I had to do that because it has been working fine for about 2 months now.  Maybe the services experience issues every so often.  Nonetheless, thanks for notifying me.
0 Kudos
IanWint
Deactivated User
If you get a chance try it again.  I restarted the geoprocessing service and the mapservice.  That action apparently did the trick.  I'm not sure why I had to do that because it has been working fine for about 2 months now.  Maybe the services experience issues every so often.  Nonetheless, thanks for notifying me.


UPDATE:

I'm noticing that I sometimes receive the error message when I use the Geodatabase option for downloading.  This doesn't seem to be happen with the shapefile option.  This is all after restarting the services.  I'll have to troubleshoot why the geodatabase option is misbehaving.
0 Kudos
Reynaldde_Castro
Deactivated User
Where do I put the workaround you sent?  I am using the sample clip and ship from Esri's site. Thanks in advance.
0 Kudos
Reynaldde_Castro
Deactivated User
I still received the job failed message from your site even after selecting shapefile format.
0 Kudos
IanWint
Deactivated User
Where do I put the workaround you sent?  I am using the sample clip and ship from Esri's site. Thanks in advance.


Below is an abbreviated version of the last part of my JavaScript code.  I tried calling attention to the block of work around code you need to add.  I did so by adding comments. Look towards the bottom of my JavaScript code.  The rest of the code is just for context:

function extractData() {
 //get clip layers
 var clipLayers = [];
 if(dijit.byId('layer0').checked) {
  clipLayers.push('Bridges (Moveable)');
 }
 if(dijit.byId('layer1').checked) {
  clipLayers.push('Building Permits');
 }
 if(dijit.byId('layer2').checked) {
  clipLayers.push('Businesses');
 }
 if(dijit.byId('layer3').checked) {
  clipLayers.push('Colleges and Universities');
 }
 if(dijit.byId('layer4').checked) {
  clipLayers.push('Fire Stations');
 }
 if(clipLayers.length === 0 || map.graphics.graphics.length === 0) {
  alert('Select layers to extract and area of interest');
  return;
 }
 var features = [];
 features.push(map.graphics.graphics[0]);
 var featureSet = new esri.tasks.FeatureSet();
 featureSet.features = features;

 var params = {
  "Layers_to_Clip" : clipLayers,
  "Area_of_Interest" : featureSet,
  "Feature_Format" : dijit.byId('formatBox').value
 }
 esri.show(loading);
 gp.submitJob(params, completeCallback, statusCallback, function(error) {
  alert(error);
  esri.hide(loading);
 });
}

function completeCallback(jobInfo) {
 if(jobInfo.jobStatus !== "esriJobFailed") {
  gp.getResultData(jobInfo.jobId, "Output_Zip_File", downloadFile);
 }
}

function statusCallback(jobInfo) {
 var status = jobInfo.jobStatus;
 if(status === "esriJobFailed") {
  alert(status);
  esri.hide(loading);
 } else if(status === "esriJobSucceeded") {
  esri.hide(loading);
 }
}

function downloadFile(outputFile) {
 map.graphics.clear();
 var theurl = outputFile.value.url;
 window.location = theurl;
}

/*--------------------------------------------------------------------------*/
/* +++++  THIS BLOCK CONTAINS THE WORK AROUND CODE            ++++++++*/       
esri.setRequestPreCallback(function(ioargs) {
 if(ioargs.content.Area_of_Interest) {
  var aoijson = dojo.fromJson(ioargs.content.Area_of_Interest);

  aoijson.spatialReference = aoijson.sr;
  ioargs.content.Area_of_Interest = dojo.toJson(aoijson);
  console.log('test');

 }
 return ioargs;
});
/* +++++ END OF WORK AROUND CODE ++++++++++++++++++++++++++ */
//-------------------------------------------------
function showLoading() {
    esri.show(loading);
    map.disableMapNavigation();
    map.hideZoomSlider();
}

function hideLoading(error) {
    esri.hide(loading);
    map.enableMapNavigation();
    map.showZoomSlider();

}
//-----------------------------------------------
dojo.addOnLoad(init);
0 Kudos