RecordSet

摘要

RecordSet 对象是表的轻量级表示。 它们是一种既包含方案又包含数据的特殊数据元素。 RecordSet 对象也表示通过服务器发送和接收表的方式。

说明

注:

如果要将某个表加载到新的 RecordSet,并使用可对诸如计算字段等输入或诸如 UpdateCursor 等函数进行修改的地理处理工具来修改 RecordSet,那么也将对原始表进行修改。

语法

 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
(只读)

返回一个字符串形式的几何 Esri JSON 制图表达。

提示:

通过 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 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

可选参数仅为位置参数;无法通过指定参数来传递可选参数。

save (table_path)
参数说明数据类型
table_path

要创建的输出表。

String

代码示例

RecordSet 示例 1

导入服务器工具箱;从服务器工具的指定参数获取 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 示例 2

创建 RecordSet 并加载托管表的子集。

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)
RecordSet 示例 3

根据 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)

相关主题