Change a geometry service to a geoprocessing service

647
9
01-14-2014 09:14 PM
ArcGISG_I_S
New Contributor
Hi everyone,

I need your help in one problem that i am facing the last 3 days.
I create one web app using javascript that allow me to add point in the map and create buffer around each point (I used Geometry Service), now i should merge any buffer who intersect with the other one, so i create one model in model builder using Dissolve All and i publish it as a geoprocessing service.
That give me a url like: http://IP:6080/arcgis/rest/services/Service_Name/GPServer/Model_Name.

I tried to repalce the URL that i used for the geometry service by this URL but its not working.
Below is the Head code for the geometry service if you can help me to found the changes that i should do to have the result.

require(["dojo/dom",
          "dojo/dom-attr",
          "dojo/_base/array",
          "dojo/_base/Color",
          "dojo/parser",

          "esri/config",
          "esri/map",
          "esri/graphic",
   
          "esri/tasks/GeometryService",
          "esri/tasks/BufferParameters",
   
          "esri/toolbars/draw",
   
          "esri/symbols/SimpleMarkerSymbol",
          "esri/symbols/SimpleLineSymbol",
          "esri/symbols/SimpleFillSymbol",
         
          "dijit/layout/BorderContainer",
          "dijit/layout/ContentPane"],
   
    function(dom, domAttr, array, Color, parser, esriConfig, Map,
Graphic, GeometryService, BufferParameters, Draw, SimpleMarkerSymbol,
SimpleLineSymbol, SimpleFillSymbol)

{
      var map, geo, tb;
     
   parser.parse();
      map = new Map("map", {
        basemap: "streets",
        center: [-122.4, 37.785],
        zoom: 13,
      });
  
esriConfig.defaults.io.proxyUrl = "/proxy";
    esriConfig.defaults.io.alwaysUseProxy = false;  

geo = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
  
    map.on("load", initToolbar);

/*
**  Initialize the drawing toolbar
*/
function initToolbar(evtObj) {
      app.tb = new Draw(evtObj.map);
      app.tb.on("draw-end", drawPoint);
    }

// Array where points are saved
var list = new Array();

/*
    ** Draw point
*/
function drawPoint(evtObj) {
      // Get the click geometry
   var geometry = evtObj.geometry; 
   
   // Point symbol
      var symbol = new SimpleMarkerSymbol(
     SimpleMarkerSymbol.STYLE_SQUARE,
  10,
  new SimpleLineSymbol(
    SimpleLineSymbol.STYLE_SOLID,
    new Color([255,0,0]),
    1),
  new Color([0,255,0,0.25])
   );
  
   // Add point to the map
      var graphic = new Graphic(geometry, symbol);
      app.map.graphics.add(graphic);

   // Store the point geometry
   list.push(geometry)
}

/*
    **  Create buffer around points
*/
function doBuffer() {
   // Stop drawing points
   app.tb.deactivate();

   // Show the zoom slider
      app.map.showZoomSlider();
  
      // Setup the buffer parameters
      var params = new BufferParameters();
      params.distances = [ dom.byId("distance").value ];
      params.bufferSpatialReference = new esri.SpatialReference({wkid: dom.byId("bufferSpatialReference").value});
      params.outSpatialReference = map.spatialReference;
      params.unit = GeometryService[dom.byId("unit").value];
   params.geometries = list;
  
   // Launch buffer calculation
      app.geo.buffer(params, showBuffer);
    };

/*
    **  Draw buffer on the map
*/
    function showBuffer(geoms) {
   // Symbol of the buffer
      var symbol = new SimpleFillSymbol(
        SimpleFillSymbol.STYLE_SOLID,
        new SimpleLineSymbol(
          SimpleLineSymbol.STYLE_SOLID,
          new Color([255,0,0,0.65]), 2
        ),
        new Color([255,0,0,0.35])
      );
     
   // Add the buffer graphics to the map
   array.forEach(geoms, function(geometry) {
        var graphic = new Graphic(geometry, symbol);
        app.map.graphics.add(graphic);
      });  
    }
 
    app = {
      map: map,
      tb: tb,
      geo: geo,
   buffer: doBuffer
    };
  });
 
  /*
  ** Click on Foggy Zone button
  */
  function foggyZoneClick(){
app.buffer();
  }
 
  /*
  ** Click on Point button
  */
  function pointClick(){
    app.tb.activate(esri.toolbars.Draw.POINT);
app.map.hideZoomSlider();
  }

