GP tool to calculate  acres  for new polygons digitized

2082
4
02-21-2014 01:10 PM
AlexGole1
New Contributor II
Hi!
I am trying to figure out the following problem. I am using the ESRI template located here and I would like to add a simple GP tool that allows me to calculate features acres based on a "Double" field called ACRES once I finish digitizing new features (working with one polygon layer). The input value for my GPtool is the feature service layer I am using to digitize (that has an "ACRES" field).

By simply adding the GPtool to the script my feature service disappears from the template picker legend. I am not sure why?? here is the code. I made sure to add thefunction: "Geoprocessor" and the dojo require: "esri/tasks/Geoprocessor" at the beginning.

Thank you for your help,
Alex


        parser.parse();       

        // snapping is enabled for this sample - change the tooltip to reflect this
        jsapiBundle.toolbars.draw.start = jsapiBundle.toolbars.draw.start +  "<br>Press <b>ALT</b> to enable snapping";
       
        // refer to "Using the Proxy Page" for more information:  https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
        esriConfig.defaults.io.proxyUrl = "/proxy";    

        //This service is for development and testing purposes only. We recommend that you create your own geometry service for use within your applications. 
        esriConfig.defaults.geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
        
        map = new Map("map", { 
          basemap: "satellite",
          center: [-96.541, 38.351],
          zoom: 14,
          slider: false 
        });

        map.on("layers-add-result", initEditor);
       
        //add boundaries and place names 
        var polygons = new FeatureLayer("http://webgisdevint1/arcgis/rest/services/Alex_Try/ACRES/FeatureServer/0",{
          mode: FeatureLayer.MODE_ONDEMAND, 
          outFields: ['*']
        });
        //Calling out the GP calculate field acreage
        var gpURL = "http://webgisdevint1/arcgis/rest/services/Alex_Try/Tool/GPServer/Calculate_Acres";
       var gp = new Geoprocessor(gpUrl);
        function executeGP(){
     var params = { "Acres":polygons};
     gp.execute(params, displayTrack);
      }
        //Returns value
        function displayTrack(results, messages) {
     var polygons = results[0].value.features;
      }

        map.addLayers([waterbodies,rivers]);

        function initEditor(evt) {
          var templateLayers = arrayUtils.map(evt.layers, function(result){
            return result.layer;
          });
          var templatePicker = new TemplatePicker({
            featureLayers: templateLayers,
            grouping: true,
            rows: "auto",
            columns: 3
          }, "templateDiv");
          templatePicker.startup();

          var layers = arrayUtils.map(evt.layers, function(result) {
            return { featureLayer: result.layer };
          });
          var settings = {
            map: map,
            templatePicker: templatePicker,
            layerInfos: layers,
            toolbarVisible: true,
            createOptions: {
              polylineDrawTools:[ Editor.CREATE_TOOL_FREEHAND_POLYLINE ],
              polygonDrawTools: [ Editor.CREATE_TOOL_FREEHAND_POLYGON,
                Editor.CREATE_TOOL_CIRCLE,
                Editor.CREATE_TOOL_TRIANGLE,
                Editor.CREATE_TOOL_RECTANGLE
              ]
            },
            toolbarOptions: {
              reshapeVisible: true
            }
          };

          var params = {settings: settings};    
          var myEditor = new Editor(params,'editorDiv');
          //define snapping options
          var symbol = new SimpleMarkerSymbol(
            SimpleMarkerSymbol.STYLE_CROSS, 
            15, 
            new SimpleLineSymbol(
              SimpleLineSymbol.STYLE_SOLID, 
              new Color([255, 0, 0, 0.5]), 
              5
            ), 
            null
          );
          map.enableSnapping({
            snapPointSymbol: symbol,
            tolerance: 20,
            snapKey: keys.ALT
          });
    
          myEditor.startup();
        }
      });[ATTACH=CONFIG]31678[/ATTACH]
0 Kudos
4 Replies
RobertoPepato
Occasional Contributor II
Hi!
I am trying to figure out the following problem. I am using the ESRI template located here and I would like to add a simple GP tool that allows me to calculate features acres based on a "Double" field called ACRES once I finish digitizing new features (working with one polygon layer). The input value for my GPtool is the feature service layer I am using to digitize (that has an "ACRES" field).

By simply adding the GPtool to the script my feature service disappears from the template picker legend. I am not sure why?? here is the code. I made sure to add thefunction: "Geoprocessor" and the dojo require: "esri/tasks/Geoprocessor" at the beginning.

