arcrest.agol package

Submodules

arcrest.agol.services module

class arcrest.agol.services.FeatureLayer(url, securityHandler=None, initialize=False, proxy_url=None, proxy_port=None)[source]

Bases: arcrest._abstract.abstract.BaseAGOLClass

This contains information about a feature service’s layer.

addAttachment(oid, file_path)[source]

Adds an attachment to a feature service Input:

oid - string - OBJECTID value to add attachment to file_path - string - path to file
Output:
JSON Repsonse
addFeature(features, gdbVersion=None, rollbackOnFailure=True)[source]

Adds a single feature to the service Inputs:

feature - list of common.Feature object or a single
common.Feature Object or a FeatureSet object

gdbVersion - Geodatabase version to apply the edits 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:
JSON message as dictionary
addFeatures(fc, attachmentTable=None, nameField='ATT_NAME', blobField='DATA', contentTypeField='CONTENT_TYPE', rel_object_field='REL_OBJECTID', lowerCaseFieldNames=False)[source]

adds a feature to the feature service Inputs:

fc - string - path to feature class data to add. attachmentTable - string - (optional) path to attachment table nameField - string - (optional) name of file field in attachment table blobField - string - (optional) name field containing blob data contentTypeField - string - (optional) name of field containing content type rel_object_field - string - (optional) name of field with OID of feature class
Output:
boolean, add results message as list of dictionaries
administration

returns the hostservice object to manage the back-end functions

advancedQueryCapabilities

returns the advanced query capabilities

allowGeometryUpdates

returns boolean if geometry updates are allowed

applyEdits(addFeatures=[], updateFeatures=[], deleteFeatures=None, gdbVersion=None, useGlobalIds=False, rollbackOnFailure=True)[source]

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

addFeatures - The array of features to be added. These
features should be common.Feature objects
updateFeatures - The array of features to be updateded.
These features should be common.Feature objects

deleteFeatures - 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
calculate(where, calcExpression, sqlFormat='standard')[source]

The calculate operation is performed on a feature service 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: >>>sh = arcrest.AGOLTokenSecurityHandler(“user”, “pw”) >>>fl = arcrest.agol.FeatureLayer(url=”someurl”,

securityHandler=sh, initialize=True)
>>>print fl.calculate(where=”OBJECTID < 2”,
calcExpression={“field”: “ZONE”,
“value” : “R1”})

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

canModifyLayer

returns boolean to say if layer can be modified

canScaleSymbols

states if symbols can scale

capabilities

operations that can be performed on layer

copyrightText

returns the copyright text

create_fc_template(out_path, out_name)[source]

creates a featureclass template on local disk

create_feature_template()[source]

creates a feature template

currentVersion

returns the current version

defaultVisibility

returns the default visibility of the layer

definitionExpression

returns the definitionExpression

deleteAttachment(oid, attachment_id)[source]

removes an attachment from a feature service feature Input:

oid - integer or string - id of feature attachment_id - integer - id of attachment to erase
Output:
JSON response
deleteFeatures(objectIds='', where='', geometryFilter=None, gdbVersion=None, rollbackOnFailure=True)[source]

removes 1:n features based on a sql statement Input:

objectIds - The object IDs of this layer/table to be deleted 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.
geometryFilter - a filters.GeometryFilter object to limit
deletion by a geometry.
gdbVersion - Geodatabase version to apply the edits. This
parameter applies only if the isDataVersioned property of the layer is true
rollbackOnFailure - 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:
JSON response as dictionary
description

returns the layer’s description

displayField

returns the primary display field

drawingInfo

returns the symbol information about the layer

editFieldsInfo

returns edit field info

editingInfo

returns the edit information

effectiveMaxScale

returns the effective maximum scale value

effectiveMinScale

returns the effective minimum scale value

extent

returns the extent

fields

returns the layer’s fields

geometryType

returns the geometry type

getHTMLPopup(oid)[source]

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:

get_local_copy(out_path, includeAttachments=False)[source]

exports the whole feature service to a feature class Input:

out_path - path to where the data will be placed includeAttachments - default False. If sync is not supported

then the paramter is ignored.
Output:
path to exported feature class or fgdb (as list)
globalIdField

returns the global id field

hasAttachments

boolean that tells if attachments are associated with layer

hasLabels

returns if layer has labels on or not

hasM

returns if it has a m value or not

hasStaticData

boolean T/F if static data is present

hasZ

returns if it has a Z value or not

htmlPopupType

returns the popup type

id

returns the id

indexes

gets the indexes

isDataVersioned

returns boolean if data is in version control

listAttachments(oid)[source]

list attachements for a given OBJECT ID

