Select to view content in your preferred language

Geoprocessing Service using selected features

1325
5
09-29-2022 09:25 AM
RobMcCulley
Occasional Contributor

I'm trying to create a geoprocessing service that consumes the selected features in a webmap.  I'm running it through the geoprocessing widget in a web app builder map.  My enterprise server is running Portal 11.0 with a Federated server, also at 11.0.  I'm publishing from ArcGIS Pro 3.0.2.

The geoprocessing service is a python toolbox function with two parameters - an input layer, and an output spreadsheet  The parameters looks like:

    def getParameterInfo(self):
        """Define parameter definitions"""
        p0 = arcpy.Parameter(displayName="Parcel Layer", name="parcellayer", direction="Input", datatype="GPFeatureLayer", parameterType="Required")
        p1 = arcpy.Parameter(displayName="Owner List", name="ownerlist", direction="Output", datatype="DEFile", parameterType="Derived")
        return [p0, p1]

The execute function looks like:

    def execute(self, parameters, messages):
        """The source code of the tool."""
        fl = parameters[0].valueAsText
        fc = arcpy.management.CopyFeatures(fl, os.path.join(arcpy.env.scratchGDB, "SelectedParcels"))
        with arcpy.da.SearchCursor(fc, ("roll",)) as sc:
            rolls = [row[0] for row in sc]
        powners, aowners = get_owner_info(rolls)
        xlname = "OwnerList_%s.xlsx" % datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
        xlpth = os.path.join(arcpy.env.scratchFolder, xlname)
        make_excel(xlpth, powners, aowners)
        parameters[1].value = xlpth
        return

 

The tool works perfectly when run in ArcGIS Pro, and publishes to the portal without errors.  When published, the first parameter is set to "User Defined", so that I get a dropdown list to select the layer from the webmap.  When I run the geoprocessing service published directly from the python toolbox, the selection in the webmap isn't utilized, and the output spreadsheet is comprised of all of the features from input layer.

I've tried checking the box "Do not send URL but FeatureCollections as input" in the geoprocessing widget, but it makes no difference, the service uses all features.

I've tried running it both with and without the CopyFeatures line in the execute function, but it makes no difference, the service uses all features.

Is there any way to make my python toolbox, published as a geoprocessing service, utilize the selection in the webmap?

5 Replies
allenjoones
New Contributor

Did you ever get an answer to this?  I have built a super simple proof of concept geoprocessing tool that should take a selection, buffer it and return the result to the map.  I cannot get it to take a feature set of selected features from the web application.  It either returns an empty output or buffers the whole feature class.  

Zartico-GIS
Occasional Contributor

@allenjoones @RobMcCulley 

Did either of you find a resolution to this?

I want to use selected features of a feature layer as input to a geoprocessing service.

Could it have been an Experience Builder vs Web AppBuilder thing? Bug? Not supported? 

Any info would be fantastic. Thanks!

0 Kudos
Juan_Toro-Killion
Occasional Contributor

Sooooo did anyone get any solutions for this? Also experiencing similar problem.

0 Kudos
RobMcCulley
Occasional Contributor

I haven't found a solution for this.

In the end, I converted my python toolbox to a model builder tool, and it works as expected.

0 Kudos
PierreloupDucroix
Frequent Contributor

Hello,

when you say it works after you converted to a model builder, did you share your model builder as a geoprocessing service, or just use it as a toolbox ?

0 Kudos