Writing ArcGIS Geodatabase Attachments

Liz Sanderson
Liz Sanderson

FME Version

Introduction

Geodatabase attachments are a way to connect additional information to features in the form of a specific file (i.e. an image, a PDF, or a text document). As the ArcGIS documentation mentions:

“For example, if you have a feature representing a building, you could use attachments to add multiple photographs of the building taken from several angles, along with PDF files containing the building's deed and tax information.”

You can attach one or more files to a feature and then retrieve the information using query tools in ArcGIS.

 

Requirements

The Esri Geodatabase (File Geodb) reader/writer used in the following example requires that a licensed version of ArcGIS be available to the user. For more information on required ArcGIS license levels, please see Required ArcGIS License Types for FME Geodatabase Formats.

 

Video

The above video covers the theory that is covered in Introduction to Working with Geodatabase Relationship Classes, and the example covered in this article.

 

Attachments and FME

Because attachments are handled by a relationship class, FME is capable of easily creating this sort of connection. However, both the relationship class and attachments table must be created in ArcGIS beforehand. The key is to read the contents of the file to be attached into an attribute and write that attribute to a DATA field in the attachments table.
An AttributeFileReader transformer or the Data File reader can be used to read the contents of a file into an attribute. In the case of the Data File reader, be sure to set the reader parameter “Read Whole File at Once” to Yes.
The exercise to follow will demonstrate how to write to a relationship class while adding attachments.

 

Source Data

Fire Hall, Community Centre, and Library (GML)

sourcedata.png


PDFs & Photos (System File Paths)

pathdata.png

 

Step-by-step Instructions

1. Open Template Workspace
Open the attached WritingGeodatabaseAttachments_Begin.fmwt workspace in FME Workbench. You can download this workspace from the Files section of this article. This workspace reads in three points of interest from a GML file, as well as reads in a path to photos which we will later attach. In addition, some of the attributes have been modified to match the destination schema using AttributeManagers. This workspace also has the geodatabase writer set up, the schema for this geodatabase came from the ATTACHMENTSTEMPLATE.xml file. For more information on using templates, see the How to use an Esri Template Geodatabase article. 
TemplateWorkspace.png
2. Add Relationship Related Attributes
FME needs to be told that the features participate in a relationship class. To do this, we will use an AttributeCreator transformer. Add an AttributeCreator to the canvas and connect it to all three AttributeManagers. 
GMLAttributeCreator.png

In the parameters create a New Attribute called geodb_feature_has_relationships then set the Value to yes. 
AttributeCreator_!.png

Now we need to create our geodb_oid (Feature ID). Add a Counter to the canvas and connect it to the AttributeCreator. In the parameters, set the Count Start to 1, then expand the Advanced section and set the Count Scope to Local. Now change the Output Attribute Name Count to geodb_oid, and click OK. 
Counter.png

