private void 处理面积ToolStripMenuItem_Click(object sender, EventArgs e)
{
pLayer = axMapControl2.get_Layer(0);
pFLayer = pLayer as IFeatureLayer;
pFC = pFLayer.FeatureClass;
IFeatureCursor pFCursor = pFC.Search(null, false);
IFeature pFeature = pFCursor.NextFeature();
//创建表,获得要素ID,标识码,面积,用于筛选相同表示码,面积较小的要素
DataTable pTable = new DataTable();
DataColumn colID = new DataColumn("要素ID");
colID.DataType = System.Type.GetType("System.String");
pTable.Columns.Add(colID);
DataColumn colIdent = new DataColumn("标识码");
colIdent.DataType = System.Type.GetType("System.String");
pTable.Columns.Add(colIdent);
DataColumn colArea = new DataColumn("面积");
colArea.DataType = System.Type.GetType("System.Double");
pTable.Columns.Add(colArea);
int indexOfFID_HBTC_Z = pFC.FindField("FID_HBTC_Z");
int indexOfBSM = pFC.FindField("BSM");
int indexOfTBMJ = pFC.FindField("TBMJ");
while (pFeature != null)
{
string FID_HBTC_Z = pFeature.get_Value(indexOfFID_HBTC_Z).ToString();
string BSM = pFeature.get_Value(indexOfBSM).ToString();
double TBMJ = (double)pFeature.get_Value(indexOfTBMJ);
DataRow pRow = pTable.NewRow();
pRow[0] = FID_HBTC_Z;
pRow[1] = BSM;
pRow[2] = TBMJ;
pTable.Rows.Add(pRow);
pFeature = pFCursor.NextFeature();
}
//从表中获得同一标识码的列表,并删除与当前标识码面积小的要素
for (int i = 0; i < pTable.Rows.Count; i++)
{
string bsm1 = pTable.Rows[i][1].ToString();
double TBMJ1 = (double)pTable.Rows[i][2];
for (int x = 0; x < pTable.Rows.Count; x++)
{
string FID_HBTC_Z2 = pTable.Rows[x][0].ToString();
string bsm2 = pTable.Rows[x][1].ToString();
double TBMJ2 = (double)pTable.Rows[x][2];
if (bsm1 == bsm2)
{
if (TBMJ1 > TBMJ2)
{
deleteFeature(FID_HBTC_Z2);
}
}
}
}
//dataGridView1.DataSource = pTable;
}
private void deleteFeature(string FID_HBTC_Z)
{
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "FID_HBTC_Z=" + FID_HBTC_Z;
IFeatureCursor updateCursor = pFC.Update(queryFilter, true);
IFeature feature1 = updateCursor.NextFeature();
while (feature1 != null)
{
updateCursor.DeleteFeature();
feature1 = updateCursor.NextFeature();
}
updateCursor.Flush();
//TokayWorkspace.ComRelease(del_featcur);
//updateCursor = null;
axMapControl2.ActiveView.Refresh();
}