Extract Data Task - Clip and Ship Not exporting

3693
20
05-09-2011 07:25 AM
BenSayers
Emerging Contributor
Hi there,
I am trying to replicate the Clip and Ship Geoprocessing sample using my own data and I am having trouble getting the data to export.

I am getting a zip file exported and downloaded but the shapefile is empty although the .DBF does have the column names.

My data is held in Oracle in British National Grid (SRID 27700) and the map uses web mercator (102100). I am setting the geoprocessing output spatial refernce but this does not seem to affect anything.
gp = new esri.tasks.Geoprocessor("http://maps.lynxinfo.co.uk:8080/LIVE/services/UKOGL/UKOGLTools/GPServer/Extract%20Data%20Task");
gp.setOutSpatialReference({wkid:27700});

Does anyone have any idea what I need to do to fix this?
0 Kudos
20 Replies
BenSayers
Emerging Contributor
From you code, i create a featureSet json like this:

{"features" :[{ "geometry" :{"rings" : [[[125125.00000000006, 856615], [125077.00000000012, 856599.0000000006], [124837.00000000017, 856536.0000000001], [124595.00000000006, 856481.0000000005], [124570.00000000017, 856473.0000000008], [125125.00000000006, 856615]]]}}]}

Put it into your AOI parameter at your service url: http://maps.lynxinfo.co.uk:8080/LIVE/services/UKOGL/ClipAndShip/GPServer/Extract%20Data%20Task/submi.... Test it. if your AOI set up is OK, you should get some results.


Sorry to be really basic but I can see how you've taken this from the Tomcat error I have pasted, but how to I get create this using the JavaScript API?
IS there a way I can set the featureSet explicitly as a polygon? As this is what is creating the polyline
var clipFeatureSet = new esri.tasks.FeatureSet();
var graphic = new esri.Graphic();
graphic.geometry = esri.graphicsExtent(map.graphics.graphics);
clipFeature.push(graphic);
clipFeatureSet.features = clipFeature;


DO I need to add the Polygon extent to the map.graphics?
0 Kudos
HemingZhu
Frequent Contributor
Sorry to be really basic but I can see how you've taken this from the Tomcat error I have pasted, but how to I get create this using the JavaScript API?
IS there a way I can set the featureSet explicitly as a polygon? As this is what is creating the polyline
var clipFeatureSet = new esri.tasks.FeatureSet();
var graphic = new esri.Graphic();
graphic.geometry = esri.graphicsExtent(map.graphics.graphics);
clipFeature.push(graphic);
clipFeatureSet.features = clipFeature;


DO I need to add the Polygon extent to the map.graphics?


If all your graphics in your map.graphics are polygons, all you need to do push every graphic into clipFeatureSet like this:
var clipFeatureSet = new esri.tasks.FeatureSet();
var clipFeature =[];
forEach(map.graphics.graphics, function(graphic)(
     //if (graphic.geometry.type ="polygon")
           clipFeature.push (graphic);
));
clipFeatureSet.features = clipFeature;
The most important thing is make sure that each feature (graphic) in AOI featureset has to be a feature with geometry type as "polygon".  Usually you either draw or specify certain polygon graphic(s) as your AOI instead of using all the grahics on your map as AOI. You really need to look at the ESRI sample to understand how to set up your AOI parameter. http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/gp_clipasync.html

Additionally, from what i understand is you add all query results on the map and want to download them. what you should do is to create a extent that cover all the results and then use this extent to create a featureset:

var graphic= new esri.Graphic(esri.graphicsExtent(results.features));
var clipFeatureSet = new esri.tasks.FeatureSet();
var clipFeature =[];

clipFeature.push (graphic);
clipFeatureSet.features = clipFeature;
0 Kudos
BenSayers
Emerging Contributor
Thank you for your explanation. One more quick question:
Say I have a group of lines like a tic tac toe grid and I only want the vertical lines by doing what you say
what you should do is to create a extent that cover all the results and then use this extent to create a featureset
won't this also select the horizontal lines too?
0 Kudos
HemingZhu
Frequent Contributor
Thank you for your explanation. One more quick question:
Say I have a group of lines like a tic tac toe grid and I only want the vertical lines by doing what you say  won't this also select the horizontal lines too?


Whatever the extent polygon feature (clipFeatureSet) covers will be cliped and downloaded. So you might have to do some code logic to create the clipFeatureSet cover only the vertical lines.
0 Kudos
BenSayers
Emerging Contributor
If all your graphics in your map.graphics are polygons, all you need to do push every graphic into clipFeatureSet like this:
var clipFeatureSet = new esri.tasks.FeatureSet();
var clipFeature =[];
forEach(map.graphics.graphics, function(graphic)(
//if (graphic.geometry.type ="polygon")
clipFeature.push (graphic);
));
clipFeatureSet.features = clipFeature;
The most important thing is make sure that each feature (graphic) in AOI featureset has to be a feature with geometry type as "polygon". Usually you either draw or specify certain polygon graphic(s) as your AOI instead of using all the grahics on your map as AOI. You really need to look at the ESRI sample to understand how to set up your AOI parameter. http://help.arcgis.com/en/webapi/jav...clipasync.html

