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?
-
1I'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.PolyGeo– PolyGeo ♦2013年05月28日 22:15:06 +00:00Commented 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.cwa– cwa2013年05月30日 21:56:31 +00:00Commented May 30, 2013 at 21:56
1 Answer 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.