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))
{"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}}]}
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 = "FS Output1", name = "fsOutput1", datatype = "GPFeatureRecordSetLayer", parameterType = "Derived", direction = "Input") params.append(param1) param2 = arcpy.Parameter( displayName = "FS Output2", name = "fsOutput2", datatype = "GPFeatureRecordSetLayer", parameterType = "Derived", direction = "Output") params.append(param2) param3 = arcpy.Parameter( displayName = "JSON Output", name = "strOutput", datatype = "String", parameterType = "Derived", direction = "Output") params.append(param3) 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 parameters[2].value = featureSet parameters[3].value = featureSet.JSON except Exception as e: arcpy.AddError(str(e))
Hi
I had the same problem as yours
To Resolve, I used the following parameter: GPFeatureRecordSetLayer
maybe it can solve your problem:
param0 = arcpy.Parameter(
displayName = "FS Output", name = "fsOutput",
datatype = "GPFeatureRecordSetLayer", parameterType = "Derived", direction = "Intput")
Jean
Hi
I had the same problem as yours
To Resolve, I used the following parameter: GPFeatureRecordSetLayer
maybe it can solve your problem:
param0 = arcpy.Parameter(
displayName = "FS Output", name = "fsOutput",
datatype = "GPFeatureRecordSetLayer", parameterType = "Derived", direction = "Intput")
Jean
Yes, I use 10.1 SP1
the datatype = "Feature Set" in param0 is the bad parameter. For the Feature Set use GPFeatureRecordSetLayer parameter.
Unlike my first response, the direction parameter can be output «direction="Output"»
Jean
feature_class = "....the FC you've created..." feature_set = arcpy.FeatureSet() feature_set.load(feature_class)
Note:
Server tools communicate using feature sets and record sets, meaning data must be created using or loaded into these objects when using server tools.
What exactly is it you're trying to do?
I dont normally see people using FeatureSet as output as FeatureClass usually is sufficient.
If you're ultimately trying to make a GP Service, I'd just stick with FC for output, and FS for input.
I dont know if this will help, but if you want to stick with FS as output, maybe try doing a load.
For examplefeature_class = "....the FC you've created..." feature_set = arcpy.FeatureSet() feature_set.load(feature_class)