Skip to content

Repository files navigation

Download Service for ArcGIS Pro

Download features, table rows, and attachments from ArcGIS MapServer and FeatureServer layer resources into a local dataset.

The tool queries matching object IDs first, downloads records in adaptive blocks, creates the output from the first block, and immediately appends each subsequent block. This approach limits memory use and supports large services more reliably than collecting every FeatureSet before writing the output.

Download Service geoprocessing tool

Features

  • Downloads feature layers and standalone tables.
  • Supports ArcGIS MapServer and FeatureServer layer URLs.
  • Applies an optional SQL WHERE clause.
  • Applies an optional spatial filter and spatial relationship.
  • Downloads related attachments to a local folder.
  • Supports public, portal-hosted, federated, and standalone ArcGIS Server services.
  • Reuses the active ArcGIS Pro portal sign-in token when available.
  • Discovers the standalone ArcGIS Server token endpoint from /rest/info.
  • Renews an invalid or expired token once for ArcGIS REST errors 498 and 499.
  • Reduces the block size automatically when a request URL is too long.
  • Preserves partial output and reports progress if a large download fails.

Requirements

  • ArcGIS Pro with its bundled Python environment and arcpy.
  • Network access to the ArcGIS REST service.
  • HTTPS for protected services is strongly recommended. ArcGIS token generation requires HTTPS.

The current code has been modernized for recent ArcGIS Pro Python environments. Test the toolbox with the specific ArcGIS Pro and ArcGIS Enterprise versions used by your organization before production use.

Installation

  1. Download or clone this repository.
  2. Keep Download Service.tbx and download_service.py in the same folder.
  3. In ArcGIS Pro, open the Catalog pane.
  4. Add a folder connection to the repository folder.
  5. Expand Download Service.tbx and run the Download Service tool.

Parameters

Parameter Description
Hosted Feature Service Select for ArcGIS Online or a federated ArcGIS Enterprise service.
ArcGIS Server Service Select for a standalone ArcGIS Server service.
Portal/AGOL Portal connection used by ArcGIS Pro for hosted or federated services.
Service URL Layer/Table Full REST URL of a layer or table, including its numeric layer ID.
Where Optional SQL filter. When empty, the tool uses 1=1.
Spatial Filter Optional feature class or geometry drawn in ArcGIS Pro.
Spatial Relationship Spatial relationship applied to the filter geometry.
Username Optional username for a protected service.
Password Optional password for a protected service.
Folder attachments Optional existing folder where attachments will be saved.
Output Feature Class/Table Destination feature class or table.

Example layer URLs:

https://gis.example.com/arcgis/rest/services/Planning/Parcels/FeatureServer/0
https://gis.example.com/server/rest/services/Assets/MapServer/3

The URL must point to an individual layer or table, not only to the MapServer or FeatureServer root.

Authentication

Public services

Leave username and password empty. No token is requested.

ArcGIS Online or federated ArcGIS Enterprise

Select Hosted Feature Service. The tool reuses the active ArcGIS Pro portal token when available. If both username and password are supplied, the tool first calls SignInToPortal() for the selected portal and then retrieves its sign-in token.

Standalone ArcGIS Server

Select ArcGIS Server Service and provide both username and password. The tool reads authInfo.tokenServicesUrl from the server's /rest/info resource and sends credentials to the advertised generateToken endpoint using HTTP POST.

Username and password must either both be supplied or both be empty. Credentials and tokens are not written to geoprocessing messages.

If ArcGIS REST returns error 498 or 499, the tool renews the token and retries once. A token error detected while loading a FeatureSet is handled before the adaptive block-size retry, so it is not mistaken for an excessively long request URL.

Queries and adaptive block size

CHUNK is set to 100 in download_service.py. The initial block size is the lower of CHUNK and the service's maxRecordCount.

Records are requested by object ID. If FeatureSet.load() fails while authentication remains valid, the tool halves the current block size and retries the same object IDs. It continues until the block succeeds or contains only one object ID.

The first successful block creates the output dataset with Merge. Later blocks are written immediately with Append. If a later block fails, the existing output is retained and the tool reports how many records were written.

Spatial filter

The spatial filter is optional. Multiple input geometries are combined before the query. An empty spatial filter is ignored. The selected spatial relationship defaults to esriSpatialRelIntersects in the toolbox.

Attachments

When an attachment folder is selected and the service reports hasAttachments: true, attachments are saved using this naming convention:

<object-id>-<attachment-id>-<original-name>

Invalid Windows filename characters and path components are removed. The object ID and attachment ID prefixes keep filenames unique. A failed attachment is reported as a warning without exposing the service token, and the remaining attachments continue downloading.

Proxy and timeout configuration

Set PROXIES near the beginning of download_service.py when an explicit proxy is required:

PROXIES = {
    "http": "http://10.10.1.10:3128",
    "https": "http://10.10.1.10:1080",
}

REQUEST_TIMEOUT contains the connection and read timeouts in seconds:

REQUEST_TIMEOUT = (10, 120)

Error handling

The tool distinguishes a valid query returning no object IDs from connection failures, HTTP errors, invalid JSON, malformed REST responses, invalid SQL filters, and ArcGIS REST authentication errors. ArcGIS error codes, messages, and details are included when available.

Known limitations

  • Coded-value domains and subtypes are not recreated explicitly.
  • Related records are not downloaded.
  • Output field selection is not configurable; all fields are requested.
  • A token renewal can succeed only when ArcGIS Pro still has a valid portal session or standalone server credentials were supplied.
  • Full runtime validation requires ArcGIS Pro because arcpy is not available in standard Python environments.

Planned improvements

  • Preserve domains and subtypes.
  • Download related records.
  • Allow output field selection.
  • Add automated tests with an arcpy test double.

Contributing and issues

Bug reports, feature requests, and contributions are welcome through GitHub Issues.

License

Licensed under the Apache License 2.0.

About

Download data from services of arcgis server or host service

Topics

Resources

Stars

38 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages