arcgis.features module

The arcgis.features module contains types and functions for working with features and feature layers in the GIS.

Entities located in space with a geometrical representation (such as points, lines or polygons) and a set of properties can be represented as features. The arcgis.features module is used for working with feature data, feature layers and collections of feature layers in the GIS. It also contains the spatial analysis functions which operate against feature data.

In the GIS, entities located in space with a set of properties can be represented as features. Features are stored as feature classes, which represent a set of features located using a single spatial type (point, line, polygon) and a common set of properties. This is the geographic extension of the classic tabular or relational representation for entities - a set of entities is modelled as rows in a table. Tables represent entity classes with uniform properties. In addition to working with “entities with location” as features, the system can also work with non-spatial entities as rows in tables. The system can also model relationships between entities using properties which act as primary and foreign keys. A collection of feature classes and tables, with the associated relationships among the entities, is a feature layer collection. FeatureLayerCollections are one of the dataset types contained in a Datastore. Finally, features are not simply entities in a dataset. Features have a visual representation and user experience - on a map, in a 3D scene, as entities with a property sheet or popups.

Feature

class arcgis.features.Feature(geometry=None, attributes=None)

Entities located in space with a set of properties can be represented as features.

as_dict

returns the feature as a dictionary

as_row

converts a feature to a list for insertion into an insert cursor Output:

[row items], [field names] returns a list of fields and the row object
attributes

returns the feature attributes

fields

returns a list of feature fields

classmethod from_dict(feature)

returns a feature from a dict

classmethod from_json(json_str)

returns a feature from a JSON string

geometry

returns the feature geometry

geometry_type

returns the feature’s geometry type

get_value(field_name)

returns a value for a given field name

set_value(field_name, value)

sets an attribute value for a given field name

FeatureLayer

class arcgis.features.FeatureLayer(url, gis=None, container=None)

The feature layer is the primary concept for working with features in a GIS.

Users create, import, export, analyze, edit, and visualize features, i.e. “entities in space” as feature layers.

Feature layers can be added to and visualized using maps. They act as inputs to and outputs from feature analysis tools.

Feature layers are created by publishing feature data to a GIS, and are exposed as a broader resource (Item) in the GIS. Feature layer objects can be obtained through the layers attribute on feature layer Items in the GIS.

calculate(where, calc_expression, sql_format='standard')

The calculate operation is performed on a feature layer resource. It updates the values of one or more fields in an existing feature service layer based on SQL expressions or scalar values. The calculate operation can only be used if the supportsCalculate property of the layer is true. Neither the Shape field nor system fields can be updated using calculate. System fields include ObjectId and GlobalId. See Calculate a field for more information on supported expressions

Inputs:
where - A where clause can be used to limit the updated records.
Any legal SQL where clause operating on the fields in the layer is allowed.
calcExpression - The array of field/value info objects that

contain the field or fields to update and their scalar values or SQL expression. Allowed types are dictionary and list. List must be a list of dictionary objects. Calculation Format is as follows:

{“field” : “<field name>”, “value” : “<value>”}
sqlFormat - The SQL format for the calcExpression. It can be
either standard SQL92 (standard) or native SQL (native). The default is standard. Values: standard, native
Output:
JSON as string

Usage: >>>print(fl.calculate(where=”OBJECTID < 2”,

calcExpression={“field”: “ZONE”,
“value” : “R1”}))

{‘updatedFeatureCount’: 1, ‘success’: True}

container

The feature layer collection to which this layer belongs.

edit_features(adds=None, updates=None, deletes=None, gdb_version=None, use_global_ids=False, rollback_on_failure=True)

This operation adds, updates, and deletes features to the associated feature layer or table in a single call. Inputs:

adds - The array of features to be added. updates - The array of features to be updateded. deletes - string of OIDs to remove from service gdbVersion - Geodatabase version to apply the edits. useGlobalIds - instead of referencing the default Object ID