Any help is appreciate (Its really urgent 😞 )
0 Kudos
9 Replies
JeffJacobson
Occasional Contributor III
When you post code on the forums be sure you use the
 tags to preserve your indentation, making the code easier for others to read.

require(["dojo/dom",
    "dojo/dom-attr",
    "dojo/_base/array",
    "dojo/_base/Color",
    "dojo/parser",

    "esri/config",
    "esri/map",
    "esri/graphic",

    "esri/tasks/GeometryService",
    "esri/tasks/BufferParameters",

    "esri/toolbars/draw",

    "esri/symbols/SimpleMarkerSymbol",
    "esri/symbols/SimpleLineSymbol",
    "esri/symbols/SimpleFillSymbol",

    "dijit/layout/BorderContainer",
    "dijit/layout/ContentPane"],

function (dom, domAttr, array, Color, parser, esriConfig, Map,
Graphic, GeometryService, BufferParameters, Draw, SimpleMarkerSymbol,
SimpleLineSymbol, SimpleFillSymbol)

{
    var map, geo, tb;

    parser.parse();
    map = new Map("map", {
        basemap: "streets",
        center: [-122.4, 37.785],
        zoom: 13
    });

    esriConfig.defaults.io.proxyUrl = "/proxy";
    esriConfig.defaults.io.alwaysUseProxy = false;

    geo = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

    map.on("load", initToolbar);

    /*
     ** Initialize the drawing toolbar
     */
    function initToolbar(evtObj) {
        app.tb = new Draw(evtObj.map);
        app.tb.on("draw-end", drawPoint);
    }

    // Array where points are saved
    var list = [];

    /*
     ** Draw point
     */
    function drawPoint(evtObj) {
        // Get the click geometry
        var geometry = evtObj.geometry;

        // Point symbol
        var symbol = new SimpleMarkerSymbol(
        SimpleMarkerSymbol.STYLE_SQUARE,
        10,
        new SimpleLineSymbol(
        SimpleLineSymbol.STYLE_SOLID,
        new Color([255, 0, 0]),
        1),
        new Color([0, 255, 0, 0.25]));

        // Add point to the map
        var graphic = new Graphic(geometry, symbol);
        app.map.graphics.add(graphic);

        // Store the point geometry
        list.push(geometry);
    }

    /*
     ** Create buffer around points
     */
    function doBuffer() {
        // Stop drawing points
        app.tb.deactivate();

        // Show the zoom slider
        app.map.showZoomSlider();

        // Setup the buffer parameters
        var params = new BufferParameters();
        params.distances = [dom.byId("distance").value];
        params.bufferSpatialReference = new esri.SpatialReference({
            wkid: dom.byId("bufferSpatialReference").value
        });
        params.outSpatialReference = map.spatialReference;
        params.unit = GeometryService[dom.byId("unit").value];
        params.geometries = list;

        // Launch buffer calculation
        app.geo.buffer(params, showBuffer);
    }

    /*
     ** Draw buffer on the map
     */
    function showBuffer(geoms) {
        // Symbol of the buffer
        var symbol = new SimpleFillSymbol(
        SimpleFillSymbol.STYLE_SOLID,
        new SimpleLineSymbol(
        SimpleLineSymbol.STYLE_SOLID,
        new Color([255, 0, 0, 0.65]), 2),
        new Color([255, 0, 0, 0.35]));

        // Add the buffer graphics to the map
        array.forEach(geoms, function (geometry) {
            var graphic = new Graphic(geometry, symbol);
            app.map.graphics.add(graphic);
        });
    }

    app = {
        map: map,
        tb: tb,
        geo: geo,
        buffer: doBuffer
    };
});

/*
 ** Click on Foggy Zone button
 */
function foggyZoneClick() {
    app.buffer();
}

/*
 ** Click on Point button
 */
function pointClick() {
    app.tb.activate(esri.toolbars.Draw.POINT);
    app.map.hideZoomSlider();
}
0 Kudos
ArcGISG_I_S
New Contributor
Hi,

Ok jacobsj next time i will use it, so you can provide me with the an answer or any body can help 😞
0 Kudos
RobertoPepato
Occasional Contributor II
I think that this happens because you're not accessing a GeometryService anymore (but still are using an instance of the GeometryService). You need a specialized task to do the job of calling and handling your custom GP service.