maxRecordCount

returns the maximum returned records

maxRecordCountFactor

returns the maxRecordCountFactor for the feature layer

maxScale

sets the max scale

minScale

minimum scale layer will show

name

returns the name

objectIdField
ownershipBasedAccessControlForFeatures

returns value for owernship based access control

parentLayer

returns information about the parent

query(where='1=1', out_fields='*', timeFilter=None, geometryFilter=None, returnGeometry=True, returnIDsOnly=False, returnCountOnly=False, returnFeatureClass=False, returnDistinctValues=False, returnExtentOnly=False, groupByFieldsForStatistics=None, statisticFilter=None, resultOffset='', resultRecordCount='', out_fc=None, objectIds='', **kwargs)[source]

queries a feature service based on a sql statement Inputs:

where - the selection sql statement out_fields - the attribute fields to return 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.
returnGeometry - true means a geometry will be returned,
else just the attributes
returnIDsOnly - false is default. True means only OBJECTIDs
will be returned
returnCountOnly - if True, then an integer is returned only
based on the sql statement
returnFeatureClass - Default False. If true, query will be
returned as feature class
groupByFieldsForStatistics - One or more field names on
which the values need to be grouped for calculating the statistics.

resultOffset - Default is 0. If set, 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.

statisticFilter - object that performs statistic queries out_fc - only valid if returnFeatureClass is set to True.

Output location of query.
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 list of Feature Objects (default) or a path to the output featureclass if returnFeatureClass is set to True.

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.
refresh()[source]

refreshes all the properties of the service

relationships

returns the relationships for the layer

securityHandler

gets the security handler

serviceItemId

returns the service item id

standardMaxRecordCount

returns the standardMaxRecordCount for the feature layer

subLayers

returns sublayers for layer

supportedQueryFormats

returns supported query formats

supportsAdvancedQueries

boolean value if advanced queries is supported

supportsApplyEditsWithGlobalIds

returns the url for the feature layer

supportsAttachmentsByUploadId

returns is supports attachments by uploads id

supportsCalculate

returns the supports calculate values

supportsCoordinatesQuantization

returns the supports calculate values

supportsRollbackOnFailureParameter

returns if rollback on failure supported

supportsStatistics

boolean to if supports statistics

supportsValidateSql

returns the supports calculate values

templates

gets the template

tileMaxRecordCount

returns the tileMaxRecordCount for the feature layer

timeInfo

returns the time information about the layer

type

returns the type

typeIdField

returns the type Id field

types

returns the types

updateAttachment(oid, attachment_id, file_path)[source]

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
updateFeature(features, gdbVersion=None, rollbackOnFailure=True)[source]

updates an existing feature in a feature service layer Input:

feature - feature object(s) to get updated. A single
feature, a list of feature objects can be passed, or a FeatureSet object.
Output:
dictionary of result messages
url

returns the url for the feature layer

useStandardizedQueries

returns value if standardized queries can be used

class arcrest.agol.services.FeatureService(url, securityHandler=None, initialize=False, proxy_url=None, proxy_port=None)[source]

Bases: arcrest._abstract.abstract.BaseAGOLClass

contains information about a feature service

administration

returns the hostservice object to manage the back-end functions

allowGeometryUpdates

informs the user if the data allows geometry updates

capabilities

returns a list of capabilities

copyrightText

returns the copyright text

createReplica(replicaName, layers, layerQueries=None, geometryFilter=None, replicaSR=None, transportType='esriTransportTypeUrl', returnAttachments=False, returnAttachmentsDatabyURL=False, async=False, attachmentsSyncDirection='none', syncModel='none', dataFormat='json', replicaOptions=None, wait=False, out_path=None)[source]

The createReplica operation is performed on a feature service resource. This operation creates the replica between the feature service 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 createReplica includes replicaID, server generation number, and data similar to the response from the feature service query operation. The createReplica 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:

replicaName - name of the replica layers - layers to export layerQueries - In addition to the layers and geometry parameters, the layerQueries

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:

layerQueries = {“0”:{“queryOption”: “useFilter”, “useGeometry”: true, “where”: “requires_inspection = Yes”}}
geometryFilter - Geospatial filter applied to the replica to
parse down data output.
returnAttachments - If true, attachments are added to the replica and returned in the
response. Otherwise, attachments are not included.
returnAttachmentDatabyURL - If true, a reference to a URL will be provided for each
attachment returned from createReplica. Otherwise, attachments are embedded in the response.

replicaSR - the spatial reference of the replica geometry. transportType - The transportType represents the response format. If the

