I have managed to merge all the layers (with the same table attributes) into one single shapefile. However, the table structure is not the same as the original. For instance, my layers in the map control have fields named "Contact", "Address", "Location", "Phone" and the merged shapefile has a table with fields: "field_1", "field_2", "field_3", etcWorse, there isn't even any data in any of the fields...What am I doing wrong?
ITable inputTable = null;
// Create a feature class name for the output shapefile and open the output's workspace
IWorkspaceName pWorkspaceName = new WorkspaceNameClass();
pWorkspaceName.WorkspaceFactoryProgID = "esriCore.ShapeFileWorkspaceFactory.1";
pWorkspaceName.PathName = @"C:\Temp";
// define the temp output featureclass name
IFeatureClassName pFeatClassName = new FeatureClassNameClass();
pFeatClassName.FeatureType = esriFeatureType.esriFTSimple;
pFeatClassName.ShapeFieldName = "Shape";
pFeatClassName.ShapeType = esriGeometryType.esriGeometryPolygon;
IDatasetName pDatasetName = (IDatasetName)pFeatClassName;
pDatasetName.Name = "Merge_Result";
pDatasetName.WorkspaceName = pWorkspaceName;
IArray featArray = new ArrayClass();
ILayer pLayer;
for (int i = 0; i < axMapControl1.LayerCount; i++)
{
pLayer = (ILayer)axMapControl1.get_Layer(i);
inputTable = (ITable)pLayer;
featArray.Add(inputTable);
}
// perform the merge
IBasicGeoprocessor pBGP = new BasicGeoprocessorClass();
try
{
IFeatureClass pOutFeatureClass = pBGP.Merge(featArray, inputTable, pFeatClassName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}