In this topic
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.
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 it is used as the parameter value for tools that perform field mapping, such as Merge, Append, FeatureClass To FeatureClass, and Table To Table.
The easiest way to work with these objects is to create a IGPFieldMapping object, then initialize its IGFieldMap 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 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 a 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, for example, 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 the previous example, this creates a value of Eureka Street.
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 Federal Information Processing Standard (FIPS) text field. This 11-digit value is a unique identifier for all census tracts for the United States. The value can be broken into three components:
- The first two digits provide the state code
- The next three digits indicate the county code
- The last six digits identify the census tract
See the following illustration:
In the previous illustration, the value 36089991200 represents census tract 991200, which contains the State University of New York at Potsdam in upstate New York with the state code of 36, 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 FIPS 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.