field, the service will look at a GUID field to track changes. This means the GUIDs will be passed instead of OIDs for delete, update or add features.
rollbackOnFailure - Optional parameter to specify if the
edits should be applied only if all submitted edits succeed. If false, the server will apply the edits that succeed even if some of the submitted edits fail. If true, the server will apply the edits only if all edits succeed. The default value is true.
Output:
dictionary of messages
classmethod fromitem(item, layer_id=0)

Creates a feature layer from a GIS Item. The type of item should be a ‘Feature Service’ that represents a FeatureLayerCollection. The layer_id is the id of the layer in feature layer collection (feature service).

get_html_popup(oid)

The htmlPopup resource provides details about the HTML pop-up authored by the user using ArcGIS for Desktop. Input:

oid - object id of the feature where the HTML pop-up

Output:

manager

Helper object to manage the feature layer, update it’s definition, etc

properties

The properties of this object

query(where='1=1', out_fields='*', time_filter=None, geometry_filter=None, return_geometry=True, return_count_only=False, return_ids_only=False, return_distinct_values=False, return_extent_only=False, group_by_fields_for_statistics=None, statistic_filter=None, result_offset=None, result_record_count=None, object_ids=None, distance=None, units=None, max_allowable_offset=None, out_sr=None, geometry_precision=None, gdb_version=None, order_by_fields=None, out_statistics=None, return_z=False, return_m=False, multipatch_option=None, quanitization_parameters=None, return_centroid=False, **kwargs)

queries a feature service based on a sql statement Inputs:

where - the selection sql statement out_fields - the attribute fields to return objectIds - The object IDs of this layer or table to be

queried.
distance - The buffer distance for the input geometries.
The distance unit is specified by units. For example, if the distance is 100, the query geometry is a point, units is set to meters, and all points within 100 meters of the point are returned.
units - The unit for calculating the buffer distance. If
unit is not specified, the unit is derived from the geometry spatial reference. If the geometry spatial reference is not specified, the unit is derived from the feature service data spatial reference. This parameter only applies if supportsQueryWithDistance is true. Values: esriSRUnit_Meter | esriSRUnit_StatuteMile | esriSRUnit_Foot | esriSRUnit_Kilometer | esriSRUnit_NauticalMile | esriSRUnit_USNauticalMile
timeFilter - a TimeFilter object where either the start time
or start and end time are defined to limit the search results for a given time. The values in the timeFilter should be as UTC timestampes in milliseconds. No checking occurs to see if they are in the right format.
geometryFilter - a GeometryFilter object to parse down a given
query by another spatial dataset.
maxAllowableOffset - This option can be used to specify the
maxAllowableOffset to be used for generalizing geometries returned by the query operation. The maxAllowableOffset is in the units of outSR. If outSR is not specified, maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.

outSR - The spatial reference of the returned geometry. geometryPrecision - This option can be used to specify the

number of decimal places in the response geometries returned by the Query operation.

gdbVersion - Geodatabase version to query returnDistinctValues - If true, it returns distinct values

based on the fields specified in outFields. This parameter applies only if the supportsAdvancedQueries property of the layer is true.
returnIdsOnly - If true, the response only includes an
array of object IDs. Otherwise, the response is a feature set. The default is false.
returnCountOnly - If true, the response only includes the
count (number of features/records) that would be returned by a query. Otherwise, the response is a feature set. The default is false. This option supersedes the returnIdsOnly parameter. If returnCountOnly = true, the response will return both the count and the extent.
returnExtentOnly - If true, the response only includes the
extent of the features that would be returned by the query. If returnCountOnly=true, the response will return both the count and the extent. The default is false. This parameter applies only if the supportsReturningQueryExtent property of the layer is true.
orderByFields - One or more field names on which the
features/records need to be ordered. Use ASC or DESC for ascending or descending, respectively, following every field to control the ordering.
groupByFieldsForStatistics - One or more field names on
which the values need to be grouped for calculating the statistics.
outStatistics - The definitions for one or more field-based
statistics to be calculated.
returnZ - If true, Z values are included in the results if
the features have Z values. Otherwise, Z values are not returned. The default is false.
returnM - If true, M values are included in the results if
the features have M values. Otherwise, M values are not returned. The default is false.
multipatchOption - This option dictates how the geometry of
a multipatch feature will be returned.
resultOffset - This option can be used for fetching query
results by skipping the specified number of records and starting from the next record (that is, resultOffset + 1th).
resultRecordCount - This option can be used for fetching
query results up to the resultRecordCount specified. When resultOffset is specified but this parameter is not, the map service defaults it to maxRecordCount. The maximum value for this parameter is the value of the layer’s maxRecordCount property.
quanitizationParameters - Used to project the geometry onto
a virtual grid, likely representing pixels on the screen.
returnCentroid - Used to return the geometry centroid
associated with each feature returned. If true, the result includes the geometry centroid. The default is false.
kwargs - optional parameters that can be passed to the Query
function. This will allow users to pass additional parameters not explicitly implemented on the function. A complete list of functions available is documented on the Query REST API.
Output:
A FeatureSet containing the features matching the query unless another return type is specified, such as return

