private void confirmCategory() { string[] shp = new string[2]; shp[0] = System.IO.Path.GetDirectoryName(shpPathText.Text); shp[1] = System.IO.Path.GetFileName(shpPathText.Text); if (shp[0] == null) { return; } IFeatureClass pFC = mg.openShapefile(shp[0], shp[1]); IFeatureCursor pFeatureCur = pFC.Search(null, false); IFeature pFeature = pFeatureCur.NextFeature(); Hashtable i = mg.Index(pFC); readExcel t = new readExcel(); t.OpenExcel(excelText.Text); List <TrashInfo> trashItems = t.readTrashTables(); t.closeExcel(); IQueryFilter tQueryFilter = new QueryFilterClass(); tQueryFilter.WhereClause = ""; tQueryFilter.AddField(pFC.OIDFieldName); //Invoke(new MethodInvoker(() => //{ // proWork.Maximum = pFC.FeatureCount(tQueryFilter); // proWork.Value = 0; //})); //int number = 1; while (pFeature != null) { ResultItem value = new ResultItem(); value = mg.getFields(i, pFeature); #region 查找与excel中匹配的数据 TrashInfo right = trashItems.Find( delegate(TrashInfo T) { return(T.Figure == value.Figure); }); pFeature.set_Value((int)i["垃圾类别"], right.Category); //如果垃圾类别没设置,则取消注释 pFeature.Store(); #endregion //Invoke(new MethodInvoker(() => //{ // proWork.Value = number++; //})); pFeature = pFeatureCur.NextFeature(); } }
private void getAllshp(string shpName) { string[] shp = new string[2]; shp[0] = System.IO.Path.GetDirectoryName(shpName); shp[1] = System.IO.Path.GetFileName(shpName); if (shp[0] == null) { MessageBox.Show("文件路径问题!"); } IFeatureClass pFC = mg.openShapefile(shp[0], shp[1]); IFeatureCursor pFeatureCur = pFC.Search(null, false); IFeature pFeature = pFeatureCur.NextFeature(); Hashtable i = mg.Index(pFC); while (pFeature != null) { ResultItem value = new ResultItem(); value = mg.getFields(i, pFeature); allValue.Add(value); pFeature = pFeatureCur.NextFeature(); } allValue.Sort(delegate(ResultItem p1, ResultItem p2) { return(p1.Figure.CompareTo(p2.Figure)); }); }