Take a look at the Geoprocessor class: https://developers.arcgis.com/en/javascript/jsapi/geoprocessor-amd.html
0 Kudos
ArcGISG_I_S
New Contributor
Hi pepatosp,

Thanks for your feedback, it's exactly the problem i'am facing, even if i'am changing the geometry service and using geoprocessing service i'am still using an instance of the GeometryService.

I check the URL that you send me i found some classes that i change but still not working if you can provide me with more help i will be grateful.

Thanks a lot for your support
0 Kudos
RobertoPepato
Occasional Contributor II
Hi pepatosp,

Thanks for your feedback, it's exactly the problem i'am facing, even if i'am changing the geometry service and using geoprocessing service i'am still using an instance of the GeometryService.

I check the URL that you send me i found some classes that i change but still not working if you can provide me with more help i will be grateful.

Thanks a lot for your support


Could you post your full updated code here? This would help to diagnose your issue.
0 Kudos
ArcGISG_I_S
New Contributor
Dear pepatosp,

bellow the full updated code:

<!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>Foggy Buffer Zone</title>

  <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/dojo/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css">
  <style>
     html, body {
      height: 100%;
      width: 100%;
      margin: 0; 
      padding: 0;
      overflow:hidden;
    }
    #leftPane{
      color:#000;
      width:250px;
      padding-bottom:15px;
    }
    #map{
      padding:0;
    }
    .details{
      font-size:14px;
      font-weight:600;
      padding-bottom:20px;
    }
  </style>

  <script src="http://js.arcgis.com/3.7/"></script>
  <script>
  require(["dojo/dom",
          "dojo/dom-attr",
          "dojo/_base/array",
          "dojo/_base/Color",
          "dojo/parser",

          "esri/config",
          "esri/map",
          "esri/graphic",
              
    "esri/tasks/Geoprocessor",
    "esri/tasks/FeatureSet",
          "esri/tasks/LinearUnit",
    
          "esri/toolbars/draw",
    
          "esri/symbols/SimpleMarkerSymbol",
          "esri/symbols/SimpleLineSymbol",
          "esri/symbols/SimpleFillSymbol",
          
          "dijit/layout/BorderContainer",
          "dijit/layout/ContentPane"],
    
    function(dom, domAttr, array, Color, parser, esriConfig, Map, 
 Graphic, Geoprocessor, FeatureSet, LinearUnit, Draw, 
 SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol)
 
 {
      var map, gp, tb;
      
parser.parse();
      map = new Map("map", {
        basemap: "streets",
        center: [-122.4, 37.785],
        zoom: 13,
      });
   
 esriConfig.defaults.io.proxyUrl = "/proxy";
    esriConfig.defaults.io.alwaysUseProxy = false;   
 
 gp = new Geoprocessor("http://localhost:6080/arcgis/rest/services/SFFoggyZone/GPServer/Model");
 
   //gp.setOutputSpatialReference({
              //wkid: 32612
            //});
   
    map.on("load", initToolbar);
 
 /* 
 **  Initialize the drawing toolbar
 */
 function initToolbar(evtObj) {
      app.tb = new Draw(evtObj.map);
      app.tb.on("draw-end", drawPoint);
    }

 // Array where points are saved
 var list = new Array();
 
 /*
    ** Draw point
 */
 function drawPoint(evtObj) { 
      // Get the click geometry 
   var geometry = evtObj.geometry;  
    
   // Point symbol
      var symbol = new SimpleMarkerSymbol(
     SimpleMarkerSymbol.STYLE_SQUARE, 
  10, 
  new SimpleLineSymbol(
    SimpleLineSymbol.STYLE_SOLID, 
    new Color([255,0,0]), 
    1), 
  new Color([0,255,0,0.25])
   );
   
   // Add point to the map
      var graphic = new Graphic(geometry, symbol);
      app.map.graphics.add(graphic);

   // Store the point geometry
   list.push(geometry)
 }
 
 /*
    **  Create buffer around points
 */
 function doBuffer() {
   // Stop drawing points
   app.tb.deactivate();

   // Show the zoom slider
      app.map.showZoomSlider();
   
      // Setup the buffer parameters
     // var params = new BufferParameters();
     // params.distances = [ dom.byId("distance").value ];
    //  params.bufferSpatialReference = new esri.SpatialReference({wkid: dom.byId("bufferSpatialReference").value});
     // params.outSpatialReference = map.spatialReference;
     // params.unit = GeometryService[dom.byId("unit").value];
 //  params.geometries = list;
   
   var features = [];
     // features.push(graphic);
   var featureSet = new FeatureSet();
      featureSet.features = features;
   var distances = new LinearUnit();
      distances.distance = [ dom.byId("Dis").value ];
      distances.units = [dom.byId("unit").value];
  // var bufferSpatialReference = new gp.setOutputSpatialReference({wkid: dom.byId("bufferSpatialReference").value});
   var params = {
              "Foggy_Points":FeatureSet,
     "Boundary_Polygons":FeatureSet,
              "Buffer_Distance": distances,
     "bufferSpatialReference": dom.byId("bufferSpatialReference").value
            };

   // Launch buffer calculation
     // app.geo.buffer(params, showBuffer);
   gp.execute(params, showBuffer);
    };

 /*
    **  Draw buffer on the map
 */
    function showBuffer(geoms) {
   // Symbol of the buffer
      var symbol = new SimpleFillSymbol(
        SimpleFillSymbol.STYLE_SOLID,
        new SimpleLineSymbol(
          SimpleLineSymbol.STYLE_SOLID,
          new Color([255,0,0,0.65]), 2
        ),
        new Color([255,0,0,0.35])
      );
      
   // Add the buffer graphics to the map
   array.forEach(geoms, function(geometry) {
        var graphic = new Graphic(geometry, symbol);
        app.map.graphics.add(graphic);
      });   
    }
  
    app = {
      map: map,
      tb: tb,
      geo: geo,
   buffer: doBuffer
    };
  });
  
  /*
  ** Click on Foggy Zone button
  */
  function foggyZoneClick(){
 app.buffer();
  }
  
  /*
  ** Click on Point button
  */
  function pointClick(){
    app.tb.activate(esri.toolbars.Draw.POINT);
 app.map.hideZoomSlider();
  }
  
  /*
  ** Click on Clear Graphics button
  */
  function clearGraphicsClick(){
    app.map.graphics.clear();
  }
  </script>

