ArcGIS Online

Visualize your attachments in ArcGIS Online with Arcade

Like any other piece of information, your attachments play a key role in providing context and understanding when you or others explore your data.  Up until now, that additional understanding has been focused around viewing your attachments when browsing your data. But what if you could do a little bit more, and ask a few additional questions about what’s really going on with those attachments? Questions like:

Answering these questions is now a bit easier in ArcGIS Online, thanks to Arcade and Field Calculate. The latest release of ArcGIS Online gives you the ability to work with information related to a feature’s attachments.  By using the Attachment() function, you can gain access to various attachment properties, allowing you to calculate new field values based on those properties.

 

Get the number of attachments

Getting the total number of attachments per feature comes in handy when trying to identify what assets might be missing visual information, such as photos to support asset condition surveys.  The fastest way to get this information is to chain the new Attachments() function with the Count() function.


//returns the number of attachments per feature
Count(Attachments($feature))

Because you are calculating this information to a field, you can than render your map or filter your features based on the new value. This lets you do something that resembles the map below.

Identify features with attachments based on a condition

After getting the number of attachments, you can build in more complexity as required.  For example, what if you only wanted to identify features that have 0 attachments AND have a status of Inspected.  Your expression might look something like this:


// Is status = Inspected, and does the feature have attachments
If ($feature.status == 'Inspected')  {
  If(Count(Attachments($feature)) > 0) {
      // if count is greater than zero there are attachments
      return 'Inspection Complete'
  } else {
      // otherwise the feature has been inspected but missing photos
      return 'Incomplete inspection (photos are missing)'
  }
  
} else {
  return 'Not Applicable'
}

Find a specific file within your feature’s attachments

With this new information, you can send your field crew back out with a focused objective to collect photos for the missing assets.

You can also dive in and get information about one or more specific attachments by accessing the properties of the Attachment data type. That additional information might be useful if you’re trying to understand something like your attachments and their size or type. Maybe you’re interested in finding a specific attachment by a well-known file name.  Diving deeper could let you quickly audit your buildings/properties and make sure they all have an as-built plan attached to them based on your organization’s naming conventions.

That would look roughly like:


var attachmentOptions = {"types":["application/pdf"]}
var pdfAttachments = Attachments($feature,attachmentOptions)
var hasAsBuilt = 0 

// Make sure there are attachments before trying to get the properties
If (!isEmpty(pdfAttachments)) {
    for (var a in pdfAttachments) {
            //look for the specific file name
            if (pdfAttachments[a].name == 'As Built.pdf') {
                hasAsBuilt = 1                
            }        
    }       
} 

// Check the value and return a human readable string
If (hasAsBuilt == 1) { 
    return "Site has as-built plans"
} else {
    return "Site is missing as-built plans"
}

It’s important to remember that like most things in Arcade, you are responsible for checking for nulls. Without checking for no attachments in this scenario, you will end up with errors (on features with no attachments) evaluating the expression.

 

Parting thoughts

I hope the examples above are enough to get you thinking about how you can use the new Attachments() function to do more with your data. I’ll leave you with a couple of reminders before you dive in:

Stay tuned for future releases as we continue to optimize performance with field calculate and Arcade, and be sure to head over to the Arcade documentation to learn more.

About the author

Product Engineer for ArcGIS Online and technology enthusiast.

Next Article

Pro Map Text IV: Layout Text

Read this article