arcgis.features.managers module¶
Helper classes for managing feature layers and datasets. These class are not created by users directly. Instances of this class, are available as a properties of feature layers and make it easier to manage them.
AttachmentManager¶
-
class
arcgis.features.managers.
AttachmentManager
(layer)¶ Manager class for manipulating feature layer attachments. This class is not created by users directly. An instance of this class, called ‘attachments’, is available as a property of the FeatureLayer object, if the layer supports attachments. Users call methods on this ‘attachments’ object to manipulate (create, get, list, delete) attachments.
-
add
(oid, file_path)¶ Adds an attachment to a feature layer Input:
oid - string - OBJECTID value to add attachment to file_path - string - path to file
- Output:
JSON Repsonse
-
delete
(oid, attachment_id)¶ removes an attachment from a feature Input:
oid - integer or string - id of feature attachment_id - integer - id of attachment to erase
- Output:
JSON response
-
download
(oid=None, attachment_id=None, save_path=None)¶ downloads attachment and returns it’s path on disk.
The download tool works as follows:
- 1). if nothing is given, all attachments will be downloaded
example: download()
2). If a single oid and attachment_id are given, the single file will download 3). If a list of oid values are given, all the attachments for those object ids will be saved locally.
Arguement
Description
oid
optional list/string. A list of object Ids or a single value to download data from.
attachment_id
optional string. Id of the attachment to download. This is only honored if return_all is False.
save_folder
optional string. Path to save data to.
- Returns
list of downloaded files
-
get_list
(oid)¶ returns the list of attachements for a given OBJECT ID
-
search
(where='1=1', object_ids=None, global_ids=None, attachment_types=None, size=None, keywords=None, show_images=False, as_df=False)¶ The search method allows querying the layer for its attachments and returns the results as a Pandas DataFrame or dict
Arguement
Description
where
required string. The definition expression to be applied to the related layer/table. From the list of records that are related to the specified object Ids, only those records that conform to this expression will be returned.
Example: where=”STATE_NAME = ‘Alaska’”. The query results will return all attachments in Alaska.
object_ids
optional list/string. The object IDs of this layer/table to be queried.
Syntax: objectIds=<objectId1>,<objectId2>
Example: objectIds=2. The query results will return attachments only for the specified object id.
global_ids
optional list/string. The global IDs of this layer/table to be
queried.
Syntax: globalIds=<globalIds1>,<globalIds2>
Example: globalIds=6s430c5a-kb75-4d52-a0db-b30bg060f0b9,35f0d027-8fc0-4905-a2f6-373c9600d017
The query results will return attachments only for specified global id.
attachment_types
optional list/string. The file format that is supported by query attachment.
Supported attachment types: bmp, ecw, emf, eps, ps, gif, img, jp2, jpc, j2k, jpf, jpg, jpeg, jpe, png, psd, raw, sid, tif, tiff, wmf, wps, avi, mpg, mpe, mpeg, mov, wmv, aif, mid, rmi, mp2, mp3, mp4, pma, mpv2, qt, ra, ram, wav, wma, doc, docx, dot, xls, xlsx, xlt, pdf, ppt, pptx, txt, zip, 7z, gz, gtar, tar, tgz, vrml, gml, json, xml, mdb, geodatabase
Example: attachment_types=’image/jpeg’
size
optional tuple/list. The file size of the attachment is specified in bytes. You can enter a file size range (1000,15000) to query for attachments with the specified range.
Example: size=1000,15000. The query results will return all attachments within the specified file size range (1000 - 15000) bytes.
keywords
optional string. When attachments are uploaded, keywords can be assigned to the uploaded file. By passing a keyword value, the values will be searched.
Example: keywords=’airplanes’
show_images
optional bool. The default is False, when the value is True, the results will be displayed as a HTML table. If the as_df is set to False, this parameter will be ignored.
as_df
optional bool. Default is False, if True, the results will be a Pandas’ DataFrame. If False, the values will be a list of dictionary values.
- Returns
list of downloaded files
-
update
(oid, attachment_id, file_path)¶ updates an existing attachment with a new file Inputs:
oid - string/integer - Unique record ID attachment_id - integer - Unique attachment identifier file_path - string - path to new attachment
- Output:
JSON response
-
SyncManager¶
-
class
arcgis.features.managers.
SyncManager
(featsvc)¶ Manager class for manipulating replicas for syncing disconnected editing of feature layers. This class is not created by users directly. An instance of this class, called ‘replicas’, is available as a property of the FeatureLayerCollection object, if the layer is sync enabled / supports disconnected editing. Users call methods on this ‘replicas’ object to manipulate (create, synchronize, unregister) replicas.
-
create
(replica_name, layers, layer_queries=None, geometry_filter=None, replica_sr=None, transport_type='esriTransportTypeUrl', return_attachments=False, return_attachments_databy_url=False, asynchronous=False, attachments_sync_direction='none', sync_model='none', data_format='json', replica_options=None, wait=False, out_path=None, sync_direction=None, target_type='client')¶ The create operation is performed on a feature layer collection resource. This operation creates the replica between the feature dataset and a client based on a client-supplied replica definition. It requires the Sync capability. See Sync overview for more information on sync. The response for create includes replicaID, replica generation number, and data similar to the response from the feature layer collection query operation. The create operation returns a response of type esriReplicaResponseTypeData, as the response has data for the layers in the replica. If the operation is called to register existing data by using replicaOptions, the response type will be esriReplicaResponseTypeInfo, and the response will not contain data for the layers in the replica.
- Inputs:
replica_name - name of the replica layers - layers to export layer_queries - In addition to the layers and geometry parameters, the layer_queries
parameter can be used to further define what is replicated. This parameter allows you to set properties on a per layer or per table basis. Only the properties for the layers and tables that you want changed from the default are required. Example:
layer_queries = {“0”:{“queryOption”: “useFilter”, “useGeometry”: true, “where”: “requires_inspection = Yes”}}
- geometry_filter - spatial filter from arcgis.geometry.filters module to filter results by a
spatial relationship with another geometry
replica_sr - the spatial reference of the replica geometry. transport_type - The transport_type represents the response format. If the
transport_type is esriTransportTypeUrl, the JSON response is contained in a file, and the URL link to the file is returned. Otherwise, the JSON object is returned directly. The default is esriTransportTypeUrl. If async is true, the results will always be returned as if transport_type is esriTransportTypeUrl. If dataFormat is sqlite, the transportFormat will always be esriTransportTypeUrl regardless of how the parameter is set. Values: esriTransportTypeUrl | esriTransportTypeEmbedded
- return_attachments - If true, attachments are added to the replica and returned in
the response. Otherwise, attachments are not included. The default is false. This parameter is only applicable if the feature service has attachments.
- return_attachments_databy_url - If true, a reference to a URL will be provided for
each attachment returned from create method. Otherwise, attachments are embedded in the response. The default is true. This parameter is only applicable if the feature service has attachments and if return_attachments is true.
- asynchronous - If true, the request is processed as an asynchronous job, and a URL is
returned that a client can visit to check the status of the job. See the topic on asynchronous usage for more information. The default is false.
- attachments_sync_direction - Client can specify the attachmentsSyncDirection when
creating a replica. AttachmentsSyncDirection is currently a createReplica property and cannot be overridden during sync. Values: none, upload, bidirectional
- sync_model - this parameter is used to indicate that the replica is being created for
per-layer sync or per-replica sync. To determine which model types are supported by a service, query the supportsPerReplicaSync, supportsPerLayerSync, and supportsSyncModelNone properties of the Feature Service. By default, a replica is created for per-replica sync. If syncModel is perReplica, the syncDirection specified during sync applies to all layers in the replica. If the syncModel is perLayer, the syncDirection is defined on a layer-by-layer basis.
If syncModel is perReplica, the response will have replicaServerGen. A perReplica syncModel requires the replicaServerGen on sync. The replicaServerGen tells the server the point in time from which to send back changes. If syncModel is perLayer, the response will include an array of server generation numbers for the layers in layerServerGens. A perLayer sync model requires the layerServerGens on sync. The layerServerGens tell the server the point in time from which to send back changes for a specific layer. sync_model=none can be used to export the data without creating a replica. Query the supportsSyncModelNone property of the feature service to see if this model type is supported.
See the RollbackOnFailure and Sync Models topic for more details. Values: perReplica | perLayer | none Example: syncModel=perLayer
- data_format - The format of the replica geodatabase returned in the response. The
default is json. Values: filegdb, json, sqlite, shapefile
- replica_options - This parameter instructs the create operation to create a
new replica based on an existing replica definition (refReplicaId). It can be used to specify parameters for registration of existing data for sync. The operation will create a replica but will not return data. The responseType returned in the create response will be esriReplicaResponseTypeInfo.
wait - if async, wait to pause the process until the async operation is completed. out_path - folder path to save the file
-
create_replica_item
(replica_name, item, destination_gis, layers=None, extent=None)¶ creates a replicated service from a parent to another GIS
-
get
(replica_id)¶ returns replica metadata for a specific replica. Inputs:
- replica_id - The replicaID returned by the feature service
when the replica was created.
-
get_list
()¶ returns all the replicas for the feature layer collection
-
sync_replicated_items
(parent, child, replica_name)¶ synchronizes two replicated items between portals
- Paramters:
- parent
arcgis.gis.Item class that points to a feature service who is the parent (source) dataset.
- child
arcgis.gis.Item class that points to the child replica
- replica_name
name of the replica to synchronize
- Output:
boolean value. True means service is up to date/synchronized, False means the synchronization failed.
-
synchronize
(replica_id, transport_type='esriTransportTypeUrl', replica_server_gen=None, return_ids_for_adds=False, edits=None, return_attachment_databy_url=False, asynchronous=False, sync_direction='snapshot', sync_layers='perReplica', edits_upload_id=None, edits_upload_format=None, data_format='json', rollback_on_failure=True)¶ synchronizes replica with feature layer collection http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r3000000vv000000
-
unregister
(replica_id)¶ unregisters a replica from a feature layer collection Inputs:
- replica_id - The replicaID returned by the feature service
when the replica was created.
-
FeatureLayerCollectionManager¶
-
class
arcgis.features.managers.
FeatureLayerCollectionManager
(url, gis=None, fs=None)¶ Allows updating the definition (if access permits) of a feature layer collection. This class is not created by users directly. An instance of this class, called ‘manager’, is available as a property of the FeatureLayerCollection object.
Users call methods on this ‘manager’ object to manage the feature layer collection.
-
add_to_definition
(json_dict)¶ The add_to_definition operation supports adding a definition property to a hosted feature layer collection service. The result of this operation is a response indicating success or failure with error code and description.
This function will allow users to change or add additional values to an already published service.
- Input:
- json_dict - part to add to host service. The part format can
be derived from the properties property. For layer level modifications, run updates on each individual feature service layer object.
- Output:
JSON message as dictionary
-
create_view
(name, spatial_reference=None, extent=None, allow_schema_changes=True, updateable=True, capabilities='Query', view_layers=None)¶ Creates a view of an existing feature service. You can create a view, if you need a different view of the data represented by a hosted feature layer, for example, you want to apply different editor settings, apply different styles or filters, define which features or fields are available, or share the data to different groups than the hosted feature layer create a hosted feature layer view of that hosted feature layer.
When you create a feature layer view, a new hosted feature layer item is added to Content. This new layer is a view of the data in the hosted feature layer, which means updates made to the data appear in the hosted feature layer and all of its hosted feature layer views. However, since the view is a separate layer, you can change properties and settings on this item separately from the hosted feature layer from which it is created.
For example, you can allow members of your organization to edit the hosted feature layer but share a read-only feature layer view with the public.
To learn more about views visit: https://doc.arcgis.com/en/arcgis-online/share-maps/create-hosted-views.htm
Argument
Description
name
Required string. Name of the new view item
spatial_reference
Optional dict. Specify the spatial reference of the view
extent
Optional dict. Specify the extent of the view
allow_schema_changes
- Optional bool. Default is True. Determines if a view can alter a
service’s schema.
updateable
Optional bool. Default is True. Determines if view can update values
capabilities
- Optional string. Specify capabilities as a comma separated string.
For example “Query, Update, Delete”. Default is ‘Query’.
view_layers
- Optional list. Specify list of layers present in the FeatureLayerCollection
that you want in the view.
- Returns
Returns the newly created item for the view.
-
delete_from_definition
(json_dict)¶ The delete_from_definition operation supports deleting a definition property from a hosted feature layer collection service. The result of this operation is a response indicating success or failure with error code and description. See http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Delete_From_Definition_Feature_Service/02r30000021w000000/ # noqa for additional information on this function. Input:
- json_dict - part to add to host service. The part format can
be derived from the properties property. For layer level modifications, run updates on each individual feature service layer object. Only include the items you want to remove from the FeatureService or layer.
- Output:
JSON Message as dictionary
-
classmethod
fromitem
(item)¶
-
overwrite
(data_file)¶ Overwrite all the features and layers in a hosted feature layer collection service. This operation removes all features but retains the properties (such as metadata, itemID) and capabilities configured on the service. There are some limits to using this operation:
Only hosted feature layer collection services can be overwritten
The original data used to publish this layer should be available on the portal
3. The data file used to overwrite should be of the same format and filename as the original that was used to publish the layer 4. The schema (column names, column data types) of the data_file should be the same as original. You can have additional or fewer rows (features).
In addition to overwriting the features, this operation also updates the data of the item used to published this layer.
- Parameters
data – path to data_file used to overwrite the hosted feature layer collection
- Returns
JSON message as dictionary such as {‘success’:True} or {‘error’:’error message’}
-
property
properties
¶ The properties of this object
-
refresh
()¶ refreshes a feature layer collection
-
update_definition
(json_dict)¶ The update_definition operation supports updating a definition property in a hosted feature layer collection service. The result of this operation is a response indicating success or failure with error code and description.
- Input:
- json_dict - part to add to host service. The part format can
be derived from the properties property. For layer level modifications, run updates on each individual feature service layer object.
- Output:
JSON Message as dictionary
-
FeatureLayerManager¶
-
class
arcgis.features.managers.
FeatureLayerManager
(url, gis=None)¶ Allows updating the definition (if access permits) of a feature layer. This class is not created by users directly. An instance of this class, called ‘manager’, is available as a property of the FeatureLayer object, if the layer can be managed by the user. Users call methods on this ‘manager’ object to manage the feature layer.
-
add_to_definition
(json_dict)¶ The addToDefinition operation supports adding a definition property to a hosted feature layer. The result of this operation is a response indicating success or failure with error code and description.
This function will allow users to change add additional values to an already published service.
- Input:
- json_dict - part to add to host service. The part format can
be derived from the asDictionary property. For layer level modifications, run updates on each individual feature service layer object.
- Output:
JSON message as dictionary
-
delete_from_definition
(json_dict)¶ The deleteFromDefinition operation supports deleting a definition property from a hosted feature layer. The result of this operation is a response indicating success or failure with error code and description. See: http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Delete_From_Definition_Feature_Service/02r30000021w000000/ # noqa for additional information on this function. Input:
- json_dict - part to add to host service. The part format can
be derived from the asDictionary property. For layer level modifications, run updates on each individual feature service layer object. Only include the items you want to remove from the FeatureService or layer.
- Output:
JSON Message as dictionary
-
classmethod
fromitem
(item, layer_id=0)¶ Creates a FeatureLayerManager object 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).
-
property
properties
¶ The properties of this object
-
refresh
()¶ refreshes a service
-
truncate
(attachment_only=False, asynchronous=False, wait=True)¶ The truncate operation supports deleting all features or attachments in a hosted feature service layer. The result of this operation is a response indicating success or failure with error code and description. See: http://resources.arcgis.com/en/help/arcgis-rest-api/#/Truncate_Feature_Layer/02r3000002v0000000/ # noqa for additional information on this function. Input:
- attachment_only - Deletes all the attachments for this layer.
None of the layer features will be deleted when attachmentOnly=true.
- asynchronous - Supports options for asynchronous processing. The
default format is false. It is recommended to set async=true for larger datasets.
- wait - if async, wait to pause the process until the async
operation is completed.
- Output:
JSON Message as dictionary
-
update_definition
(json_dict)¶ The updateDefinition operation supports updating a definition property in a hosted feature layer. The result of this operation is a response indicating success or failure with error code and description.
- Input:
- json_dict - part to add to host service. The part format can
be derived from the asDictionary property. For layer level modifications, run updates on each individual feature service layer object.
- Output:
JSON Message as dictionary
-