transportType 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 transportType is esriTransportTypeUrl. If dataFormat is sqlite, the transportFormat will always be esriTransportTypeUrl regardless of how the parameter is set. Values: esriTransportTypeUrl | esriTransportTypeEmbedded
returnAttachments - 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.
returnAttachmentsDatabyURL - If true, a reference to a URL will be provided for
each attachment returned from createReplica. Otherwise, attachments are embedded in the response. The default is true. This parameter is only applicable if the feature service has attachments and if returnAttachments is true.
attachmentsSyncDirection - 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
async - 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.
syncModel - Client can specify the attachmentsSyncDirection when creating a replica.
AttachmentsSyncDirection is currently a createReplica property and cannot be overridden during sync.
dataFormat - The format of the replica geodatabase returned in the response. The
default is json. Values: filegdb, json, sqlite, shapefile
replicaOptions - This parameter instructs the createReplica 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 createReplica 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

currentVersion

returns the map service current version

description

returns the service description

documentInfo

returns the document information

editingInfo

returns the editing information

editorTrackingInfo

returns the editor tracking information

enableZDefaults

returns the enable Z defaults value

fullExtent

returns the full extent of the feature service

hasStaticData

returns boolean for has statistic data

hasVersionedData

returns boolean for versioned data

initialExtent

returns the initial extent of the feature service

layers

returns a list of layer objects

maxRecordCount

returns the max record count

query(layerDefsFilter=None, geometryFilter=None, timeFilter=None, returnGeometry=True, returnIdsOnly=False, returnCountOnly=False, returnZ=False, returnM=False, outSR=None)[source]

The Query operation is performed on a feature service resource

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.
refresh_service()[source]

repopulates the properties of the service

replicaInfo(replica_id)[source]

The replica info resources lists replica metadata for a specific replica. Inputs:

replica_id - The replicaID returned by the feature service
when the replica was created.
replicaStatus(url)[source]

gets the replica status when exported async set to True

replicas

returns all the replicas for a feature service

securityHandler

returns the security handler

serviceDescription

returns the serviceDescription of the map service

serviceItemId

returns the serviceItemId

size

returns the size parameter

spatialReference

returns the spatial reference

supportedQueryFormats

returns the supported query formats

supportsApplyEditsWithGlobalIds

returns the supportsApplyEditsWithGlobalIds property

supportsDisconnectedEditing

returns boolean is disconnecting editted supported

syncCapabilities

type of sync that can be performed

syncEnabled

informs the user if sync of data can be performed

synchronizeReplica(replicaID, transportType='esriTransportTypeUrl', replicaServerGen=None, returnIdsForAdds=False, edits=None, returnAttachmentDatabyURL=False, async=False, syncDirection='snapshot', syncLayers='perReplica', editsUploadID=None, editsUploadFormat=None, dataFormat='json', rollbackOnFailure=True)[source]

TODO: implement synchronize replica http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r3000000vv000000

tables

returns the tables

unRegisterReplica(replica_id)[source]

removes a replica from a feature service Inputs:

replica_id - The replicaID returned by the feature service
when the replica was created.
units

returns the measurement unit

uploads

returns the class to perform the upload function. it will only return the uploads class if syncEnabled is True.

url

returns the url for the feature service

xssPreventionInfo

returns the xssPreventionInfo information

zDefault

returns the Z default value

class arcrest.agol.services.TableLayer(url, securityHandler=None, initialize=False, proxy_url=None, proxy_port=None)[source]

Bases: arcrest.agol.services.FeatureLayer

Table object is exactly like FeatureLayer object

class arcrest.agol.services.TiledService(url, securityHandler, initialize=False, proxy_url=None, proxy_port=None)[source]

Bases: arcrest._abstract.abstract.BaseAGOLClass

AGOL Tiled Map Service

access

returns the access value

capabilities

returns the capabilities

copyrightText

returns the copyright information

created

returns the created value

currentVersion

returns the current version

description

returns the description

documentInfo

returns the document information

exportTilesAllowed

export tiles allowed

fullExtent

returns the full extent

id

returns the ID

initialExtent

initial extent of tile service

layers

returns the layers

mapName

returns the map name

maxExportTilesCount

returns the max export tiles count

maxScale

returns the maximum scale

minScale

returns the minimum scale

modified

returns the modified value

name

returns the service name

securityHandler

gets the security handler

server

returns the server information

serviceDescription

returns the service description

singleFusedMapCache

information about the single fused map cache

spatialReference

returns the spatial reference value

status

returns the status

storageFormat

returns the storage format

supportedImageFormatTypes

returns the supported image format types

tables

returns the tables in the map service

tileInfo

returns the tile information

tileServers

returns the tile services value

type

returns the type

units

returns the units

Module contents