About mapping fields
A common geoprocessing task is to merge many datasets into a new or existing dataset to create a single dataset that covers a larger area or a table that contains a greater number of records. Often, the attributes or fields are the same for all the inputs that are used in a merge or append operation, but sometimes they do not match and the relationships between fields of different names and types have to be mapped. The Merge tool in the Data Management toolbox facilitates this mapping of relationships so data is placed in the desired output fields with the correct values.
IGPFieldMap
The IGPFieldMap object provides a field definition and a list of input fields from a set of tables or feature classes that provide its values. The IGPFieldMapping object is a collection of IGPFieldMap objects and is used as the parameter value for tools that perform field mapping—such as Merge, Append, Feature Class To Feature Class, and Table To Table. The easiest way to work with these objects is to create an IGPFieldMapping object, then initialize its IGPFieldMap objects by adding the input feature classes or tables that are to be combined. Once all inputs are provided, the IGPFieldMapping object will contain one IGPFieldMap object or output field for each unique field name from all the inputs. This list can be modified by adding new fields, altering the properties and/or contents of an output field, or removing any unwanted output fields.
The properties of the IGPFieldMap object include the start and end position of an input text value, so a new output value can be created using a slice of an input value. If an IGPFieldMap object contains multiple input fields from the same table or feature class, the values in each record will be merged using the MergeRule property. This is a convenient way to join values, for example, a street name that is held in one field and a street type that is held in another, such as, Eureka and Street. The Delimiter property of IGPFieldMap is used if the MergeRule Join value is specified. Any set of characters, such as a space, can be used as a delimiter. In this case, this creates a value of Eureka Street.
Input table attribute
In the following example, a table containing U.S. census data is converted to a new table. One of the input attributes found in the input table is the STFID text field. This 15-digit value is a unique identifier for all census blocks for the United States. The value can be broken into the following components:
- The first two digits provide the state code
- The next three digits indicate the county code
- The next six digits identify the census tract
- The last four digits identify the census block
See the following illustration:
![Illustration showing an example of 15-digit unique identifier for census blocks.](./bitmaps/bc887fd0-b46b-4877-92c0-3c5b82f840671.png)
In this illustration, the value of 360899912001006 represents census block 1006, which contains the State University of New York at Potsdam in upstate New York with the state code of 36, in census tract 991200 in the county of St. Lawrence with the county code of 089. This sample converts this table and also creates a new TRACTID field because the input data only has the STFID attribute.
To do this, the GPFieldMapping object is initialized using the AddTable method to enter the input table. Then the default IGPFieldMapping object is modified by creating a new IGPFieldMap object, populating its properties, then adding them to the IGPFieldMapping object.
See Also:
Sample: Geoprocessing field mappingUsing the field mapping control