サマリー
RecordSet objects are a lightweight representation of a table. They are a special 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.
説明
注意:
If you're loading a table into a new RecordSet and modifying the RecordSet with a geoprocessing tool that modifies the input such as Calculate Field or a function such as UpdateCursor, the original table will also be modified.
構文
RecordSet ({table})
パラメーター | 説明 | データ タイプ |
table | The table to load into the RecordSet object. The input can be a catalog path to a feature class, a URL to a hosted feature layer, a JSON with the syntax {"url":"<url>", "serviceToken":"<serviceToken>"} to load data from external sources that require an access token, or an Esri (FeatureSet) JSON string. An Esri JSON (.json) is a standard for encoding feature (geometry and attribute) data as a JSON object. For tables, the JSON does not include geometryType, spatialReference, or geometry keys. | 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 |
方法の概要
方法 | 説明 |
load (table_path, {where_clause}) | Imports a table into the RecordSet object. |
save (table_path) | Export to a table. |
方法
load (table_path, {where_clause})
パラメーター | 説明 | データ タイプ |
table_path | The table to load into the RecordSet object. The input can be a catalog path to a feature class, a URL to a hosted feature layer, a JSON with the syntax {"url":"<url>", "serviceToken":"<serviceToken>"} to load data from external sources that require an access token, or an Esri JSON string. | String |
where_clause | An SQL expression used to select a subset of records. For more information on SQL syntax, see SQL reference for query expressions used in ArcGIS. (デフォルト値は次のとおりです None) | String |
The optional arguments are positional only; they cannot be passed by named arguments.
save (table_path)
パラメーター | 説明 | データ タイプ |
table_path | The output table to be created. | String |
コードのサンプル
Import a server toolbox; get the RecordSet 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)
Create a RecordSet 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 empty RecordSet
record_set = arcpy.RecordSet()
# Load data into RecordSet with query
record_set.load(in_dataset, query)
Create a RecordSet 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)