Skip to main content

RecordSet

汇总

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

讨论

  • RecordSet 作为输入应用至修改输入的工具或函数(例如 计算字段UpdateCursor )将修改原始要素类。

  • 将新表加载至 RecordSet 将不会覆盖原始表。 load 方法只会更改对表的引用,而不会更改原始表本身。

语法

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.

(默认值为 None)

String

属性

名称 说明 数据类型

JSON

(只读)

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

提示:

通过 json 模块的 loads 函数,返回的字符串可转换至字典。

String

GeoJSON

(只读)

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

提示:

通过 json 模块的 loads 函数,返回的字符串可转换至字典。

String

方法

load({table_path}, {where_clause})

将表加载至 RecordSet 对象。

名称 说明 数据类型

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.

(默认值为 None)

String

save(table_path)

导出到表。

名称 说明 数据类型

table_path

The output table that will be created.

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 RecordSet with query
record_set = arcpy.RecordSet(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)