Hello,
I'm looking for a way to count attachments found within my feature service and return this number. These attachments are images that were collected in Collector.
Would Arcade be the best way to go?
Thanks
There are a couple of ways to achieve this.
If it's an once off calculatation, you can either:
1) Make a ArcGIS REST API call to Query Attachments to get the json response and count the elements:
e.g.
and paste the json in a json viewer like this:
JSON Editor Online - view, edit and format JSON online
You can view the array and get the element count.
OR
2) Run a python script to query the feature layer.
The following script downloads the attachments, takes a total file-size count as well as total number of attachments:
You can also trim it down so it only returns the count and not download the attachments.
The variable of interest is "downloadCounter"
Provide the username, password, and feature layer id in the following lines:
import logging, os, re, datetime
from IPython.display import display
from arcgis.gis import GIS
''' ********************** SCRIPT CONFIGURATION START ********************** '''
#What is the ID of the Feature Layer you want to download attachments from?
FeatureLayerId = '092d075f4b3a40f78cf1329b20b0d5e7'
#What are your ArcGIS Enterprise/ArcGIS Online credentials? This is case sensitive.
PortalUserName = ''
PortalPassword = ''
PortalUrl = 'https://www.arcgis.com'
Hope that helps.
Derrick
Perfect thanks. I will give it a shot
Hi Joerodney ,
If you look at this blog post you will see that it is much easier to use Arcade for this purpose:
Visualize your attachments in ArcGIS Online with Arcade
(you will need to create a field in your hosted feature service to store the number of attachments, since the Attachments function is not available in the visualization profile)
Cheers, I wasn't aware of this Type System too.