It's all a proof of concept for myself and my learning but I have definitely hit a brick wall here!

Here's what I've done and can get to work.

I have written a Python script that:

  1. Sets its workspace to and SDE instance.
  2. Checks out a Spatial licencse.
  3. Queries raster layers.
  4. Takes a raster layer based on some string match - and then adds 100 to each pixel to create an output raster. Raster Algebra stuff....
  5. The output raster is saved in the scratch workspace as "wibble".


I can Share As A Geoprocessing Service and it does all the same stuff and saves an output raster to the ArcGIS Servers output directory with a Scratch FGDB there and a raster called "wibble".


I want to run my Geoprocessing task from the browser using JS API and that works too, and it puts the output raster in a jobs folder - looking something like this:


My code for the geoprocessor looks like:

var gp = new Geoprocessor("http://ls8-webd-w8v:6080/arcgis/rest/services/TestRaster/GPServer/TestRaster");
var params = { "inputMessage": dom.byId("testMessage").value };
        gp.submitJob(params, completeCallback, statusCallback);

So how do I now hook up my JavaScript code to get hold of this "wibble" raster and display it on a map in the browser. Now, I know you are not able to directly draw out rasters to a map service, it has to be an image, so you use getResultImageLayer from the geoprocessing object, but it still doesn't display, I think the code is wrong:

function completeCallback(jobInfo) {
    imageParams = new ImageParameters();
    imageParams.imageSpatialReference = map.spatialReference;
    gp.getResultImageLayer(jobInfo.jobId, "wibble", imageParams, function (gpLayer) {

I'm not even doing anything with ImageParameters - as I'm not sure what to do. Then I tried a different way, still nothing.

function completeCallback(jobInfo) {
    mapserviceurl = "http://ls8-webd-w8v:6080/arcgis/rest/services/TestRaster/GPServer/TestRaster/jobs";
    var mapurl = mapserviceurl + "/" + jobinfo.jobId;

    var outputLayer = new ArcGISDynamicMapServiceLayer(mapurl, {
        "id": "TestRaster",
        "opacity": 0.7


Oh, by the way - here is the python that makes the geoprocessing script - it's nothing major!

import arcpy, os, sys
from arcpy.sa import *

inputSde = r"Database Connections\ls8-dbd-w8v-2_geodb_GEOLOGY.sde"
arcpy.env.overwriteOutput = True

inputString = arcpy.GetParameterAsText(0)

def main():
        if arcpy.CheckExtension("Spatial") == "Available":         
            raise LicenseError

        arcpy.env.workspace = inputSde
        outRas = None

        rastersStrings = arcpy.ListRasters("*", "All");

        for strRaster in rastersStrings:
            if strRaster == "GEOLOGY.MAAS_BATHYMETRY":
                path = os.path.join(inputSde, strRaster)
                raster = Raster(path)
                outRas = raster + 100
                if outRas is not None:
                    tempFile = os.path.join(arcpy.env.scratchGDB, "wibble")
                    arcpy.AddWarning("Failed to make raster")

    except LicenseError:
        print "Spatial license is unavailable"  
         arcpy.AddWarning("Error: {0}".format(sys.exc_info()[0]))

if __name__ == '__main__':

I get the following Javascript error message for using the ImageParameters code (as above) - saying its "400 a bad request" - it looks like its looking in a folder "results" but I don't have that on the server - could it be to do with how I am saving the raster in the Python script?


2 Answers 2


A couple of thoughts:


I found the solution - and it was only one or two things that were missing.

  1. In the python script I needed to add:


if outRas is not None:
  arcpy.AddWarning("Made a new raster")
  tempFile = os.path.join(arcpy.env.scratchGDB, "wibble")
  arcpy.SetParameterAsText(1, tempFile) #THIS WAS MISSING

Then when you make the tool in the toolobox - you need to set the output parameter like so:

enter image description here

Make sure it's of type Raster Layer (the name is important "output" as this is used in the Javascript bit to add the layer. The type should be Derived and the direction should be Output.

The following Javascript adds the image to the map with specifying it by name - "output" -

 var imageParams = new ImageParameters();

     imageParams.imageSpatialReference = map.spatialReference;
     gp.getResultImageLayer(jobInfo.jobId, "output", imageParams, function (gpLayer) {

Also make sure your geoprocessing service is Asyncronous and "View results with a map service" is checked. These setting are found in the Parameters page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.