/// <summary> /// 追加數據 /// </summary> /// <param name="inputPath">源數據對象</param> /// <param name="targetPath">目標數據對象</param> public static void GPAppend(AppendFeature inputPath, IFeatureClass targetPath) { GeoPRocessor mGeoprocessor = new Geoprocessor(); mGeoprocessor.OverwriteOutput = true; Append mAppend = new Append(); mAppend.inputs = inputPath.FeatureClass; mAppend.target = targetPath; mAppend.schema_type = "NO_TEST"; //mAppend.field_mapping = GetFieldMapping(inputPath.FileFullPath); string mMessageGP = ""; mGeoprocessor.Execute(mAppend, null); for (int pMessageCount = 0; pMessageCount < mGeoprocessor.MessageCount; pMessageCount++) { mMessageGP += mGeoprocessor.GetMessage(pMessageCount); } } schema_type 在NO_Text情況下,追加后發現即使字段名相同也不能使屬性值導入。通過比較ArcMap下Append工具的應用發現,選擇NO_TEXT選項后,在Field_Mapping中自動出現對象關系。查找ArcEngine幫助文檔發現此選項接收類型為IGPFiledMapping集合,集合為源對象字段與目標對象字段的對應關系,經分析如果字段名稱一樣的情況下,只要匹配源對象字段就可以解決屬性值不能導入的問題。解決屬性字段不能導入問題
public static IGPFieldMapping GetFieldMapping(string ExInputPath) { IGPUtilities mGPUtilities = new GPUtilitiesClass(); IDETable mDETable = (IDETable)mGPUtilities.MakeDataElement(ExInputPath, null, null); IArray mArray = new ArrayClass(); mArray.Add(mDETable); IGPFieldMapping mGPFieldMapping = new GPFieldMappingClass(); mGPFieldMapping.Initialize(mArray, null); //create new fieldmap IGPFieldMap mGPFieldMap = new GPFieldMapClass(); //mGPFieldMap.OutputField = mFC1.Fields.get_Field(1); //match field int fieldmap_index = mGPFieldMapping.FindFieldMap("BSM"); IGPFieldMap mGPFNew = mGPFieldMapping.GetFieldMap(fieldmap_index); int field_index = mGPFNew.FindInputField(mDETable, "BSM"); IField mField = mGPFNew.GetField(field_index); mGPFieldMap.AddInputField(mDETable, mField, -1, -1); mGPFieldMapping.AddFieldMap(mGPFieldMap); return mGPFieldMapping; } 其中GPUtilities類獲取表集合IDETable,IDETable猜測為源對象表,沒有經過嚴格測試,只是IDETable作為源對象表可以解決產生的問題。IGPFieldMapping類是對應關系集合。IGPFieldMap對應關系,需要匹配輸入字段與輸出字段,匹配后添加到IGPFieldMapping。
新聞熱點
疑難解答