Additionally, from what i understand is you add all query results on the map and want to download them. what you should do is to create a extent that cover all the results and then use this extent to create a featureset:

var graphic= new esri.Graphic(esri.graphicsExtent(results.features));
var clipFeatureSet = new esri.tasks.FeatureSet();
var clipFeature =[];

clipFeature.push (graphic);
clipFeatureSet.features = clipFeature;



None of the features that I am selecting via the querytask are polygons. They are points and polylines. I think from what I now understand that I need a way of taking these and creating a creating a small buffer around them individually to create polygons, and then using these polygons to create a Multipolygon Ring FeatureSet to pass as the AOI for the ExtractDataTask. Am I correct in thinking this? And if so how can I use the buffer gp task as this too needs a geometry for its input?

Many thanks,
Ben
0 Kudos
HemingZhu
Frequent Contributor
None of the features that I am selecting via the querytask are polygons. They are points and polylines. I think from what I now understand that I need a way of taking these and creating a creating a small buffer around them individually to create polygons, and then using these polygons to create a Multipolygon Ring FeatureSet to pass as the AOI for the ExtractDataTask. Am I correct in thinking this? And if so how can I use the buffer gp task as this too needs a geometry for its input?

Many thanks,
Ben


Yes!!! you are on the right track. Use GeometryService's buffer method to create buffer polygons instead. Here is doc you can look at: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/geometryservice.htm
0 Kudos
AlexGole1
Emerging Contributor
Yes!!! you are on the right track. Use GeometryService's buffer method to create buffer polygons instead. Here is doc you can look at: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/geometryservice.htm


Hi I am also trying to use the clip and ship template but is not successful. What I am trying to do is to allow the users to either clip by a user-drawn polygon graphic as shown in the ESRI example or query a county layer to clip data  to the extent of  certain counties. If any of you have ideas, suggestions. It is most welcome. I have been working on this for well over a week now.
gp = new Geoprocessor("http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/Incident_Data_Extraction/GPServer/Extract%20Data%20Task");
      gp.setOutSpatialReference({wkid:102100});
      
      registry.byId("polygon").on("click", function() {
      activateTool(this.id);
      });
      
      registry.byId("freehandpolygon").on("click", function() {
      activateTool(this.id);
      });
      
      registry.byId("extract").on("click", extractData);
      
      registry.byId("Query").on("click", executeQueryTask);
      
      function initSelectionToolbar() {
       map.graphics.clear();
       
       selectionToolbar = new Draw(map);
       selectionToolbar.on("draw-end", function(e) {
        selectionToolbar.deactivate();
        
        var symbol = new SimpleFillSymbol(
        "solid", 
        new SimpleLineSymbol("dash", new Color([255,0,0]), 2), 
        new Color([255,255,0,0.25])
        );
       
        var graphic = new Graphic(e.geometry, symbol);
        map.graphics.add(graphic);
       });
      }

      function activateTool(tool) {
       map.graphics.clear();
       // The draw.activate expects a string like "polygon" or "freehand_polygon".
       selectionToolbar.activate(tool);
      }
    
      function extractData(){
       //get clip layers
       var clipLayers = [];
       if ( registry.byId("layer1").get("checked") ) { clipLayers.push("Incident Points"); }
       if ( registry.byId("layer2").get("checked") ) { clipLayers.push("Incident Lines"); }
       if ( registry.byId("layer3").get("checked") ) { clipLayers.push("Incident Areas"); }
       if ( clipLayers.length === 0 || map.graphics.graphics.length === 0 ) {
        alert("Select layers to extract and draw an area of interest.");
        return;
       }
      }
      
      function executeQueryTask() {
      //variable that calls the textbox value
       var type = document.getElementById("textbox").value;
       var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/Alex_Try/Counties/MapServer/0");  //Your county feature service
       var query = new Query();
       query.returnGeometry = true;
       query.outFields = ["FMNAME_UC"];  //Your county name field in your feature service
       query.where = "FMNAME_UC = 'SISKIYOU COUNTY'";  
       
       //If you want a result handler function, just replace that here
       queryTask.execute(query, function(featureSet){
        //This is designed to get the FIRST feature graphic as a JSON in the return because I am assuming you only have one county with that name
        var params = {
         "Layers_to_Clip": clipLayers,
         "Feature_Format": registry.byId("formatBox").get("value")
        };
        
        if (featureSet.features.length > 0) {
         params.Area_of_Interest = featureSet.features[0].geometry;
        } else {
         params.Area_of_Interest = map.graphics.graphics[0].geometry;
        }
        
        domStyle.set(loading, "display", "inline-block");
        gp.submitJob(params, completeCallback , statusCallback, function(error){
         alert(error);
         domStyle.set(loading, "display", "none");
        });
        
       });
      }

Thank you Alex
0 Kudos
AnudeepGorantla
Emerging Contributor

I am also working on same king of application If you find a solution can you please share 

0 Kudos
JonathanUihlein
Esri Regular Contributor
Alex, you may want to make a new thread for your question. This thread is many years old.
0 Kudos
AlexGole1
Emerging Contributor
Alex, you may want to make a new thread for your question. This thread is many years old.


I did but nobody really answered.  My problem is very similar to Ben's. I thought one of these guys who have previously worked on this topic could help.
0 Kudos