Service definitions

Feature layers can contain feature datasets with or without spatial information. In addition, they carry a lot of properties that inform client applications about their state, version, capabilities, extent, allowed operations etc, which make up its definition. Head over to the documentation page to know about this in detail. This section of guide talks about how you can query such properties and update them.

In [1]:
# connect to your GIS with publisher or higher privileges
from arcgis.gis import GIS
gis = GIS('portal url', 'user name', 'password')
In [2]:
search_result= gis.content.search("Ports along west coast", "Feature Layer")
ports_item = search_result[0]
ports_item
Out[2]:
Ports along west coast
Feature Layer Collection by arcgis_python_api
Last Modified: December 07, 2016
0 comments, 0 views

Update definition

The manager property of a FeatureLayerCollection object gives you access to FeatureLayerCollectionManager class which can be used to update the definitions of hosted feature services.

In [4]:
from arcgis.features import FeatureLayerCollection
ports_flc = FeatureLayerCollection.fromitem(ports_item)

Querying the properties property on a FeatureLayerCollection returns a dictionary reprentation of all properties. Let us inspect if metadata fields like description, copyright text are filled.

In [5]:
ports_flc.properties
Out[5]:
{
  "hasVersionedData": false,
  "hasStaticData": false,
  "capabilities": "Query,Editing,Create,Update,Delete,Sync,Extract",
  "editorTrackingInfo": {
    "allowOthersToDelete": true,
    "allowOthersToQuery": true,
    "enableOwnershipAccessControl": false,
    "enableEditorTracking": false,
    "allowOthersToUpdate": true
  },
  "serviceDescription": "",
  "serviceItemId": "b0cb0c9f63e74e8480af0286eb9ac01f",
  "supportedQueryFormats": "JSON, geoJSON",
  "supportsApplyEditsWithGlobalIds": true,
  "maxRecordCount": 2000,
  "initialExtent": {
    "ymin": 2067451.3308849982,
    "xmin": -18000740.10863,
    "xmax": -12808635.83017,
    "ymax": 5895799.859614996,
    "spatialReference": {
      "wkid": 102100,
      "latestWkid": 3857
    }
  },
  "description": "",
  "syncEnabled": true,
  "allowGeometryUpdates": true,
  "spatialReference": {
    "wkid": 102100,
    "latestWkid": 3857
  },
  "enableZDefaults": false,
  "layers": [
    {
      "name": "ports_west_USA",
      "id": 0
    }
  ],
  "units": "esriMeters",
  "syncCapabilities": {
    "supportsRegisteringExistingData": true,
    "supportsAttachmentsSyncDirection": true,
    "supportsPerReplicaSync": false,
    "supportsAsync": true,
    "supportsSyncModelNone": true,
    "supportsRollbackOnFailure": false,
    "supportsSyncDirectionControl": true,
    "supportsPerLayerSync": true
  },
  "copyrightText": "",
  "fullExtent": {
    "ymin": 2241467.1730999984,
    "xmin": -17764735.3687,
    "xmax": -13044640.570099998,
    "ymax": 5721784.0173999965,
    "spatialReference": {
      "wkid": 102100,
      "latestWkid": 3857
    }
  },
  "allowUpdateWithoutMValues": true,
  "currentVersion": 10.5,
  "tables": [],
  "supportsDisconnectedEditing": false
}

Both the description and copyright is empty. We can update it by calling the update_definition() and passing a dictionary representation of the fields to be updated.

In [6]:
update_dict = {'description':'Updated using ArcGIS Python API',
              'copyrightText':'Rohit Singh'}
ports_flc.manager.update_definition(update_dict)
Out[6]:
{'success': True}

Let us access the service definition once again to see if these fields are updated

In [7]:
ports_flc.properties.description
Out[7]:
'Updated using ArcGIS Python API'
In [8]:
ports_flc.properties.copyrightText
Out[8]:
'Rohit Singh'

Turning off editing and sync capabilities

In addition to adding metadata, I would like to turn off sync and limit the capabilities to query.

In [10]:
update_dict2 = {"capabilities": "Query",
               "syncEnabled": False}
ports_flc.manager.update_definition(update_dict2)
Out[10]:
{'success': True}
In [11]:
ports_flc.properties.capabilities
Out[11]:
'Query'
In [12]:
ports_flc.properties.syncEnabled
Out[12]:
False
In [13]:
"syncCapabilities" in ports_flc.properties
Out[13]:
False

Turning off syncEnabled automatically removes syncCapabilities.


Feedback on this topic?