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.

# connect to your GIS with publisher or higher privileges
from arcgis.gis import GIS
gis = GIS('portal url', 'user name', 'password')
search_result= gis.content.search("Ports along west coast", "Feature Layer")
ports_item = search_result[0]
ports_item
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.

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.

ports_flc.properties
{
  "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.

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

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

ports_flc.properties.description
'Updated using ArcGIS Python API'
ports_flc.properties.copyrightText
'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.

update_dict2 = {"capabilities": "Query",
               "syncEnabled": False}
ports_flc.manager.update_definition(update_dict2)
{'success': True}
ports_flc.properties.capabilities
'Query'
ports_flc.properties.syncEnabled
False
"syncCapabilities" in ports_flc.properties
False

Turning off syncEnabled automatically removes syncCapabilities.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.