Hi everyone,
I’ve been trying to solve this one for a couple of days, so any help would be greatly appreciated!
I have created a Script Tool to perform the following tasks:
The Script Tool code is below:
import arcpy
# Get input parameters
inputFeatureSet = arcpy.GetParameterAsText(0)
bufferDistanceMetres = arcpy.GetParameterAsText(1)
try:
# Create buffer
outputBufferLayer = arcpy.Buffer_analysis(
in_features=inputFeatureSet,
out_feature_class='in_memory/Buffer',
buffer_distance_or_field='{0} meters'.format(bufferDistanceMetres),
line_side='FULL',
line_end_type='ROUND',
dissolve_option='ALL',
dissolve_field=None
)
# Select intersecting features
outputFeatureLayer = arcpy.SelectLayerByLocation_management(
in_layer=inputFeatureSet,
overlap_type='INTERSECT',
select_features=outputBufferLayer,
selection_type='ADD_TO_SELECTION'
)
except Exception, e:
arcpy.AddError(e)
else:
# Set output parameters
arcpy.SetParameter(2, outputBufferLayer)
arcpy.SetParameter(3, outputFeatureLayer)
The parameters are configured as follows:
Display Name | Data Type | Direction |
---|---|---|
InputFeatures | Feature Set | Input |
BufferDistanceMetres | Long | Input |
OutputBufferLayer | Feature Layer | Output |
OutputFeatureLayer | Feature Layer | Output |
Ultimately, I need to call the GP Service from the Geoprocessing Widget in Web AppBuilder. The Script Tool works fine in ArcMap, but when I publish it as Geoprocessing Service, it fails in SelectLayerByLocation_management with the following error:
Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation).
The error is because SelectLayerByLocation_management expects a Feature Layer instead of a Feature Set. However, the Script Tool input parameter must be a Feature Set in order for the user to be able to select a layer in the Geoprocessing Widget. If I try to create a Feature Layer from the Feature Set, only the originally selected features are included (instead of all features), so the selection cannot be added to when intersecting with the Buffer. Including the InputFeatures as an additional input parameter with type Feature Layer could work, but I don't believe that's possible because it would also have to be selected by the user.
Besides creating a custom widget, does anyone know of a way to do this?
Thanks,
Wayne