0

I am trying to calculate the average raster value over a watershed boundary.

I have published a geoprocessing service on geoserver that works when accessed in ArcMAP. The user clicks a point and then the watershed is delineated, and the stats of the raster (published with the service) are calculated using Zonal Statistics as Table. The service works in ArcMap.

When I try to access the service through the API, the function completeCallback fails.

I have also published another service that only delineates the watershed.

This service works with the API and the watershed is drawn on the map. But the service that includes Zonal Statistics fails.

Is it because I have multiple outputs ?

How do I make it draw the watershed and then access the results of the table ?

<script>
require([
  "esri/Map",
  "esri/layers/GraphicsLayer",
  "esri/Graphic",
  "esri/geometry/Point",
  "esri/tasks/Geoprocessor",
  "esri/tasks/support/LinearUnit",
  "esri/tasks/support/FeatureSet",
  "esri/views/MapView",
  "dojo/domReady!"
], function(Map, GraphicsLayer, Graphic, Point, Geoprocessor, LinearUnit, FeatureSet, MapView){

    //a map with basemap
    var map = new Map({
    basemap: "streets"
    });

    //a graphics layer to show input point and output polygon
    var graphicsLayer = new GraphicsLayer();
    map.add(graphicsLayer);

    var view = new MapView({
    container: "viewDiv",
    map: map,
    center: [-111.643245, 40.324884],
    zoom: 11
    });

    // symbol for input point
    var markerSymbol = {
          type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
          color: [0, 255, 255],
          outline: { // autocasts as new SimpleLineSymbol()
            color: [0, 122, 122],
            width: 2
          }
        };

    // symbol for watershed boundary
    var fillSymbol = {
          type: "simple-fill", // autocasts as new SimpleFillSymbol()
          color: [226, 119, 40, 0.75],
          outline: { // autocasts as new SimpleLineSymbol()
            color: [255, 255, 255],
            width: 1
          }
        };

    // Geoprocessing service url
    var gpUrl = "http://geoserver2.byu.edu/arcgis/rest/services/3_Toed_Sloth/SnowmeltCalcTable/GPServer/Snowmelt%20Calc%20Table";

    // create a new Geoprocessor
    var gp = new Geoprocessor(gpUrl);
    // define output spatial reference
    gp.outSpatialReference = { // autocasts as new SpatialReference()
          wkid: 102100 //EPSG3857
        };
    //add map click function
    view.on("click", watershed);

    var featureSet = new FeatureSet();
    var lat;
    var lon;

    //main function
    function watershed(event) {

          graphicsLayer.removeAll();
          var point = new Point({
            longitude: event.mapPoint.longitude,
            latitude: event.mapPoint.latitude
          });
          var inputGraphic = new Graphic({
            geometry: point,
            symbol: markerSymbol
          });
          graphicsLayer.add(inputGraphic);
          var inputGraphicContainer = [];
          inputGraphicContainer.push(inputGraphic);

          lat = event.mapPoint.latitude;
          lon = event.mapPoint.longitude;

          featureSet.features = inputGraphicContainer;
    }

    // What happens when you click the "Delineate Watershed" Button
    $(document).ready(function () {
        $("#delineate").click(function () {
            processRequest();
        });
    });

    function processRequest(){

        if ( isNaN(lat) && isNaN(lon) ) {  // User did not click a point
            alert("Please choose an outlet point by clicking on the map.");

        } else {
        // Delineate watershed
            $("#loadingstuff").html("<h2 style='text-align: center'>LOADING WATERSHED</h2><img src='https://media.giphy.com/media/3og0INAY5MLmEBubyU/giphy.gif' style='width: 100%'>");

            // input parameters
            var params = {
            "Input_Pour_Point": featureSet,
            };
            gp.submitJob(params).then(completeCallback, errBack, statusCallback);
        }
    }

    function completeCallback(result){
        console.log(result);
        gp.getResultData(result.jobId, "Output_Watershed_Boundary").then(drawResult, drawResultErrBack);
    }

    function drawResult(data){
        $("#loadingstuff").html("");
        alert("About to draw stuff");
        var polygon_feature = data.value.features[1];
        polygon_feature.symbol = fillSymbol;
        graphicsLayer.add(polygon_feature);
    }

    function drawResultErrBack(err) {
        console.log("draw result error: ", err);
    }

    function statusCallback(data) {
        console.log(data.jobStatus);
    }
    function errBack(err) {
        console.log("gp error: ", err);
    }
});

  • You can have 1 or 100 outputs in a gp service. But the guts of the service needs to return something for every output. There is nothing in your code that leads me to believe the service itself would operate differently from ArcMap compared to JS. Everything looks "ok", but your code sample doesnt include the HTML bits, so it cannot be run to debug without some extra effort. I'd focus on that input FeatureSet and ensuring what you submit to the GP Service is valid. From a high level it looks correct, but without debugging, maybe not. – KHibma Apr 3 at 14:49
  • Hi Chris, I would suggest you to check if the GP Service works well, and if it really returns something. Check the ArcGIS Server Logs and be sure that there is no errors. From my experience, it seems to be that the GP Service doesn't work well, so there is no JS problem. – Katah Apr 4 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.