Geoprocessing Service using selected features

46
0
09-29-2022 09:25 AM
RobMcCulley
New Contributor III

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?

0 Kudos
0 Replies