摘要
RecordSet 对象是表的轻量级表示。 它们是一种既包含方案又包含数据的数据元素。 RecordSet 对象也表示通过服务器发送和接收表的方式。
说明
- 将 RecordSet 作为输入应用至修改输入的工具或函数(例如计算字段或 UpdateCursor)将修改原始要素类。
- 将新表加载至 RecordSet 将不会覆盖原始表。 load 方法只会更改对表的引用,而不会更改原始表本身。
语法
RecordSet ({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 (featureSet) JSON string. An Esri JSON is a standard for encoding feature (geometry and attribute) data as a JSON (.json) file. For tables, the JSON does not include geometryType, spatialReference, or geometry keys. | 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 |
属性
属性 | 说明 | 数据类型 |
JSON (只读) | 返回一个字符串形式的几何 Esri JSON 制图表达。 提示:通过 json 模块的 loads 函数,返回的字符串可转换至字典。 | String |
GeoJSON (只读) | 返回一个字符串形式的几何 GeoJSON 制图表达。 提示:通过 json 模块的 loads 函数,返回的字符串可转换至字典。 | String |
方法概述
方法 | 说明 |
load ({table_path}, {where_clause}) | 将表加载至 RecordSet 对象。 |
save (table_path) | 导出到表。 |
方法
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 (featureSet) JSON string. An Esri JSON is a standard for encoding feature (geometry and attribute) data as a JSON (.json) file. For tables, the JSON does not include geometryType, spatialReference, or geometry keys. | 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 |
save (table_path)
参数 | 说明 | 数据类型 |
table_path | 要创建的输出表。 | String |
代码示例
导入服务器工具箱;从服务器工具的指定参数获取 RecordSet 对象。
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 对象并加载托管表的子集。
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)
根据 Esri JSON 字符串创建 RecordSet 对象。
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)