</head>

<body class="claro">
  <div data-dojo-type="dijit.layout.BorderContainer" 
       data-dojo-props="gutters:'true', design:'sidebar'" 
       style="width:100%;height:100%;">

    <div id="map" 
         data-dojo-type="dijit.layout.ContentPane" 
         data-dojo-props="region:'center'">
    </div>

    <div id="leftPane" 
         data-dojo-type="dijit.layout.ContentPane" 
         data-dojo-props="region:'left'">
   
   <div><b>Foggy Zone Parameters</b></div>
      Spatial Reference WKID: <input type="text" id="bufferSpatialReference" size="5" value="32612" /><br />
      Distance: <input type="text" id="Dis" size="5" value="1" />
      <select id="unit" style="width:100px;">
   <option value="UNIT_KILOMETER">Kilometers</option>
   <option value="UNIT_METER">Meters</option>
        <option value="UNIT_STATUTE_MILE">Miles</option>
      </select><br />
<hr />
      <div class="details">Please enter points of the Foggy Zone</div>   
      <button data-dojo-type="dijit.form.Button" onclick="pointClick();">Report Fog</button>
    <button id="point" data-dojo-type="dijit.form.Button" onclick="foggyZoneClick();">Foggy Zone</button>
      <button data-dojo-type="dijit.form.Button" type="button" onclick="clearGraphicsClick();">Clear Graphics</button>
<br />
 
    </div>
  </div>
  
</body>
</html>
0 Kudos
RobertoPepato
Occasional Contributor II
Could you also post the error message on your javascript console? As you're running a local GP service, I can't run it here to reproduce and analyze your issue.

I'm curious about one thing: Does your GP service do some specialized buffer operation?
0 Kudos
ArcGISG_I_S
New Contributor
Dear pepatosp,

I' am using a buffer service attached you will find a print screen of the model that i am using that will help you.

Foggy Point: are the points that we should add to the map
Boundary Polygon: is the limit of the area in order to be sure that our buffer zone not across this area.
Buffer distance: the value of the size of the buffer.

Thx a lop for your support.
[ATTACH=CONFIG]30648[/ATTACH]
0 Kudos
ArcGISG_I_S
New Contributor
Good morning,

Any suggestions to help!! i'am still facing the same problem ?!

Thanks.
0 Kudos