[GIS] Defining Feature Set parameter for ArcGIS Python Toolbox tool

arcpypython-toolbox

I'm trying to create an ArcGIS Python Toolbox tool which uses a polygon for input.

I want the user to be able to create the polygon when the tool is run.

I know how to do this using both a ModelBuilder model A quick tour of using Feature Set and Record Set and for a Python Script tool in a normal toolbox. This is done using a Feature Set variable by setting the schema to a polygon feature class.

I know from here Defining parameter data types in a Python toolbox that the datatype for Feature Set in a python toolbox is GPFeatureRecordSetLayer.

If I define the parameter as below it is not possible to create a polygon at run time. I’m almost 100% sure that this is because I have not set a schema. But does anybody know how to set the schema or know if there is some other way to interactively create a polygon and use as input for a Python Toolbox tool?

InteractiveParameter = arcpy.Parameter(
displayName="Interactive polygon",
name="toolname",
datatype="GPFeatureRecordSetLayer",
parameterType="Required",
direction="Input",
enabled = True)

Best Answer

The code example below is from the ArcGIS 10.1 Help page called Defining parameters in a Python toolbox which you have mentioned in your Question.

I think the step you have overlooked is the last one where you need to specify a polygon feature class or layer file (*.lyr). The example code references a layer file called Fire_Station.lyr.

def getParameterInfo(self):
    param0 = arcpy.Parameter(
        displayName="Input Feature Set",
        name="in_feature_set",
        datatype="GPFeatureRecordSetLayer",
        parameterType="Required",
        direction="Input")

    # Use __file__ attribute to find the .lyr file (assuming the
    #  .pyt and .lyr files exist in the same folder)
    param0.value = os.path.join(os.path.dirname(__file__),
                                "Fire_Station.lyr")
Related Question