The Query operation is performed on a feature service layer resource. The result of this operation are feature sets grouped by source layer/table object IDs. Each feature set contains Feature objects including the values for the fields requested by the user. For related layers, if you request geometry information, the geometry of each feature is also returned in the feature set. For related tables, the feature set does not include geometries. Inputs:

objectIds - the object IDs of the table/layer to be queried relationshipId - The ID of the relationship to be queried. outFields - the list of fields from the related table/layer

to be included in the returned feature set. This list is a comma delimited list of field names. If you specify the shape field in the list of return fields, it is ignored. To request geometry, set returnGeometry to true. You can also specify the wildcard “*” as the value of this parameter. In this case, the result s will include all the field values.
definitionExpression - The definition expression to be
applied to the related table/layer. From the list of objectIds, only those records that conform to this expression are queried for related records.
returnGeometry - If true, the feature set includes the
geometry associated with each feature. The default is true.
maxAllowableOffset - This option can be used to specify the
maxAllowableOffset to be used for generalizing geometries returned by the query operation. The maxAllowableOffset is in the units of the outSR. If outSR is not specified, then maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.
geometryPrecision - This option can be used to specify the
number of decimal places in the response geometries.

outWKID - The spatial reference of the returned geometry. gdbVersion - The geodatabase version to query. This parameter

applies only if the isDataVersioned property of the layer queried is true.
returnZ - If true, Z values are included in the results if
the features have Z values. Otherwise, Z values are not returned. The default is false.
returnM - If true, M values are included in the results if
the features have M values. Otherwise, M values are not returned. The default is false.

Table

class arcgis.features.Table(url, gis=None, container=None)

Tables represent entity classes with uniform properties. In addition to working with “entities with location” as features, the GIS can also work with non-spatial entities as rows in tables.

Working with tables is similar to working with feature layers, except that the rows (Features) in a table do not have a geometry, and tables ignore any geometry related operation.

calculate(where, calc_expression, sql_format='standard')

The calculate operation is performed on a feature layer resource. It updates the values of one or more fields in an existing feature service layer based on SQL expressions or scalar values. The calculate operation can only be used if the supportsCalculate property of the layer is true. Neither the Shape field nor system fields can be updated using calculate. System fields include ObjectId and GlobalId. See Calculate a field for more information on supported expressions

Inputs:
where - A where clause can be used to limit the updated records.
Any legal SQL where clause operating on the fields in the layer is allowed.
calcExpression - The array of field/value info objects that

contain the field or fields to update and their scalar values or SQL expression. Allowed types are dictionary and list. List must be a list of dictionary objects. Calculation Format is as follows:

{“field” : “<field name>”, “value” : “<value>”}
sqlFormat - The SQL format for the calcExpression. It can be
either standard SQL92 (standard) or native SQL (native). The default is standard. Values: standard, native
Output:
JSON as string

Usage: >>>print(fl.calculate(where=”OBJECTID < 2”,

calcExpression={“field”: “ZONE”,
“value” : “R1”}))

{‘updatedFeatureCount’: 1, ‘success’: True}

container

