Files
Introduction
Geodatabase attachments are a way to associate additional information with features as a specific file (e.g., 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 Comparison of Esri-Based Readers and Writers in FME.
Video
The above video covers the theory presented 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 can easily create this type 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 to 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)
PDFs & Photos (System File Paths)
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 and 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 geodatabase schema was derived from the ATTACHMENTSTEMPLATE.xml file. For more information on using templates, see the How to use an Esri Template Geodatabase article.
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.
In the parameters, create a New Attribute called geodb_feature_has_relationships, then set the Value to yes.
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.
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.
3. Rename fme_feature_type and Create a GUID
Before we can write the GML Points of Interest to a geodatabase, we need to rename the fme_feature_type and 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.
Now we need to create an Esri GUID (globally unique identifier). To do this, we will add the GUIDGenerator custom transformer and 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 is now ready to be written 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 the GUID/GFID
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.
Now duplicate the AttributeRenamer we just made and connect it to the Counter_2, which comes 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.
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 is multiple attachments for a single 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, select geodb_rel_destination_oid and path_filename, and click OK.
The result is that data is merged when the attachment filename (path_rootname) 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 – using 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.
8. Create Relationship Type
Each feature sent to an FME writer should include an attribute indicating the geometry type. In most cases, you – the user – never need to know about this attribute or set it. However, here, these features will currently be flagged as point features (i.e., points of interest), and we need to tell FME that 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 set its value to geodb_relationship.
Now you can connect the AttributeCreator_3 to the PointsOfInterest_ATTACHREL writer feature type.
9. Set up the Fields in the Attachment Table
At the moment, we’re writing a relationship between features, but the destination features (attachments) are currently just references to files, not the files themselves. We need to use these references to read the contents of the attachment file.
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: geodb_oid
- Output Attribute: REL_OBJECTID
-
Input Attribute: path_filename
- Output Attribute: ATT_NAME
-
Input Attribute: path_filesize
- Output Attribute: DATA_SIZE
-
Input Attribute: path_extension
- Output Attribute: CONTENT_TYPE
Click OK
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: Constant
- String Value: image/p.
-
String Type: Attribute Value
- String Value: path_extension
Click OK.
Finally, we need to read 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.
Now we can connect to the final writer feature type. Connect the AttributeFileReader to the PointOfInterest_ATTACH writer feature type.
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 attachments within the map, download them and then use the HTML Popup Tool. See the documentation for more information.
Data Attribution
The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.