1、画方面工具,工具名称“SelectByCircle”:
2、画圆面工具,工具名称“SelectByRect”:
3、画不规则图形面工具,工具名称“SelectByPolygon”:
其中将这几个控件的同一个属性“MapNetControl”的值都设置为所要操控的MapNet控件名上,即将这几个控件和所要控制的MapNet控件绑定。
在MapNet控件的“SelectByShape”事件中添加类似下面的代码:
1private void MapNet1_SelectByShape(StudioAT.IGeometry shape)
2 {
3 IMapNet mapNet = this.MapNet1;
4 ICollectionLayers myICL = mapNet.CollectionLayers;
5 IGetFeatures myIGF = null;
6 //根据图层读取数据到DataSet
7 ILayer myIL = myICL.FindById(this.DDL_LayerChoose.SelectedItem.Value);
8 ISpatialFilter myISF = new SpatialFilter(shape, ArcXML.enuSpatialFilterRelation.area_intersection);
9 ISpatialQuery2 myISQ2 = new SpatialQuery();
10 myISQ2.SpatialFilter = myISF;
11 DataSet myDs = myIL.Recordset(myISQ2,true, false,myIGF);
12 //更改列名
13 try
14 {
15 int GIS_IDindex = -1;
16 int IDindex = -1;
17 for (int k = 0; k < myDs.Tables[0].Columns.Count; k++)
18 {
19 switch (myDs.Tables[0].Columns[k].ColumnName)
20 {
21 case "#ID#":
22 myDs.Tables[0].Columns[k].ColumnName = "序号";
23 IDindex = k;
24 break;
25 case "EnvelopeXMin":
26 myDs.Tables[0].Columns[k].ColumnName = "最小经度";
27 break;
28 case "EnvelopeXMax":
29 myDs.Tables[0].Columns[k].ColumnName = "最大经度";
30 break;
31 case "EnvelopeYMin":
32 myDs.Tables[0].Columns[k].ColumnName = "最小纬度";
33 break;
34 case "EnvelopeYMax":
35 myDs.Tables[0].Columns[k].ColumnName = "最大纬度";
36 break;
37 case "NAME":
38 myDs.Tables[0].Columns[k].ColumnName = "名称";
39 break;
40 case "GIS_ID":
41 GIS_IDindex = k;
42 break;
43 case "REMARK":
44 myDs.Tables[0].Columns[k].ColumnName = "备注";
45 break;
46 default:
47 break;
48 }
49 }
50 //下面的Grid并非是.Net2003中自己的Grid而是第三方控件所提供的名称:UWG_Result
UWG_Result.DataSource = myDs;
51 UWG_Result.DataBind();
52 UWG_Result.Columns[GIS_IDindex].Hidden = true;
53 UWG_Result.Columns[IDindex].Hidden = true;
54 }
55 catch (Exception ex)
56 {
57 PageClass myPC = new PageClass();
58 myPC.Alert(ex.Message,this);
59 }
60 }
这样无论是画圆面、画方面还是画不规则图形面都会触发上述事件,从而能统计出在DropDownList控件中(上诉中有“DDL_LayerChoose”名称的为此控件)所选择的图层元素在所画的“shape”面中的个数以及每个元素的详细信息。2 {
3 IMapNet mapNet = this.MapNet1;
4 ICollectionLayers myICL = mapNet.CollectionLayers;
5 IGetFeatures myIGF = null;
6 //根据图层读取数据到DataSet
7 ILayer myIL = myICL.FindById(this.DDL_LayerChoose.SelectedItem.Value);
8 ISpatialFilter myISF = new SpatialFilter(shape, ArcXML.enuSpatialFilterRelation.area_intersection);
9 ISpatialQuery2 myISQ2 = new SpatialQuery();
10 myISQ2.SpatialFilter = myISF;
11 DataSet myDs = myIL.Recordset(myISQ2,true, false,myIGF);
12 //更改列名
13 try
14 {
15 int GIS_IDindex = -1;
16 int IDindex = -1;
17 for (int k = 0; k < myDs.Tables[0].Columns.Count; k++)
18 {
19 switch (myDs.Tables[0].Columns[k].ColumnName)
20 {
21 case "#ID#":
22 myDs.Tables[0].Columns[k].ColumnName = "序号";
23 IDindex = k;
24 break;
25 case "EnvelopeXMin":
26 myDs.Tables[0].Columns[k].ColumnName = "最小经度";
27 break;
28 case "EnvelopeXMax":
29 myDs.Tables[0].Columns[k].ColumnName = "最大经度";
30 break;
31 case "EnvelopeYMin":
32 myDs.Tables[0].Columns[k].ColumnName = "最小纬度";
33 break;
34 case "EnvelopeYMax":
35 myDs.Tables[0].Columns[k].ColumnName = "最大纬度";
36 break;
37 case "NAME":
38 myDs.Tables[0].Columns[k].ColumnName = "名称";
39 break;
40 case "GIS_ID":
41 GIS_IDindex = k;
42 break;
43 case "REMARK":
44 myDs.Tables[0].Columns[k].ColumnName = "备注";
45 break;
46 default:
47 break;
48 }
49 }
50 //下面的Grid并非是.Net2003中自己的Grid而是第三方控件所提供的名称:UWG_Result
UWG_Result.DataSource = myDs;
51 UWG_Result.DataBind();
52 UWG_Result.Columns[GIS_IDindex].Hidden = true;
53 UWG_Result.Columns[IDindex].Hidden = true;
54 }
55 catch (Exception ex)
56 {
57 PageClass myPC = new PageClass();
58 myPC.Alert(ex.Message,this);
59 }
60 }
不知道对大家是否有帮助,因为时间仓促这次的随笔就写到这里了,对上述代码还有什么独特见解的可以发表评论。