The feature layer collection to which this layer belongs.

edit_features(adds=None, updates=None, deletes=None, gdb_version=None, use_global_ids=False, rollback_on_failure=True)

This operation adds, updates, and deletes features to the associated feature layer or table in a single call. Inputs:

adds - The array of features to be added. updates - The array of features to be updateded. deletes - string of OIDs to remove from service gdbVersion - Geodatabase version to apply the edits. useGlobalIds - instead of referencing the default Object ID

field, the service will look at a GUID field to track changes. This means the GUIDs will be passed instead of OIDs for delete, update or add features.
rollbackOnFailure - Optional parameter to specify if the
edits should be applied only if all submitted edits succeed. If false, the server will apply the edits that succeed even if some of the submitted edits fail. If true, the server will apply the edits only if all edits succeed. The default value is true.
Output:
dictionary of messages
fromitem(item, layer_id=0)

Creates a feature layer from a GIS Item. The type of item should be a ‘Feature Service’ that represents a FeatureLayerCollection. The layer_id is the id of the layer in feature layer collection (feature service).

get_html_popup(oid)

The htmlPopup resource provides details about the HTML pop-up authored by the user using ArcGIS for Desktop. Input:

oid - object id of the feature where the HTML pop-up

Output:

manager

Helper object to manage the feature layer, update it’s definition, etc

properties

The properties of this object

query(where='1=1', out_fields='*', time_filter=None, geometry_filter=None, return_geometry=True, return_count_only=False, return_ids_only=False, return_distinct_values=False, return_extent_only=False, group_by_fields_for_statistics=None, statistic_filter=None, result_offset=None, result_record_count=None, object_ids=None, distance=None, units=None, max_allowable_offset=None, out_sr=None, geometry_precision=None, gdb_version=None, order_by_fields=None, out_statistics=None, return_z=False, return_m=False, multipatch_option=None, quanitization_parameters=None, return_centroid=False, **kwargs)

queries a feature service based on a sql statement Inputs:

where - the selection sql statement out_fields - the attribute fields to return objectIds - The object IDs of this layer or table to be

queried.
distance - The buffer distance for the input geometries.
The distance unit is specified by units. For example, if the distance is 100, the query geometry is a point, units is set to meters, and all points within 100 meters of the point are returned.
units - The unit for calculating the buffer distance. If
unit is not specified, the unit is derived from the geometry spatial reference. If the geometry spatial reference is not specified, the unit is derived from the feature service data spatial reference. This parameter only applies if supportsQueryWithDistance is true. Values: esriSRUnit_Meter | esriSRUnit_StatuteMile | esriSRUnit_Foot | esriSRUnit_Kilometer | esriSRUnit_NauticalMile | esriSRUnit_USNauticalMile
timeFilter - a TimeFilter object where either the start time
or start and end time are defined to limit the search results for a given time. The values in the timeFilter should be as UTC timestampes in milliseconds. No checking occurs to see if they are in the right format.
geometryFilter - a GeometryFilter object to parse down a given
query by another spatial dataset.
maxAllowableOffset - This option can be used to specify the
maxAllowableOffset to be used for generalizing geometries returned by the query operation. The maxAllowableOffset is in the units of outSR. If outSR is not specified, maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.

outSR - The spatial reference of the returned geometry. geometryPrecision - This option can be used to specify the

number of decimal places in the response geometries returned by the Query operation.

gdbVersion - Geodatabase version to query returnDistinctValues - If true, it returns distinct values

