摘要
FeatureSet 对象是要素类的轻量级表示。 它们是一种既包含方案又包含数据的特殊数据元素。 而且,FeatureSet 对象也表示通过服务器发送和接收要素数据的方式。
说明
注:
如果要将某个要素类加载到新的 FeatureSet,并使用可对诸如计算字段等输入或诸如 UpdateCursor 等函数进行修改的地理处理工具来修改 FeatureSet,那么也将对原始要素类进行修改。
语法
FeatureSet ({table})
参数 | 说明 | 数据类型 |
table | The features to load into the FeatureSet 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. | String |
属性
属性 | 说明 | 数据类型 |
JSON (只读) | 返回一个字符串形式的几何 Esri JSON 制图表达。 提示:通过 json 模块的 loads 函数,返回的字符串可转换至字典。 | String |
方法概述
方法 | 说明 |
load (table_path, {where_clause}, {time_filter}, {renderer}, {is_renderer}) | 将表导入 FeatureSet 对象。 |
save (table_path) | 导出到表。 |
方法
load (table_path, {where_clause}, {time_filter}, {renderer}, {is_renderer})
参数 | 说明 | 数据类型 |
table_path | The features to load into the FeatureSet 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 |
time_filter | The time instant or the time extent to query. The time filter can only be applied to hosted feature layers, and the layer must be time-enabled. A time instant should be formatted as a string, for example, "1199145600000" ((1 Jan 2008 00:00:00 GMT). A time extent should be a comma-delimited string, for example: "1199145600000, 1230768000000" (1 Jan 2008 00:00:00 GMT to 1 Jan 2009 00:00:00 GMT). A null value specified for the start time or the end time will represent infinity for the start or the end time, respectively, for example: "null, 1230768000000". (默认值为 None) | String |
renderer | The output FeatureSet symbology can be set using a string, or dictionary representation of either a JSON renderer or a JSON definition object. Learn more about JSON renderers and JSON definition objects. (默认值为 None) | String |
is_renderer | Specifies the type of the value used with the renderer argument. Set to True if the value is a renderer object, and False if the value is a definition. (默认值为 None) | Boolean |
可选参数仅为位置参数;无法通过指定参数来传递可选参数。 例如,如果意图为仅指定符号系统,则必须使用 None 跳过可选参数 where_clause 和 time_filter。
save (table_path)
参数 | 说明 | 数据类型 |
table_path | 要创建的输出表。 | String |
代码示例
将数据加载到要素类并插入 FeatureSet 中。
import arcpy
arcpy.env.overwriteOutput = True
arcpy.ImportToolbox("http://flame7/arcgis/services;BufferByVal",
"servertools")
# List of coordinates
coordinates = [[-117.196717216, 34.046944853],
[-117.186226483, 34.046498438],
[-117.179530271, 34.038016569],
[-117.187454122, 34.039132605],
[-117.177744614, 34.056765964],
[-117.156205131, 34.064466609],
[-117.145491191, 34.068261129],
[-117.170825195, 34.073618099],
[-117.186784501, 34.068149525],
[-117.158325598, 34.03489167]]
# Create an in_memory feature class to initially contain the coordinate pairs
feature_class = arcpy.CreateFeatureclass_management(
"in_memory", "tempfc", "POINT")[0]
# Open an insert cursor
with arcpy.da.InsertCursor(feature_class, ["SHAPE@XY"]) as cursor:
# Iterate through list of coordinates and add to cursor
for (x, y) in coordinates:
cursor.insertRow([(x, y)])
# Create a FeatureSet object and load in_memory feature class
feature_set = arcpy.FeatureSet()
feature_set.load(feature_class)
results = arcpy.BufferPoints_servertools(feature_set)
将 ArcGIS Living Atlas of the World 中的数据子集加载到 FeatureSet 中并设置符号系统。
import arcpy
# Set data
in_data = "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_States_Generalized/FeatureServer/0"
query = "STATE_NAME = 'California'"
renderer = '''{
"renderer": {
"type": "simple",
"symbol": {
"type": "esriSFS",
"style": "esriSFSSolid",
"color": [
255,
0,
0,
255
],
"outline": {
"type": "esriSLS",
"style": "esriSLSSolid",
"color": [
110,
110,
110,
255
],
"width": 2
}
},
"label": "",
"description": "",
"rotationType": "geographic",
"rotationExpression": ""
}
}'''
# Create empty FeatureSet
feature_set = arcpy.FeatureSet()
# Load data into FeatureSet with query
feature_set.load(in_data, query, None, renderer, True)
根据 Esri JSON 字符串创建 FeatureSet。
import arcpy
# Set data
data_json = '''{
"objectIdFieldName": "objectid",
"globalIdFieldName": "globalid",
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 102100,
"latestWkid": 3857
},
"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": [
{
"geometry": {
"x": -9809161.170230601,
"y": 5123045.5266209831
},
"attributes": {
"objectid": 246362,
"requestid": "1",
"requesttype": "Sidewalk Damage",
"comments": "Pothole"
}
},
{
"geometry": {
"x": -9074857.9234435894,
"y": 4982391.2604217697
},
"attributes": {
"objectid": 246382,
"requestid": "2",
"requesttype": "Pothole",
"comments": "Jhh"
}
}
]
}'''
# Create FeatureSet from Esri JSON
feature_set = arcpy.FeatureSet(data_json)