Retrieve Attachments From Features in a Vector

Learn how to access attachments from existing features and make use of the data within custom analytics.

1. Description

This article explains how to retrieve attachments from features in a vector, especially in order to use the attachments in custom analytics.

Examples of attachments that can be retrieved:

  • Images (ex: .jpg) attached to a feature with the Infield Mobile App
  • Images (ex: .jpg), files (ex: .pdf) attached to a feature directly in the platform in the interface

A feature here corresponds to a polygon, line, or point of a vector file.  Example: one microplot of a microplots file.

2. Workflow

Step 1 - Connect to the SDK:

import alteia
sdk = alteia.SDK(config_path=MY_CONFIG_PATH)

Step 2 - Initialize variables:


Find the collection of the features to retrieve attachments from features. The collection is linked to the map-service vector.

Step 3 - Search the vector map-service:

vector =
       'project': {'$eq': PROJECT_ID},
       '': {'$eq': 'map-service'},
       'name': {'$eq': VECTOR_NAME}
)[0] # return a list so take only the first element

Step 4 - Extract the collection ID and then the features IDs to iterate on them to extract attachments:

# Extract collection ID
collection_id = vector.components[0]['collection']['id']

# Describe collection to find features
collection = sdk.collections.describe(collection_id) 
# Return a list of features ID
features = collection.features 

# Iterate on features
for feat in features:
   f = sdk.features.describe(feat)
   if hasattr(f, 'attachments'): # Keep only features with attachments
       attachments_ids = f.attachments # returns a list of attachments ID
       for a in attachments_ids:
           d = sdk.datasets.describe(a) # attachment is considered as a dataset
               overwrite=True) # false by default but the download fail if there is the same attachment name

3. Results

Once retrieved, the attachments can be used by your code in custom analytics for example.