based on the fields specified in outFields. This parameter applies only if the supportsAdvancedQueries property of the layer is true.
returnIdsOnly - If true, the response only includes an
array of object IDs. Otherwise, the response is a feature set. The default is false.
returnCountOnly - If true, the response only includes the
count (number of features/records) that would be returned by a query. Otherwise, the response is a feature set. The default is false. This option supersedes the returnIdsOnly parameter. If returnCountOnly = true, the response will return both the count and the extent.
returnExtentOnly - If true, the response only includes the
extent of the features that would be returned by the query. If returnCountOnly=true, the response will return both the count and the extent. The default is false. This parameter applies only if the supportsReturningQueryExtent property of the layer is true.
orderByFields - One or more field names on which the
features/records need to be ordered. Use ASC or DESC for ascending or descending, respectively, following every field to control the ordering.
groupByFieldsForStatistics - One or more field names on
which the values need to be grouped for calculating the statistics.
outStatistics - The definitions for one or more field-based
statistics to be calculated.
returnZ - If true, Z values are included in the results if
the features have Z values. Otherwise, Z values are not returned. The default is false.
returnM - If true, M values are included in the results if
the features have M values. Otherwise, M values are not returned. The default is false.
multipatchOption - This option dictates how the geometry of
a multipatch feature will be returned.
resultOffset - This option can be used for fetching query
results by skipping the specified number of records and starting from the next record (that is, resultOffset + 1th).
resultRecordCount - This option can be used for fetching
query results up to the resultRecordCount specified. When resultOffset is specified but this parameter is not, the map service defaults it to maxRecordCount. The maximum value for this parameter is the value of the layer’s maxRecordCount property.
quanitizationParameters - Used to project the geometry onto
a virtual grid, likely representing pixels on the screen.
returnCentroid - Used to return the geometry centroid
associated with each feature returned. If true, the result includes the geometry centroid. The default is false.
kwargs - optional parameters that can be passed to the Query
function. This will allow users to pass additional parameters not explicitly implemented on the function. A complete list of functions available is documented on the Query REST API.
Output:
A FeatureSet containing the features matching the query unless another return type is specified, such as return

The Query operation is performed on a feature service layer resource. The result of this operation are feature sets grouped by source layer/table object IDs. Each feature set contains Feature objects including the values for the fields requested by the user. For related layers, if you request geometry information, the geometry of each feature is also returned in the feature set. For related tables, the feature set does not include geometries. Inputs:

objectIds - the object IDs of the table/layer to be queried relationshipId - The ID of the relationship to be queried. outFields - the list of fields from the related table/layer

to be included in the returned feature set. This list is a comma delimited list of field names. If you specify the shape field in the list of return fields, it is ignored. To request geometry, set returnGeometry to true. You can also specify the wildcard “*” as the value of this parameter. In this case, the result s will include all the field values.
definitionExpression - The definition expression to be
applied to the related table/layer. From the list of objectIds, only those records that conform to this expression are queried for related records.
returnGeometry - If true, the feature set includes the
geometry associated with each feature. The default is true.
maxAllowableOffset - This option can be used to specify the
maxAllowableOffset to be used for generalizing geometries returned by the query operation. The maxAllowableOffset is in the units of the outSR. If outSR is not specified, then maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.
geometryPrecision - This option can be used to specify the
number of decimal places in the response geometries.

outWKID - The spatial reference of the returned geometry. gdbVersion - The geodatabase version to query. This parameter

applies only if the isDataVersioned property of the layer queried is true.
returnZ - If true, Z values are included in the results if
the features have Z values. Otherwise, Z values are not returned. The default is false.
returnM - If true, M values are included in the results if
the features have M values. Otherwise, M values are not returned. The default is false.

FeatureLayerCollection

class arcgis.features.FeatureLayerCollection(url, gis=None)

A FeatureLayerCollection is a collection of feature layers and tables, with the associated relationships among the entities.

In a web GIS, a feature layer collection is exposed as a feature service with multiple feature layers.

Instances of FeatureDatasets can be obtained from feature service Items in the GIS using FeatureLayerCollection.fromitem(item), from feature service endpoints using the constructor, or by accessing the dataset attribute of feature layer objects.

FeatureDatasets can be configured and managed using their manager helper object.

If the dataset supports the sync operation, the replicas helper object allows management and synchronization of replicas for disconnected editing of the feature layer collection.

fromitem(item)
manager

helper object to manage the feature layer collection, update it’s definition, etc

properties

The properties of this object

query(layer_defs_filter=None, geometry_filter=None, time_filter=None, return_geometry=True, return_ids_only=False, return_count_only=False, return_z=False, return_m=False, out_sr=None)