Thank you for your help,
Alex


        parser.parse();       

        // snapping is enabled for this sample - change the tooltip to reflect this
        jsapiBundle.toolbars.draw.start = jsapiBundle.toolbars.draw.start +  "<br>Press <b>ALT</b> to enable snapping";
       
        // refer to "Using the Proxy Page" for more information:  https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
        esriConfig.defaults.io.proxyUrl = "/proxy";    

        //This service is for development and testing purposes only. We recommend that you create your own geometry service for use within your applications. 
        esriConfig.defaults.geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
        
        map = new Map("map", { 
          basemap: "satellite",
          center: [-96.541, 38.351],
          zoom: 14,
          slider: false 
        });

        map.on("layers-add-result", initEditor);
       
        //add boundaries and place names 
        var polygons = new FeatureLayer("http://webgisdevint1/arcgis/rest/services/Alex_Try/ACRES/FeatureServer/0",{
          mode: FeatureLayer.MODE_ONDEMAND, 
          outFields: ['*']
        });
        //Calling out the GP calculate field acreage
        var gpURL = "http://webgisdevint1/arcgis/rest/services/Alex_Try/Tool/GPServer/Calculate_Acres";
       var gp = new Geoprocessor(gpUrl);
        function executeGP(){
     var params = { "Acres":polygons};
     gp.execute(params, displayTrack);
      }
        //Returns value
        function displayTrack(results, messages) {
     var polygons = results[0].value.features;
      }

        map.addLayers([waterbodies,rivers]);

        function initEditor(evt) {
          var templateLayers = arrayUtils.map(evt.layers, function(result){
            return result.layer;
          });
          var templatePicker = new TemplatePicker({
            featureLayers: templateLayers,
            grouping: true,
            rows: "auto",
            columns: 3
          }, "templateDiv");
          templatePicker.startup();

          var layers = arrayUtils.map(evt.layers, function(result) {
            return { featureLayer: result.layer };
          });
          var settings = {
            map: map,
            templatePicker: templatePicker,
            layerInfos: layers,
            toolbarVisible: true,
            createOptions: {
              polylineDrawTools:[ Editor.CREATE_TOOL_FREEHAND_POLYLINE ],
              polygonDrawTools: [ Editor.CREATE_TOOL_FREEHAND_POLYGON,
                Editor.CREATE_TOOL_CIRCLE,
                Editor.CREATE_TOOL_TRIANGLE,
                Editor.CREATE_TOOL_RECTANGLE
              ]
            },
            toolbarOptions: {
              reshapeVisible: true
            }
          };

          var params = {settings: settings};    
          var myEditor = new Editor(params,'editorDiv');
          //define snapping options
          var symbol = new SimpleMarkerSymbol(
            SimpleMarkerSymbol.STYLE_CROSS, 
            15, 
            new SimpleLineSymbol(
              SimpleLineSymbol.STYLE_SOLID, 
              new Color([255, 0, 0, 0.5]), 
              5
            ), 
            null
          );
          map.enableSnapping({
            snapPointSymbol: symbol,
            tolerance: 20,
            snapKey: keys.ALT
          });
    
          myEditor.startup();
        }
      });[ATTACH=CONFIG]31678[/ATTACH]


Hi Alex,

That's not exactly the answer you expect about your GP problem but, have you looked at the Measurement sample? Do you have any requirement that impedes yourself of using the Measurement class? I think that, in the end, it would be simpler than dealing with a remote GP tool. What do you think about it?
0 Kudos
AlexGole1
New Contributor II
Hi Alex,

That's not exactly the answer you expect about your GP problem but, have you looked at the Measurement sample? Do you have any requirement that impedes yourself of using the Measurement class? I think that, in the end, it would be simpler than dealing with a remote GP tool. What do you think about it?


I might be wrong (i thought about using it) because I am quite new to the Javascript API but doesnt the measurement widget only work with graphics? If it works  How would I use it in the script I am using?

Thank you,
Alex
0 Kudos
RobertoPepato
Occasional Contributor II
I might be wrong (i thought about using it) because I am quite new to the Javascript API but doesnt the measurement widget only work with graphics? If it works  How would I use it in the script I am using?

Thank you,
Alex


I don't know if I got it what you mean but when you said "once I finish digitizing new features (working with one polygon layer)" I understood that you'd to draw the polygons. If what you want is to calculate the area for a set of already drawn (an stored) polygons on a FeatureLayer I think that the GP usage is a better solution.

Could you please confirm if I got something wrong?

Also, could you post your full-page code so I can try to create a sample to send you back?

Thanks!
0 Kudos
AlexGole1
New Contributor II
I don't know if I got it what you mean but when you said "once I finish digitizing new features (working with one polygon layer)" I understood that you'd to draw the polygons. If what you want is to calculate the area for a set of already drawn (an stored) polygons on a FeatureLayer I think that the GP usage is a better solution.

Could you please confirm if I got something wrong?

Also, could you post your full-page code so I can try to create a sample to send you back?

Thanks!


That is correct. I am working with a feature service (feature layer). One of my goal is create a Javascript functionality (or GP tool) that would automatically calculate a field called "ACRES" (double) once the new polygon (feature layer) is digitized. It seemed like a GP tool would do the trick but I am not sure. I am also currently looking into AreasAndLengthsParameters. Let me know if you think of a better way to do so.
Thank you,
Alex

I am using this sample https://developers.arcgis.com/javascript/jssamples/ed_simpletoolbar.html