FeatureSet

Краткая информация

Объекты FeatureSet являются упрощенным представлением класса пространственных объектов. Они представляют собой элемент данных, который содержит не только схему, но и данные. Объект FeatureSet – это также метод, с помощью которого данные объекта передаются и получаются с сервера.

Обсуждение

При использовании объекта Feature Set необходимо принимать во внимание следующее:

  • Использование объекта FeatureSet в качестве входных данных для инструмента или функции, которые изменяют входные данные, например, Вычислить поле или UpdateCursor, изменит исходный класс объектов.
  • Загрузка нового класса объектов в объект FeatureSet не приведет к перезаписи исходного класса объектов. Метод load изменит только ссылку на класс объектов, но не сам исходный класс объектов.

Синтаксис

 FeatureSet ({table_path}, {where_clause}, {time_filter}, {renderer}, {is_renderer}, {geojson_geometry_type})
ПараметрОписаниеТип данных
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, an Esri (featureSet) JSON string, or a GeoJSON string.

Esri JSON and GeoJSON are standards for encoding feature (geometry and attribute) data as a .json file.

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
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.

Format a time instant as a string, for example, "1199145600000" (1 Jan 2008 00:00:00 GMT). Format a time extent as 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; set to False if the value is a definition.

(Значение по умолчанию — None)

Boolean
geojson_geometry_type

The geometry type of the GeoJSON file that will be loaded. A single GeoJSON file may contain multiple types of geometry records. Only the records of the specified geometry type will be loaded. By default, this is the geometry type of the first record.

This option is only supported if the table_path value is GeoJSON.

  • POINTTreat GeoJSON Point geometry type as point features.
  • MULTIPOINTTreat GeoJSON MultiPoint geometry type as multipoint features.
  • POLYLINETreat GeoJSON LineString and MultiLineString geometry types as polyline features.
  • POLYGONTreat GeoJSON Polygon and MultiPolygon geometry types as polygon features.

Only the listed GeoJSON geometry types are supported.

(Значение по умолчанию — None)

String

Свойства

СвойствоОписаниеТип данных
JSON
(только чтение)

Возвращает представление геометрии Esri JSON в виде строки.

Подсказка:

Возвращаемая строка может быть конвертирована в словарь с помощью функции loads модуля json.

String
GeoJSON
(только чтение)

Возвращает представление геометрии GeoJSON в виде строки.

Подсказка:

Возвращаемая строка может быть конвертирована в словарь с помощью функции loads модуля json.

String

Обзор метода

МетодОписание
load ({table_path}, {where_clause}, {time_filter}, {renderer}, {is_renderer}, {geojson_geometry_type})

Загружает таблицу в объект FeatureSet.

save (table_path)

Экспорт в таблицу.

Методы

load ({table_path}, {where_clause}, {time_filter}, {renderer}, {is_renderer}, {geojson_geometry_type})
ПараметрОписаниеТип данных
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, an Esri (featureSet) JSON string, or a GeoJSON string.

Esri JSON and GeoJSON are standards for encoding feature (geometry and attribute) data as a .json file.

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
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.

Format a time instant as a string, for example, "1199145600000" (1 Jan 2008 00:00:00 GMT). Format a time extent as 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; set to False if the value is a definition.

(Значение по умолчанию — None)

Boolean
geojson_geometry_type

The geometry type of the GeoJSON file that will be loaded. A single GeoJSON file may contain multiple types of geometry records. Only the records of the specified geometry type will be loaded. By default, this is the geometry type of the first record.

This option is only supported if the table_path value is GeoJSON.

  • POINTTreat GeoJSON Point geometry type as point features.
  • MULTIPOINTTreat GeoJSON MultiPoint geometry type as multipoint features.
  • POLYLINETreat GeoJSON LineString and MultiLineString geometry types as polyline features.
  • POLYGONTreat GeoJSON Polygon and MultiPolygon geometry types as polygon features.

Only the listed GeoJSON geometry types are supported.

(Значение по умолчанию — None)

String
save (table_path)
ПараметрОписаниеТип данных
table_path

Создаваемая выходная таблица.

String

Пример кода

FeatureSet, пример 1

Загрузить данные в класс пространственных объектов и вставить в 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_class)

results = arcpy.BufferPoints_servertools(feature_set)
FeatureSet, пример 2

Загрузите подмножество данных из 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 FeatureSet with query and renderer
feature_set = arcpy.FeatureSet(in_data, query, renderer=renderer, is_renderer=True)
FeatureSet, пример 3

Создаёт объект FeatureSet из строки JSON Esri.

import arcpy

# Set data
esri_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": ""
   }
  }
 ]
}'''

# Create FeatureSet from Esri JSON
feature_set = arcpy.FeatureSet(data_json)
FeatureSet, пример 4

Создает объект FeatureSet на основе строки GeoJSON.

import arcpy

geo_json = '''{
    "crs": {
        "properties": {
            "name": "EPSG: 3857"
        },
        "type": "name"
    },
    "features": [
        {
            "geometry": {
                "coordinates": [
                    -9809161.170230601,
                    5123045.526620984
                ],
                "type": "Point"
            },
            "id": 246362,
            "properties": {
                "comments": "Pothole",
                "objectid": 246362,
                "requestid": "1",
                "requesttype": "Sidewalk Damage"
            },
            "type": "Feature"
        },
        {
            "geometry": {
                "coordinates": [
                    -9074857.923443586,
                    4982391.260421775
                ],
                "type": "Point"
            },
            "id": 246382,
            "properties": {
                "comments": "",
                "objectid": 246382,
                "requestid": "2",
                "requesttype": "Pothole"
            },
            "type": "Feature"
        }
    ],
    "type": "FeatureCollection"
}'''

# Create FeatureSet from Geo JSON
feature_set = arcpy.FeatureSet(geo_json, geojson_geometry_type="POINT")
FeatureSet, пример 5

Создает объект FeatureSet на основе размещенного векторного слоя с поддержкой времени, используя параметр time_filter.

import arcpy

url = {"url": "https://services.arcgis.com/O9GvsOYzrcFwdwqx/arcgis/rest/services/MyTimeEnabledLayer/FeatureServer/0"}
filter = "Country = 'United States'"
in_start, in_end = 1672473600000, 1718434800000
time_filter = f"{in_start}, {in_end}"

# Create FeatureSet using a time filter
feature_set = arcpy.FeatureSet(table_path=url, time_filter=time_filter)

Связанные разделы