Select to view content in your preferred language

output raster in Geoprocessing widget in webapp

958
6
03-11-2021 09:06 AM
yaronmic
Emerging Contributor

Hi, I am trying to publish a relatively simple python script as a Geoprocessing widget insde a webpp
The tool works well when executed locally.
and publishes to ArcGIS Server
But I did not understand from esri guide
how do i add raster that wil show after the user active the widget 

this is the scripts ,how do i add the output raster to the map that the user see in the webmap
Thank you very much

import arcpy
from arcpy import env
from arcpy.sa import *
#arcpy.env.scratchWorkspace = 'c:/temp/scratchoutput.gdb'
number = arcpy.GetParameterAsText(0)

#Pop_Total
statData = "C:\\arcprotest\\b.tif"

#def main():
out_raster = arcpy.sa.Plus(statData,int(number))#out_raster.save("test")# how do i add this raster to the webmap

0 Kudos
6 Replies
DavidPike
MVP Frequent Contributor

what versions of stuff are you running?  Is this the standard GP tool widget? There should be an option to add result to display.  What happens when you run the GP task from arcmap/Pro?

0 Kudos
yaronmic
Emerging Contributor

i use ArcGIS pro 2.6 and And now I have upgraded to 2.7

the ArcGIS Server is 10.8 

the option to add result to display is found in the weight GUI in the Server?

 

this is the code that work ok in the desktop and add the raster to the map



import arcpy
from arcpy import env
from arcpy.sa import *
#arcpy.env.scratchWorkspace = 'c:/temp/scratchoutput.gdb'
number = arcpy.GetParameterAsText(0)

#Pop_Total
statData = "C:\\arcprotest\\b.tif"


out_raster = arcpy.sa.Plus(statData,int(number))

#arcpy.env.scratchWorkspace = 'C:\arcprotest\MyProject15.gdb'
#out_raster.save("test")
#out_raster2.save("test2222")
out_rasterlayer = arcpy.management.MakeRasterLayer(out_raster, "sub")#if i dount use thoes line the layer of the raster dount add in the map in the arcPro
aprx = arcpy.mp.ArcGISProject('CURRENT')#
activeMap = aprx.activeMap#
activeMap.addLayer(out_rasterlayer[0], 'TOP')#

 

0 Kudos
DavidPike
MVP Frequent Contributor

It's been some time since I've done raster stuff in GP Tasks, but the widget should have an option to add to display.

If you don't have that option it's probably because you don't have the output location as a parameter (on publishing this gets repathed to the server).  I'm also guessing you're copying data to the server each time publishing?

I'm sure you can run it locally, but what I meant was can you run the GP Server task as a service from ArcGISPro without error?

I'm not sure how aprx CURRENT references would work on the server either. 

0 Kudos
yaronmic
Emerging Contributor

Thank you very much

how do i put the  output location as a parameter in the server 

like this ? "arcpy.SetParameter(0,tif_path)"

and then i will have the "Option to add the result"

thenk

yaronmic_0-1615566882831.png

 

0 Kudos
DavidPike
MVP Frequent Contributor

Possibly, it's been a while since I've done it.  You shouldn't need to SetParameter(), just GetParameterAsText().

Run the script tool as normal, with any output path you like, then on publishing this path is interpreted and wrangled by the server.

0 Kudos
yaronmic
Emerging Contributor

Thank you very much  i will try it 

0 Kudos