Skip to main content

RecordSet

サマリー

RecordSet objects are a lightweight representation of a table. They are a data element that contains not only schema, but also the data. The RecordSet object is also how tables are sent and received from the server.

ディスカッション

  • Using the RecordSet as input to a tool or function that modifies the input, such as Calculate Field or UpdateCursor, will modify the original table.

  • Loading a new table into a RecordSet will not overwrite the original table. The load method will only change the reference to the table, not the original table itself.

構文

RecordSet({table_path}, {where_clause})

名前 説明 データ タイプ

table_path

(オプション)

The table to load into the RecordSet object.

String

where_clause

(オプション)

An SQL expression used to select a subset of records.

For more information about SQL syntax, see SQL reference for query expressions used in ArcGIS.

The default value is None.

String

プロパティ

名前 説明 データ タイプ

JSON

(読み取り専用)

Returns an Esri JSON representation of the geometry as a string.

ヒント:

The returned string can be converted to a dictionary using the json module's loads function.

String

GeoJSON

(読み取り専用)

Returns a GeoJSON representation of the geometry as a string.

ヒント:

The returned string can be converted to a dictionary using the json module's loads function.

String

方法

load({table_path}, {where_clause})

Loads a table into the RecordSet object.

名前 説明 データ タイプ

table_path

(オプション)

The table to load into the RecordSet object.

String

where_clause

(オプション)

An SQL expression used to select a subset of records.

For more information about SQL syntax, see SQL reference for query expressions used in ArcGIS.

The default value is None.

String

save(table_path)

Exports to a table.

名前 説明 データ タイプ

table_path

The output table that will be created.

String

コードのサンプル

RecordSet example 1

Import a server toolbox; get the RecordSet object from the server tool's specified parameter.

import arcpy

# Add a custom server toolbox
arcpy.ImportToolbox("http://myserver/arcgis/services;Geocode")

# Get recordset from server tool's first parameter to use as schema
in_recordset = arcpy.GetParameterValue("GeocodeAddress", 0)
RecordSet example 2

Create a RecordSet object and load a subset of a hosted table.

import arcpy

# Set data
in_dataset = "https://maps.my.org/arcgis/rest/services/Tables/MapServer/0"
query = "Country_Code: 'IT'"

# Create RecordSet with query
record_set = arcpy.RecordSet(in_dataset, query)
RecordSet example 3

Create a RecordSet object from an Esri JSON string.

import arcpy

# Set data
data_json = '''{
 "objectIdFieldName": "objectid",
 "globalIdFieldName": "globalid",
 "fields": [
  {
   "name": "objectid",
   "alias": "OBJECTID",
   "type": "esriFieldTypeOID"
  },
  {
   "name": "requestid",
   "alias": "Service Request ID",
   "type": "esriFieldTypeString",
   "length": 25
  },
  {
   "name": "requesttype",
   "alias": "Problem",
   "type": "esriFieldTypeString",
   "length": 100
  },
  {
   "name": "comments",
   "alias": "Comments",
   "type": "esriFieldTypeString",
   "length": 255
  }
 ],
 "features": [
  {
   "attributes": {
    "objectid": 246362,
    "requestid": "1",
    "requesttype": "Sidewalk Damage",
    "comments": "Pothole"
   }
  },
  {
   "attributes": {
    "objectid": 246382,
    "requestid": "2",
    "requesttype": "Pothole",
    "comments": "Jhh"
   }
  }
 ]
}'''

# Create FeatureSet from Esri JSON
feature_set = arcpy.RecordSet(data_json)