queries the feature layer collection

The Query operation is performed on a feature service layer resource. The result of this operation are feature sets grouped by source layer/table object IDs. Each feature set contains Feature objects including the values for the fields requested by the user. For related layers, if you request geometry information, the geometry of each feature is also returned in the feature set. For related tables, the feature set does not include geometries. Inputs:

objectIds - the object IDs of the table/layer to be queried relationshipId - The ID of the relationship to be queried. outFields - the list of fields from the related table/layer

to be included in the returned feature set. This list is a comma delimited list of field names. If you specify the shape field in the list of return fields, it is ignored. To request geometry, set returnGeometry to true. You can also specify the wildcard “*” as the value of this parameter. In this case, the result s will include all the field values.
definitionExpression - The definition expression to be
applied to the related table/layer. From the list of objectIds, only those records that conform to this expression are queried for related records.
returnGeometry - If true, the feature set includes the
geometry associated with each feature. The default is true.
maxAllowableOffset - This option can be used to specify the
maxAllowableOffset to be used for generalizing geometries returned by the query operation. The maxAllowableOffset is in the units of the outSR. If outSR is not specified, then maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.
geometryPrecision - This option can be used to specify the
number of decimal places in the response geometries.

outWKID - The spatial reference of the returned geometry. gdbVersion - The geodatabase version to query. This parameter

applies only if the isDataVersioned property of the layer queried is true.
returnZ - If true, Z values are included in the results if
the features have Z values. Otherwise, Z values are not returned. The default is false.
returnM - If true, M values are included in the results if
the features have M values. Otherwise, M values are not returned. The default is false.

FeatureSet

class arcgis.features.FeatureSet(features, fields=None, has_z=False, has_m=False, geometry_type=None, spatial_reference=None, display_field_name=None, object_id_field_name=None, global_id_field_name=None)

A set of features with information about their fields, field aliases, geometry type, spatial reference etc.

FeatureSets are commonly used as input/output with several Geoprocessing Tools, and can be the obtained through the query() methods of feature layers. A FeatureSet can be combined with a layer definition to compose a FeatureCollection.

FeatureSet contains Feature objects, including the values for the fields requested by the user. For layers, if you request geometry information, the geometry of each feature is also returned in the FeatureSet. For tables, the FeatureSet does not include geometries.

If a Spatial Reference is not specified at the FeatureSet level, the FeatureSet will assume the SpatialReference of its first feature. If the SpatialReference of the first feature is also not specified, the spatial reference will be UnknownCoordinateSystem.

df

converts the FeatureSet to a Pandas dataframe. Requires pandas

display_field_name

gets/sets the displayFieldName

features

gets the features in the FeatureSet

fields

gets the fields in the FeatureSet

static from_dict(featureset_dict)

returns a featureset from a dict

static from_json(json_str)

returns a featureset from a JSON string

geometry_type

gets/sets the geometry Type

global_id_field_name

gets/sets the globalIdFieldName

has_m

gets/set the M-property

has_z

gets/sets the Z-property

object_id_field_name

gets/sets the object id field

save(save_location, out_name)

Saves a featureset object to a feature class Input:

saveLocation - output location of the data outName - name of the table the data will be saved to

Types:

*.csv - CSV file returned *.json - text file with json * If no extension, a shapefile if the path is a

folder, a featureclass if the path is a GDB
spatial_reference

gets the featureset’s spatial reference

to_dict()

converts the object to Python dictionary

to_json

converts the object to JSON

value

returns object as dictionary

FeatureCollection

class arcgis.features.FeatureCollection(dictdata)

FeatureCollection is an object with a layer definition and a feature set.

It is an in-memory collection of features with rendering information.

Feature Collections can be stored as Items in the GIS, added as layers to a map or scene, passed as inputs to feature analysis tools, and returned as results from feature analysis tools if an output name for a feature layer is not specified when calling the tool.

query()

Returns the data in this feature collection as a FeatureSet. Filtering by where clause is not supported for feature collections