4

I'm having trouble setting a "Feature Set" output parameter from a .pyt .. I'm using ArcGIS 10.1 SP1.

Here’s a short script that can be invoked either from a classic toolbox (thru the main() function; one setup with same parameters here), or as a .pyt .. it works as expected when invoked from a classic toolbox, but does not as a .pyt:

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)
 # Has no effect in either .tbx or .pyt case .. no error, just does nothing.
 parameters[0].value = featureSet
 # Does what's expected for classic .tbx; does nothing
 # for .pyt .. again, no error, just does nothing.
 # You can comment this line out for testing the first set method ..
 arcpy.SetParameter(0, featureSet)
 # This works fine in both .tbx and .pyt
 parameters[1].value = featureSet.JSON
 except Exception as e:
 arcpy.AddError(str(e))
def main():
 tool = Test()
 tool.execute(arcpy.GetParameterInfo(), None)
if __name__ == ‘__main__’:
 main()

Not sure what I'm doing wrong .. Any suggestions?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 28, 2013 at 21:41
2
  • 1
    I've only ever used feature sets for input and thought that, rather than output, was what they were designed for. It will be a while before I can look at this so I'm going to include links to your posting on the ArcGIS Discussion Forum and the Help Page to assist later. Commented May 28, 2013 at 22:15
  • I got a similar answer in post you linked to; using "datatype = 'Feature Class'" instead of "datatype = 'Feature Set'" does fix my problem. If you can offer any insight into what the real difference between a 'Feature Set' vs 'Feature Class' is, I'll gladly accept your answer. Commented May 30, 2013 at 21:56

1 Answer 1

1

I've only ever used Feature Sets for input and thought that, rather than output, was what they were designed for.

My understanding of Feature Sets comes from here .

From what I can tell they are simplified Feature Classes but simplified in what ways I do not know.

answered May 30, 2013 at 23:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.