We will need to create the same relationship attributes for our PATH reader feature type. Highlight both the AttributeCreator and the Counter, then duplicate them (ctrl-d (cmd-d) and connect the AttributeCreator_2 to the PATH reader feature type. 
PathRelationships.png

3. Rename fme_feature_type and Create a GUID
Before we can write the GML Points of Interest out to a geodatabase, we need to rename the fme_feature_type as well as create A GUID. 
Add an AttributeRenamer to the canvas and connect it to the Counter that is connected to the GML reader feature types. In the parameters,  set the Input Attribute to  fme_feature_type and the Output Attribute to POIType, then click OK. 
AttributeRenamer_POIType.png

Now we need to create an Esri GUID (globally unique identifier, to do this we will add the GUIDGenerator custom transformer. Connect it to the AttributeRenamer. There are no parameters to set. 
 
4. Connect to the PointsOfInterest Writer Feature Type
Our GML points of interest workflow are now ready to be written out to the geodatabase. Connect the GUIDGenerator to the PointsOfInterest writer feature type. Expand the PointsOfInterest writer feature type and ensure all of the attributes are mapped. You may have to manually map GUID/GFID
GUIDConnection.png

Note, since the GUIDGenerator is a custom transformer from the FME Hub, its output attribute may change. As of FME 2021.1, the output attribute is now GFID. It may change in the future, update the writer feature type parameters to reflect this change. 
 
5. Add Relationship Related Attributes
We now need to define the relationship between the two sets of features, and we do this by creating origin and destination ID numbers. First, let’s create the origin ID. Add an AttributeRenamer to the canvas and connect it to the Counter coming from the GML reader feature types. In the Parameters, set the Input Attribute to geodb_oid and the Output Attribute to geodb_rel_origin_oid, and click OK.  
OriginAttributeCreator.png

Now duplicate the AttributeRenamer we just made, and connect it to the Counter_2, which is coming from the PATH reader feature type. In the parameters, change origin to destination, so that the Output Attribute is geodb_rel_destination_oid, then click OK. 
DestinationAttributerenamer.png
RelationshipWorkspace.png

6. Build Relationship Information

Add a FeatureMerger transformer. This is how the relationship will be built. Connect the Origin AttributeRenamer_2 to the Requestor port and the Destination AttributeRenamer_3 to the Supplier. In the Parameters,  set the Requestor attribute to Name and the Supplier attribute to path_rootname.
The other outstanding issue to take care of is the case where there are multiple attachments for a particular point of interest. So, while still in the FeatureMerger parameters dialog, enable Process Duplicate Suppliers, then enable Generate List. Set the List Name to Docs and select geodb_rel_destination_oid and path_filename, click OK. 
FeatureMerger.png

The result of this is that data gets merged where the filename (path_rootname) of the attachment matches the name of the Point of Interest feature (Name).
For example, if I have a point of interest called “Big Tall Statue” (Origin ID = 13) and there is a file named “Big Tall Statue.jpg” (Destination ID = 22) then the result will be a single feature (“Big Tall Statue”, Origin ID = 13, Destination ID = 22) that defines a relationship between those features. When writing this to the Relationship Class, it will define the relationship between these features in the PointsOfInterest and PointsOfInterest_ATTACH tables.
 
7. Explode Docs List
Now when the workspace is run, for features with multiple attachments, multiple files are stored in a list, like so:

  • Docs{0}.path_filename
  • Docs{0}.geodb_rel_destination_oid
  • Docs{1}.path_filename
  • Docs{1}.geodb_rel_destination_oid

What we now need to do is explode the Docs list into individual features – so that there is a relationship record for each attachment – and this is done with a ListExploder transformer. Add a ListExploder to the canvas and connect it to the Merged output port on the FeatureMerger. In the parameters, set the List Attribute to Docs, then click OK. 
ListExploder.png

8. Create Relationship Type
Each feature that gets sent to an FME writer should have an attribute indicating the geometry type. In most cases you – the user – never need to know about this attribute and don’t need to set it. However, here these features will be currently flagged as point features (i.e. points of interest) and we need to tell FME they are actually non-geometry, relationship features. So, add an AttributeCreator and connect it to the ListExploder. In the parameters, create a New Attribute called geodb_type and give it a Value of geodb_relationship. 
RelationshipAttributeCreator.png

Now you can connect the AttributeCreator_3 to the PointsOfInterest_ATTACHREL writer feature type. 
RelationshipWriterWorkflow.png

9. Setup the fields in the Attachment Table
At the moment we’re writing a relationship between features, but the destination features (attachments) are currently just a reference to a file, not the file itself. We need to use these references to read the attachment file contents. 
First, we need to do some basic schema mapping. Add an AttributeCopier to the canvas and connect it to the Counter_2 coming from the PATH reader feature type. In the parameters, set the following: 

Input Attribute Output Attribute
geodb_oid REL_OBJECTID
path_filename ATT_NAME
path_filesize DATA_SIZE
path_extension CONTENT_TYPE


AttributeCopier.png

Now we need to create an attribute to tell ArcGIS about the type of file being attached. Add a StringConcatenator to the canvas and connect it to the AttributeCopier. In the parameters, set the New Attribute to CONTENT_TYPE, then set the following for the String Parts:

String Type String Value
Constant image/p.
Attribute Value path_extension


StringConcatenator.png

Finally, we need to read in the contents of the attachments. Add an AttributeFileReader to the canvas and connect it to the StringConcatenator. In the parameters, set the Destination Attribute to DATA and the Source File Name to path_windows, then click OK. 

AttributeFileReader.png

Now we can connect to the final writer feature type. Connect the AttributeFileReader to the PointOfInterest_ATTACH writer feature type. 
AttachmentWorkflow.png

10. Write Relationship Data & Attachments
Save and run the workspace. View your output in ArcGIS to confirm that the attachments have been added. To view the attachments from within the map, you will need to download the attachments and then use the HTML Popup Tool, see the documentation for more information. 

ArcOutput.png


Data Attribution

The data used here originates from data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.
 

Was this article helpful?

Comments

1 comment

  • Comment author
    Josh Cole

    Hi Liz, Your model is great!  Thank you so much for this detailed workflow.  I see you have a path pointing to a file location on your computer to retrieve the attachments. I need to set this up by reading an AGOl  Hosted Feature Layer that keeps a form and attachments in ArcGIS Field Maps and writes to an SDE DB.  How do I get the attachments from AGOl? 

    0

Please sign in to leave a comment.