As Arcgis for server has not a built in download shapefile(or any other format) functionality the "clip and ship" geoprocessing example is being suggested by many users and developers. However I find it quite limiting. As far as I understand, the "Extract Data" tool requires first to be run with a pre-defined set of Layers as a "Parameter" just like the "Zion" example.
What I (and many other developers) need is a script/service that takes an Arcgis Server service as an input (or a relevant js object like featureset) and returns a shapefile (or any other format) as an output. Of course I am referring to a client web application. I am using the Javascript API but if I am not mistaken Flex developers face the same issue. Thanks.
I too am looking for a way to export a layer. The clip and ship is not a solution when it comes to a user picking a layer from the list to export. Unless someone knows of a way to modify the geoprocessing service to take an the proper variables.
i tried this example but it does not work:
ArcGIS API for JavaScript Sandbox
how do i create the geoprocessing service?
Robert,
As you probably notice, sample server 4 does not have the GP service available anymore. Here is the help doc link for creating your own clip and ship GP service:
Thanks. The link you sent only takes me to:
I dint see the example. I will search for it.
Robert,
Sorry I thought they fixed that link issue. Here is the link as plain text (don't click the link, just copy the text and paste it into your browsers address bar):
Hi all,
As I wrote in original post, the limitation of the above solutions is that you have to predefine the layers to clip/download. What I did to work around this limitation was to write a small script on the server, I used C# but anything will work, that provides a single service. That service takes a WFS link as an input and builds a shapefile using the GDAL library. Then wraps it up in a zip file, puts it on the server and returns a link to the file...
Not the most efficient way to do it and might time-out for large datasets but I haven't found anything better.
To avoid the timeouts you can instead of returning a link to the file, send an email with the link to the user when the zip file is ready.
I have tested libraries in js that build the shapefile on the client but they were slower and time-out a lot more.
It would be great (and surely easy to develop) if this could be done with a build in GP service.
Cheers
i found this link in the forums:
Could Not Add The Specified Data Object to the Map
and made this work:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--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>Extract Data</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.14/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">
<style>
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
visibility: hidden;
font-family: sans-serif;
}
.claro .dijitBorderContainer-child {
border: none;
}
.claro .dijitBorderContainer-dijitContentPane, .claro .dijitContentPane {
padding: 0;
}
.claro .dijitTitlePaneContentInner {
line-height: 1.4em;
}
#controls {
position:absolute;
top:1em;right:1em;
width:auto !important;
height:auto !important;
z-index:10;
}
#loading {
display: none;
vertical-align: middle;
}
.freehandIcon { background-image:url(./images/i_draw_freepoly.png); width:20px; height:20px; }
.polyIcon { background-image:url(./images/i_draw_poly.png); width:20px; height:20px;}
</style>
<script src="http://js.arcgis.com/3.14/"></script>
<script>
var gp, map;
var selectionToolbar;
require([
"esri/map", "esri/config",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/tasks/Geoprocessor", "esri/tasks/FeatureSet", "esri/toolbars/draw",
"esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol",
"esri/graphic",
"esri/Color",
"dojo/dom", "dojo/dom-style", "dojo/query", "dojo/parser",
"dijit/registry",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane",
"dijit/TitlePane", "dijit/form/CheckBox", "dijit/form/ComboBox",
"dojo/domReady!"
], function(
Map, esriConfig,
ArcGISDynamicMapServiceLayer,
Geoprocessor, FeatureSet, Draw,
SimpleFillSymbol, SimpleLineSymbol,
Graphic,
Color,
dom, domStyle, query, parser,
registry
) {
// Create all dijits.
parser.parse();
// Prevent flash of unstyled content(FOUC).
domStyle.set(query("body")[0], "visibility", "visible");
// Specify where the location of the proxy to use to communicate with the extract GP service.
esriConfig.defaults.io.proxyUrl = "/proxy/";
// Keep a reference to the loading icon DOM node.
var loading = dom.byId("loading");
map = new Map("map", {
basemap: "streets",
center: [-104.946372, 43.433484],
zoom: 7,
});
map.on("load", initSelectionToolbar);
var homelandSecurity = new ArcGISDynamicMapServiceLayer("https://wygiscservices-dev.wygisc.org/arcgis/rest/services/EORI/Geologic_Clip/MapServer");
map.addLayer(homelandSecurity);
gp = new Geoprocessor("https://wygiscservices-dev.wygisc.org/arcgis/rest/services/EORI/MyGPService/GPServer/Extract%20Data%...");
gp.setOutSpatialReference({wkid:3857});
registry.byId("polygon").on("click", function() {
activateTool(this.id);
});
registry.byId("freehandpolygon").on("click", function() {
activateTool(this.id);
});
registry.byId("extract").on("click", extractData);
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("layer3").get("checked") ) { clipLayers.push("Bedrock Geology"); }
if ( clipLayers.length === 0 || map.graphics.graphics.length === 0 ) {
alert("Select layers to extract and draw an area of interest.");
return;
}
var featureSet = new FeatureSet();
var features = [];
features.push(map.graphics.graphics[0]);
featureSet.features = features;
var params = {
"Layers_to_Clip": clipLayers,
"Area_of_Interest": featureSet,
"Feature_Format": registry.byId("formatBox").get("value")
};
domStyle.set(loading, "display", "inline-block");
gp.submitJob(params, completeCallback , statusCallback, function(error){
alert(error);
domStyle.set(loading, "display", "none");
});
}
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);
domStyle.set("loading", "display", "none");
}
else if (status === "esriJobSucceeded"){
domStyle.set("loading", "display", "none");
}
}
function downloadFile(outputFile){
map.graphics.clear();
var theurl = outputFile.value.url;
window.location = theurl;
}
});
</script>
</head>
<body class="claro">
<div data-dojo-type="dijit/layout/BorderContainer"
data-dojo-prps="gutters:false"
style="width: 100%; height: 100%;margin:0;">
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'">
<div data-dojo-type="dijit/TitlePane" data-dojo-props="title:'Extract Data'" id="controls">
1.Select area of interest
<br>
<button id="polygon"
data-dojo-type="dijit/form/Button"
data-dojo-props="iconClass:'polyIcon', showLabel:false">
Polygon
</button>
<button id="freehandpolygon"
data-dojo-type="dijit.form.Button"
data-dojo-props="iconClass:'freehandIcon', showLabel:false">
Freehand
</button>
<br><br>
2.Select Layers to extract data from
<br>
<input id="layer3" data-dojo-type="dijit/form/CheckBox" checked="checked" type="checkbox"/>
<label for="layer3">Incident Area</label>
<br><br>
3.Specify download format
<br>
<select data-dojo-type="dijit/form/ComboBox" id="formatBox">
<option>Shapefile - SHP - .shp</option>
<option>File Geodatabase - GDB - .gdb</option>
<option>Autodesk AutoCAD - DXF_R2007 - .dxf</option>
<option>Autodesk AutoCAD - DWG_R2007 - .dwg</option>
<option>Bentley Microstation Design (V8) - DGN_V8 - .dgn</option>
</select>
<br><br>
<button id="extract" data-dojo-type="dijit/form/Button">Extract Data</button>
<img id="loading" src="images/loading.gif">
</div>
</div>
</div>
</body>
</html>
One problem i am having with the tutorial is that it wont let me do this:
I get the error object could not be added to the map.
You must be using the 10.0 version of the tutorial. Try the 10.1+ version here: Geoprocessing service example: Clip And Ship—Sharing geoprocessing workflows | ArcGIS for Desktop
(The steps you mention are telling you to make a "tool layer", a concept that does not exist in 10.1+)