FeatureSets and RecordSets |
|
Release 9.3
Last modified June 3, 2010 |
![]() ![]() ![]() Print all topics in : "Data properties and access when scripting" |
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.
Load | Import a feature class into the FeatureSet object. |
Save | Export to a geodatabase feature class or shapefile. |
Load | Import a feature class into the RecordSet object. |
Save | Export to a geodatabase table or dBASE file. |
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")
import arcgisscripting gp = arcgisscripting.create(9.3) # Add a custom server toolbox # gp.AddToolbox("http://flame7/arcgis/services;BufferByVal") # Get the default input from a tool # inRecSet= gp.GetParameterValue("bufferpoints", 0)
import arcgisscripting gp = arcgisscripting.create(9.3) # Get the FeatureSet from a script tool # inRecSet = gp.GetParameter(0)
import arcgisscripting import time gp = arcgisscripting.create(9.3) # Add a toolbox from a server # gp.AddToolbox("http://flame7/arcgis/services;GP/BufferByVal") # 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 # inFeatureSet.Load("c:/base/roads.shp") # 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: time.sleep(0.2) # Get the output FeatureSet back from the server and save to a local geodatabase # outFeatSet = result.GetOutput(0) outFeatSet.Save("c:/temp/base.gdb/towers_buffer")
import arcgisscripting gp = arcgisscripting.create(9.3) gp.AddToolbox("http://flame7/arcgis/services;BufferByVal") 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(';') pnt.id = coordinateL.index(coords) + 1 pnt.x = x pnt.y = y feat = cur.NewRow() feat.shape = pnt cur.InsertRow(feat) pointArray.add(pnt) # Delete the cursor del cur # Create a FeatureSet object and load in_memory feature class # featSet = gp.createobject("featureset") featSet.load(fc) results = gp.bufferpoints(featSet)