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.
-
delete_features
(deletes=None, where=None, geometry_filter=None, gdb_version=None, rollback_on_failure=True)¶ This operation deletes features in a feature layer or table Inputs:
deletes - string of OIDs to remove from service where - A where clause for the query filter.
Any legal SQL where clause operating on the fields in the layer is allowed. Features conforming to the specified where clause will be deleted.- geometry_filter - spatial filter from arcgis.geometry.filters module to filter results by a
- spatial relationship with another geometry
gdb_version - Geodatabase version to apply the edits. rollback_on_failure - 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
-
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-upOutput:
-
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, return_all_records=True, **kwargs)¶ queries a feature layer based on a sql statement Inputs:
where - the selection sql statement out_fields - the attribute fields to return object_ids - 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
- time_filter - 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.
- geometry_filter - spatial filter from arcgis.geometry.filters module to filter results by a
- spatial relationship with another geometry
- max_allowable_offset - 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.
out_sr - The spatial reference of the returned geometry. geometry_precision - This option can be used to specify the
number of decimal places in the response geometries returned by the Query operation.gdb_version - Geodatabase version to query return_geometry - If true, geometry is returned with the query. Default is true. return_distinct_values - 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.- return_ids_only - If true, the response only includes an
- array of object IDs. Otherwise, the response is a feature set. The default is false.
- return_count_only - 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.
- return_extent_only - 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.
- order_by_fields - 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.
- group_by_fields_for_statistics - One or more field names on
- which the values need to be grouped for calculating the statistics.
- out_statistics - The definitions for one or more field-based
- statistics to be calculated.
- return_z - 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.
- return_m - 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.
- multipatch_option - This option dictates how the geometry of
- a multipatch feature will be returned.
- result_offset - 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). This option is ignored if return_all_records is True (i.e. by default).
- result_record_count - This option can be used for fetching
- query results up to the result_record_count specified. When result_offset is specified but this parameter is not, the map service defaults it to max_record_count. The maximum value for this parameter is the value of the layer’s max_record_count property. This option is ignored if return_all_records is True (i.e. by default).
- quantization_parameters - Used to project the geometry onto
- a virtual grid, likely representing pixels on the screen.
- return_centroid - Used to return the geometry centroid
- associated with each feature returned. If true, the result includes the geometry centroid. The default is false.
- return_all_records - When True, the query operation will call
- the service until all records that satisfy the where_clause are returned. Note: result_offset and result_record_count will be ignored if return_all_records is True. Also, if return_count_only, return_ids_only, or return_extent_only are True, this parameter will be ignored.
- 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 count
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.
-
validate_sql
(sql, sql_type='where')¶ The validate_sql operation validates an SQL-92 expression or WHERE clause. The validate_sql operation ensures that an SQL-92 expression, such as one written by a user through a user interface, is correct before performing another operation that uses the expression. For example, validateSQL can be used to validate information that is subsequently passed in as part of the where parameter of the calculate operation. validate_sql also prevents SQL injection. In addition, all table and field names used in the SQL expression or WHERE clause are validated to ensure they are valid tables and fields.
Parameters: sql: the SQL expression of WHERE clause to validate Example: “Population > 300000”
sql_type: Three SQL types are supported in validate_sql - where (default) - Represents the custom WHERE clause the user
can compose when querying a layer or using calculate.
- expression - Represents an SQL-92 expression. Currently, expression is used as a default value expression when adding a new field or using the calculate API.
- statement - Represents the full SQL-92 statement that can be passed directly to the database. No current ArcGIS REST API resource or operation supports using the full SQL-92 SELECT statement directly. It has been added to the validateSQL for completeness. Values: where | expression | statement
-
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.
-
delete_features
(deletes=None, where=None, geometry_filter=None, gdb_version=None, rollback_on_failure=True)¶ This operation deletes features in a feature layer or table Inputs:
deletes - string of OIDs to remove from service where - A where clause for the query filter.
Any legal SQL where clause operating on the fields in the layer is allowed. Features conforming to the specified where clause will be deleted.- geometry_filter - spatial filter from arcgis.geometry.filters module to filter results by a
- spatial relationship with another geometry
gdb_version - Geodatabase version to apply the edits. rollback_on_failure - 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
-
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-upOutput:
-
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, return_all_records=True, **kwargs)¶ queries a feature layer based on a sql statement Inputs:
where - the selection sql statement out_fields - the attribute fields to return object_ids - 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
- time_filter - 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.
- geometry_filter - spatial filter from arcgis.geometry.filters module to filter results by a
- spatial relationship with another geometry
- max_allowable_offset - 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.
out_sr - The spatial reference of the returned geometry. geometry_precision - This option can be used to specify the
number of decimal places in the response geometries returned by the Query operation.gdb_version - Geodatabase version to query return_geometry - If true, geometry is returned with the query. Default is true. return_distinct_values - 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.- return_ids_only - If true, the response only includes an
- array of object IDs. Otherwise, the response is a feature set. The default is false.
- return_count_only - 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.
- return_extent_only - 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.
- order_by_fields - 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.
- group_by_fields_for_statistics - One or more field names on
- which the values need to be grouped for calculating the statistics.
- out_statistics - The definitions for one or more field-based
- statistics to be calculated.
- return_z - 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.
- return_m - 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.
- multipatch_option - This option dictates how the geometry of
- a multipatch feature will be returned.
- result_offset - 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). This option is ignored if return_all_records is True (i.e. by default).
- result_record_count - This option can be used for fetching
- query results up to the result_record_count specified. When result_offset is specified but this parameter is not, the map service defaults it to max_record_count. The maximum value for this parameter is the value of the layer’s max_record_count property. This option is ignored if return_all_records is True (i.e. by default).
- quantization_parameters - Used to project the geometry onto
- a virtual grid, likely representing pixels on the screen.
- return_centroid - Used to return the geometry centroid
- associated with each feature returned. If true, the result includes the geometry centroid. The default is false.
- return_all_records - When True, the query operation will call
- the service until all records that satisfy the where_clause are returned. Note: result_offset and result_record_count will be ignored if return_all_records is True. Also, if return_count_only, return_ids_only, or return_extent_only are True, this parameter will be ignored.
- 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 count
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.
-
validate_sql
(sql, sql_type='where')¶ The validate_sql operation validates an SQL-92 expression or WHERE clause. The validate_sql operation ensures that an SQL-92 expression, such as one written by a user through a user interface, is correct before performing another operation that uses the expression. For example, validateSQL can be used to validate information that is subsequently passed in as part of the where parameter of the calculate operation. validate_sql also prevents SQL injection. In addition, all table and field names used in the SQL expression or WHERE clause are validated to ensure they are valid tables and fields.
Parameters: sql: the SQL expression of WHERE clause to validate Example: “Population > 300000”
sql_type: Three SQL types are supported in validate_sql - where (default) - Represents the custom WHERE clause the user
can compose when querying a layer or using calculate.
- expression - Represents an SQL-92 expression. Currently, expression is used as a default value expression when adding a new field or using the calculate API.
- statement - Represents the full SQL-92 statement that can be passed directly to the database. No current ArcGIS REST API resource or operation supports using the full SQL-92 SELECT statement directly. It has been added to the validateSQL for completeness. Values: where | expression | statement
-
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.
Note: You can use the layers and tables property to get to the individual layers and tables in this 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.
-
upload
(path, description=None)¶ Uploads a new item to the server. Once the operation is completed successfully, the JSON structure of the uploaded item is returned.
- Parameters:
path: path of the file to upload description: optional descriptive text for the upload item
-
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_dataframe
(df)¶ returns a featureset from a Pandas’ Data or Spatial DataFrame
-
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:
-
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
-
SpatialDataFrame¶
-
class
arcgis.features.
SpatialDataFrame
(*args, **kwargs)¶ A Spatial Dataframe is an object to manipulate, manage and translate data into new forms of information for users.
- Required Parameters:
- None
- Optional:
param data: panda’s dataframe containing attribute information param geometry: list/array/geoseries of arcgis.geometry objects param sr: spatial reference of the dataframe. This can be the factory code, WKT string, arcpy.SpatialReference object, or arcgis.SpatailReference object. param gis: passing a gis.GIS object set to Pro will ensure arcpy is installed and a full swatch of functionality is available to the end user.
-
copy
(deep=True)¶ Make a copy of this SpatialDataFrame object Parameters:
Deep: boolean, default True Make a deep copy, i.e. also copy data - Returns:
copy: of SpatialDataFrame
-
erase
(other, inplace=False)¶ Erases
-
static
from_df
(df, address_column='address', geocoder=None)¶ Returns a SpatialDataFrame from a dataframe with an address column. Inputs:
df: Pandas dataframe with an address column- Optional Parameters:
- address_column: string, default “address”. This is the name of a
- column in the specified dataframe that contains addresses (as strings). The addresses are batch geocoded using the GIS’s first configured geocoder and their locations used as the geometry of the spatial dataframe. Ignored if the ‘geometry’ parameter is also specified.
- geocoder: the geocoder to be used. If not specified,
- the active GIS’s first geocoder is used.
NOTE: Credits will be consumed for batch_geocoding, from the GIS to which the geocoder belongs.
-
static
from_featureclass
(filename, **kwargs)¶ Returns a SpatialDataFrame from a feature class. Inputs:
filename: full path to the feature class- Optional Parameters:
- sql_clause: sql clause to parse data down where_clause: where statement sr: spatial reference object
-
static
from_hdf
(path_or_buf, key=None, **kwargs)¶ read from the store, close it if we opened it
Retrieve pandas object stored in file, optionally based on where criteria
- path_or_buf : path (string), buffer, or path object (pathlib.Path or
py._path.local.LocalPath) to read from
New in version 0.19.0: support for pathlib, py.path.
- key : group identifier in the store. Can be omitted if the HDF file
- contains a single pandas object.
where : list of Term (or convertable) objects, optional start : optional, integer (defaults to None), row number to start
selection- stop : optional, integer (defaults to None), row number to stop
- selection
- columns : optional, a list of columns that if not None, will limit the
- return columns
iterator : optional, boolean, return an iterator, default False chunksize : optional, nrows to include in iteration, return an iterator
The selected object
-
static
from_layer
(layer, **kwargs)¶ Returns a SpatialDataFrame from a FeatureLayer or Table object. Inputs:
param layer: FeatureLayer or Table param gis: GIS object Returns a SpatialDataFrame for services with geometry and Panda’s Dataframe for table services.
-
geoextent
¶ returns the extent of the spatial dataframe
-
geometry
¶ Get/Set the geometry data for SpatialDataFrame
-
merge_datasets
(other)¶ This operation combines two dataframes into one new DataFrame. If the operation is combining two SpatialDataFrames, the geometry_type must match.
-
plot
(*args, **kwargs)¶ writes the spatial dataframe to a map
-
reproject
(spatial_reference, transformation=None, inplace=False)¶ Reprojects a given dataframe into a new coordinate system.
-
select_by_location
(other, matches_only=True)¶ Selects all rows in a given SpatialDataFrame based on a given geometry
- Inputs:
other: arcpy.Geometry object matches_only: boolean value, if true, only matched records will be
returned, else a field called ‘select_by_location’ will be added to the dataframe with the results of the select by location.
-
set_geometry
(col, drop=False, inplace=False, sr=None)¶ Set the SpatialDataFrame geometry using either an existing column or the specified input. By default yields a new object.
The original geometry column is replaced with the input.
Parameters: keys: column label or array drop: boolean, default True
Delete column to be used as the new geometry- inplace: boolean, default False
- Modify the SpatialDataFrame in place (do not create a new object)
- sr : str/result of fion.get_sr (optional)
- Coordinate system to use. If passed, overrides both DataFrame and col’s sr. Otherwise, tries to get sr from passed col values or DataFrame.
Returns: SpatialDataFrame
-
to_featureclass
(out_location, out_name, overwrite=True, skip_invalid=True)¶ converts a SpatialDataFrame to a feature class
- Parameters:
out_location: save location workspace out_name: name of the feature class to save as overwrite: boolean. True means to erase and replace value, false means to append skip_invalids: if True, any bad rows will be ignored. - Output:
- tuple of feature class path and list of bad rows by index number.
-
to_featurelayer
(title, gis=None, tags=None)¶ publishes a spatial dataframe to a new feature layer
-
to_featureset
()¶ Converts a spatial dataframe to a feature set object
-
to_hdf
(path_or_buf, key, **kwargs)¶ Write the contained data to an HDF5 file using HDFStore.
path_or_buf : the path (string) or HDFStore object key : string
indentifier for the group in the storemode : optional, {‘a’, ‘w’, ‘r+’}, default ‘a’
'w'
- Write; a new file is created (an existing file with the same name would be deleted).
'a'
- Append; an existing file is opened for reading and writing, and if the file does not exist it is created.
'r+'
- It is similar to
'a'
, but the file must already exist.
- format : ‘fixed(f)|table(t)’, default is ‘fixed’
- fixed(f) : Fixed format
- Fast writing/reading. Not-appendable, nor searchable
- table(t) : Table format
- Write as a PyTables Table structure which may perform worse but allow more flexible operations like searching / selecting subsets of the data
- append : boolean, default False
- For Table formats, append the input data to the existing
- data_columns : list of columns, or True, default None
List of columns to create as indexed data columns for on-disk queries, or True to use all columns. By default only the axes of the object are indexed. See here.
Applicable only to format=’table’.
- complevel : int, 1-9, default 0
- If a complib is specified compression will be applied where possible
- complib : {‘zlib’, ‘bzip2’, ‘lzo’, ‘blosc’, None}, default None
- If complevel is > 0 apply compression to objects written in the store wherever possible
- fletcher32 : bool, default False
- If applying compression use the fletcher32 checksum
- dropna : boolean, default False.
- If true, ALL nan rows will not be written to store.
Submodules¶
- arcgis.features.analysis module
- aggregate_points
- calculate_density
- connect_origins_to_destinations
- create_buffers
- create_drive_time_areas
- create_route_layers
- create_viewshed
- create_watersheds
- derive_new_locations
- dissolve_boundaries
- enrich_layer
- extract_data
- find_existing_locations
- find_hot_spots
- find_nearest
- find_similar_locations
- interpolate_points
- join_features
- merge_layers
- overlay_layers
- plan_routes
- summarize_nearby
- summarize_within
- trace_downstream
- arcgis.features.analyze_patterns module
- arcgis.features.enrich_data module
- arcgis.features.find_locations module
- arcgis.features.manage_data module
- arcgis.features.summarize_data module
- arcgis.features.use_proximity module
- arcgis.features.elevation module
- arcgis.features.managers module