Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

python toolbox Feature Set output parameter

$
0
0
I'm having trouble setting an output parameter of type "Feature Set" in a python toolbox. Here's what I have currently:

Code:

import arcpy

class Toolbox(object):
    def __init__(self):
       
        self.label = "FeatureSet Output Test"
        self.alias = ""
        self.tools = [Test]

class Test(object):
   
    def __init__(self):
       
        self.label = "Test1"
        self.description = "Output a few points in a feature set"
        self.canRunInBackground = False

    def getParameterInfo(self):
       
        params = []
       
        param0 = arcpy.Parameter(
            displayName = "FS Output", name = "fsOutput",
            datatype = "Feature Set", parameterType = "Derived", direction = "Output")
        params.append(param0)
       
        param1 = arcpy.Parameter(
            displayName = "JSON Output", name = "strOutput",
            datatype = "String", parameterType = "Derived", direction = "Output")
        params.append(param1)
       
        return params

    def execute(self, parameters, messages):
       
        gdbPath = 'in_memory'
        featureClassName = 'points'
        featureClass = '{}/{}'.format(gdbPath, featureClassName)
       
        try:
            arcpy.AddMessage('Creating a point feature class with 1 text attribute')
           
            if arcpy.Exists(featureClass):
                arcpy.Delete_management(featureClass)
           
            arcpy.CreateFeatureclass_management(
                out_path=gdbPath, out_name=featureClassName, geometry_type='POINT',
                spatial_reference=arcpy.SpatialReference(4326))
           
            arcpy.AddField_management(
                in_table=featureClass,
                field_name='Attribute1', field_type='TEXT')
           
            arcpy.AddMessage('Inserting a couple points')
            with arcpy.da.InsertCursor(featureClass, ('SHAPE@XY', 'Attribute1')) as cur:
                cur.insertRow(((1, 1), 'point at 1, 1'))
                cur.insertRow(((2, 2), 'point at 2, 2'))
           
            arcpy.AddMessage('Setting the output parameters')
            featureSet = arcpy.FeatureSet(featureClass)
            parameters[0].value = featureSet
            parameters[1].value = featureSet.JSON               
       
        except Exception as e:
            arcpy.AddError(str(e))

The first output parameter displays as "empty"; if I print paramers[0].value it will output "None" ..

The second TEXT parameter seems to work fine; I get the following output:
Quote:

{"displayFieldName":"","fieldAliases":{"OID":"OID","Attribute1":"Attribute1"},"geometryType":"esriGeometryPoint","spatialReference":{"wkid":4326,"latestWkid":4326},"fields":[{"name":"OID","type":"esriFieldTypeOID","alias":"OID"},{"name":"Attribute1","type":"esriFieldTypeString","alias":"Attribute1"}],"features":[{"attributes":{"OID":1,"Attribute1":"point at 1, 1"},"geometry":{"x":1.0000000000000568,"y":1.0000000000000568}},{"attributes":{"OID":2,"Attribute1":"point at 2, 2"},"geometry":{"x":2.0000000000000568,"y":2.0000000000000568}}]}
Anyone know why this doesn't work?

Thanks in advance :)

Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images