Show Navigation | Hide Navigation
You are here:
Geoprocessing > Automating your work with scripts > Data properties and access when scripting

FeatureSets and RecordSets

Release 9.3
Last modified June 3, 2010
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Data properties and access when scripting"

Related Topics

Note: This topic was updated for 9.3.1.

FeatureSet objects are a lightweight representation of a feature class. They are a special data element that contains not only schema (geometry type, fields, spatial reference) but also the data, including the geometry itself. RecordSets are similiar, but comparable to a table. Server tools communicate using feature sets and record sets, meaning data must be created using or loaded into these objects when using server tools. When used in a script tool, FeatureSets and RecordSets can be used to interactively define features and records.

Learn more about feature sets and record sets

The FeatureSet and RecordSet objects use the same two methods.

The feature set object properties

Load Import a feature class into the FeatureSet object.
Save Export to a geodatabase feature class or shapefile.

The record set object properties

Load Import a feature class into the RecordSet object.
Save Export to a geodatabase table or dBASE file.

Learn more about feature sets and record sets

Creating and using FeatureSet and RecordSet objects

FeatureSet and RecordSet objects can be created in a number of ways depending on need and application. The Load method can be used to add new features or rows to the object, and the Save method can be used to preserve the features or rows to disk. Both FeatureSet and RecordSet objects can also be used directly as input to a geoprocessing tool.

CreateObject method

CreateObject creates an empty FeatureSet or RecordSet.

import arcgisscripting
gp = arcgisscripting.create(9.3)

# Create an empty FeatureSet object
featSet = gp.createobject("FeatureSet")

Learn more about the CreateObject method

GetParameterValue method

If you want to create a FeatureSet or RecordSet with the specific schema of a tool's input, use GetParameterValue to create an empty FeatureSet or RecordSet object with the appropriate schema.

import arcgisscripting
gp = arcgisscripting.create(9.3)

# Add a custom server toolbox

# Get the default input from a tool
inRecSet= gp.GetParameterValue("bufferpoints", 0)

Learn more about the GetParameterValue method

Using GetParameter method

When working with script tools, FeatureSet and RecordSet objects can be acquired from the tool using the geoprocessor's method GetParameter.

import arcgisscripting
gp = arcgisscripting.create(9.3)

# Get the FeatureSet from a script tool
inRecSet = gp.GetParameter(0)

Learn more about the GetParameter method

Result object's GetInput/GetOutput methods

When using a server tool, you must explicitly ask for its output. When the output is a FeatureSet or RecordSet, the Result object's GetOutput method can be used to return the tool's output in a FeatureSet or RecordSet object. As well, the Result object's GetInput method can be used to get an input FeatureSet or RecordSet object.

Learn more about getting results from a geoprocessing tool

import arcgisscripting
import time
gp = arcgisscripting.create(9.3)

# Add a toolbox from a server

# Use GetParameterValue to get a featureset object with the default schema of the 
#   first parameter of the tool 'bufferpoints'
inFeatureSet = gp.GetParameterValue("bufferpoints", 0)

# Load a shapefile into the featureset

# Run a server tool named BufferPoints with featureset created above
result = gp.BufferPoints(inFeatureSet, "5 feet")

# Check the status of the result object every 0.2 seconds until it has a value 
#    of 4 (succeeded) or greater
while result.status < 4:

# Get the output FeatureSet back from the server and save to a local geodatabase
outFeatSet = result.GetOutput(0)

Learn more about the Result object

Example: Loading data to a FeatureSet using cursors and an in_memory feature class

import arcgisscripting
gp = arcgisscripting.create(9.3)

gp.overwriteoutput = 1

# List of coordinates
coordinateL = ["-117.196717216;34.046944853","-117.186226483;34.046498438",               "-117.179530271;34.038016569","-117.187454122;34.039132605",               "-117.177744614;34.056765964","-117.156205131;34.064466609",               "-117.145491191;34.068261129","-117.170825195;34.073618099",               "-117.186784501;34.068149525","-117.158325598;34.03489167"]

# Create an in_memory feature class to initially contain the coordinate pairs
fc = gp.createfeatureclass("in_memory", "tempfc", "POINT")

# Open an insert cursor
cur = gp.InsertCursor(fc)
pointArray = gp.CreateObject("Array")
pnt = gp.CreateObject("Point")

# Iterate through list of coordinates and add to cursor
for coords in coordinateL:
    x,y = coords.split(';') = coordinateL.index(coords) + 1
    pnt.x = x
    pnt.y = y

    feat = cur.NewRow()
    feat.shape = pnt

# Delete the cursor
del cur

# Create a FeatureSet object and load in_memory feature class
featSet = gp.createobject("featureset")

results = gp.bufferpoints(featSet)    

Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.