⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buffertool.cs

📁 地理信息系统的二次开发,空间查询代码 CSharp and ArcGIS engine 地理信息开发包
💻 CS
📖 第 1 页 / 共 2 页
字号:

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show("用户设置的淹没距离是:" + textBox1.Text);
		}

		private void button2_Click(object sender, System.EventArgs e)
		{

		        label1.Text="各缓冲区融合总面积为:";
				//IMxDocument pmxdoc;
				IArea parea,qarea;
				//IActiveView pactiveview;
				IGraphicsContainer pgraphicscontainer;
				IEnumFeature penumfeature;
				
				ITopologicalOperator ptopoop;
				ITopologicalOperator Stopoop;
				IElement pelement;
				

				string dis ;
				double Sarea=0;

				//pmxdoc=axPageLayoutControl1.DocumentFilename;
				//pactiveview=(IActiveView)axMapControl1.ActiveView.FocusMap;
				//pactiveview =(ESRI.ArcGIS.Carto.IActiveView)pmxdoc.FocusMap;
				pgraphicscontainer = new MapClass();
				//pgraphicscontainer=(ESRI.ArcGIS.Carto.IGraphicsContainer)pmxdoc.FocusMap;
				pgraphicscontainer=pactiveview.FocusMap as IGraphicsContainer;
				if(pactiveview.FocusMap.SelectionCount==0)
				{
					MessageBox.Show("请选择要素!","");
					return;
				}
				dis=textBox1.Text.Trim();

				if ((dis=="")||!BaseCompareValidator.CanConvert(dis,ValidationDataType.Double))
				{
					MessageBox.Show("请正确输入距离!","");
					return;		
				}	
				if (dis=="0")	
				{
					label1.Text="各缓冲区融合总面积为:0";
					return;
				}
		
				//penumfeature = (ESRI.ArcGIS.Geodatabase.IEnumFeature)(pmxdoc.FocusMap.FeatureSelection);
				//penumfeature = new EnumFeatureGeometryClass();
				penumfeature =pactiveview.FocusMap.FeatureSelection as IEnumFeature;
				penumfeature.Reset();
				pfeature=penumfeature.Next();
				int i=0;
				double dFeatureArea=0;
				Sgeometry = new PolygonClass();
			
		
				while(!(pfeature==null))
				{	
					if(pfeature.Shape.GeometryType==esriGeometryType.esriGeometryPolygon || pfeature.Shape.GeometryType==esriGeometryType.esriGeometryPolyline)
					{
						ptopoop = pfeature.Shape as ITopologicalOperator;
						ptopoop.Simplify();
						pelement = new PolygonElementClass();
						pelement.Geometry = ptopoop.Buffer(double.Parse(dis));
						pgraphicscontainer.AddElement(pelement,0);
						pgeometry = new PolygonClass();
						pgeometry=pelement.Geometry;
				
				
						if(i==0)
							Sgeometry = pgeometry;
						else
						{
							Stopoop = Sgeometry as ITopologicalOperator; 
							Stopoop.Simplify();
							Sgeometry=Stopoop.Union(pgeometry);
						}
				
						i++;

			  	    //求出多边形原来的面积
						try
						{
							if(pfeature.Shape.GeometryType==esriGeometryType.esriGeometryPolygon)
							{	
								parea =(IArea)pfeature.Shape;
								dFeatureArea+=parea.Area;
								qarea = (IArea)pgeometry;
								Sarea+=(qarea.Area-parea.Area);		
							}
							else
							{
								qarea = (IArea)pgeometry;
								Sarea+=qarea.Area;
							}
					
						}
						catch( System.NullReferenceException xx)
						{
							MessageBox.Show(xx.ToString(),"");
						}
						catch(System.InvalidCastException yy)
						{
							MessageBox.Show(yy.ToString(),"");
						}
					}
					pfeature = penumfeature.Next();
				}	
				//label6.Text="各块缓冲区面积之和为:"+Sarea.ToString();
			    
				qarea=(IArea)Sgeometry;
				label1.Text="各缓冲区融合总面积为:"+(qarea.Area-dFeatureArea).ToString(".00") + "平方" + GetMapUnits();
				pactiveview.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics,null,null);
			this.cmdBufferAnalysis.Enabled=true;
			this.button3.Enabled=true;
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			pactiveview.GraphicsContainer.Reset();
			IElement pElement;
			pElement = pactiveview.GraphicsContainer.Next();
			while(!(pElement==null))
			{	
				if(pElement.Geometry.GeometryType==esriGeometryType.esriGeometryPolygon)
				{
					pactiveview.GraphicsContainer.DeleteElement(pElement);
				}
				pElement = pactiveview.GraphicsContainer.Next();
			}
			//pactiveview.FocusMap.ClearSelection();
			pactiveview.Refresh();
			textBox1.Clear();
			label1.Text="各缓冲区融合总面积为:0";
			label3.Text="总共有    个地物落在缓冲区里";
			listView1.Items.Clear();
			this.cmdBufferAnalysis.Enabled=false;
		}
		private void SpatialQuery(IGeometry pGeom)
		{  
			IMap m_Map=pactiveview.FocusMap; 
			ISpatialFilter  pSpatialFilter=new SpatialFilterClass();
			pSpatialFilter.Geometry=pGeom;		
			pSpatialFilter.SpatialRel=esriSpatialRelEnum .esriSpatialRelContains;
					
			iPoints=0;
			iPolylines=0;
			iPolygons=0;
			//循环与地图上的图层比较
			for(int i = 0 ;i <m_Map.LayerCount;i ++)
			{
				ILayer pLayer=m_Map.get_Layer(i);
			
				IFeatureLayer pFeatureLayer;
				pFeatureLayer=(IFeatureLayer)pLayer;
				if(pFeatureLayer==null) return;
				IFeatureClass pFeatC=pFeatureLayer.FeatureClass;
				string sLayerName=null;
				pSpatialFilter.GeometryField=pFeatC.ShapeFieldName;
				IFeatureCursor pFeatureCursor;
				pFeatureCursor=pFeatC.Search(pSpatialFilter,false);
				IFeature pFeature1=pFeatureCursor.NextFeature();
				int iFeatPoint=0;  //如果有地物被包括在缓冲区里面,则这三个变量中的一个将
				int iFeatPolyline=0; //会被赋值为1,则就可以将查询结果填入listview中
				int iFeatPolygon=0;
				while (pFeature1!=null)
				{  
						IFeatureSelection m_FeatureSelection = (IFeatureSelection) pFeatureLayer;
						m_FeatureSelection.Add(pFeature1);
						Flash.FlashFeature(pactiveview.ScreenDisplay,pFeature1);
						IGeometry pFeatGeom=pFeature1.Shape;
						esriGeometryType GemoTyp;
						GemoTyp=pFeatGeom.GeometryType;
						switch(GemoTyp)
						{
							case esriGeometryType.esriGeometryPoint:
								iFeatPoint=1;
								iPoints ++;
								break;
							case esriGeometryType.esriGeometryPolyline:
								iFeatPolyline=1;
								iPolylines ++;
								break;
							case esriGeometryType.esriGeometryPolygon:
								iFeatPolygon=1;
								iPolygons ++;
								break;
						}
						iTotal=iPoints + iPolylines + iPolygons;
						sLayerName=pFeature1.Class.AliasName;	
		
						string[] str = new string[3] ;
						ListViewItem li;
						//将查找出来的地物分布填入listview里
						if(iFeatPoint==1||iFeatPolyline==1||iFeatPolygon==1)  
						{
							str[0]=sLayerName;
							if(pFeature1.Fields.FieldCount>3)
							{    
								str[1]=pFeature1.Fields.get_Field(2).Name.ToString();
								str[2]=pFeature1.get_Value(2).ToString();
							}
							else 
							{
								str[1]=pFeature1.Fields.get_Field(0).Name.ToString();
								str[2]=pFeature1.get_Value(0).ToString();
							}
							li = new ListViewItem(str);
							this.listView1.Items.Add(li);
						}
						iFeatPoint=0;
						iFeatPolyline=0;
						iFeatPolygon=0;

						pFeature1=pFeatureCursor.NextFeature();
					}
				
				
			
				pactiveview.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,null,null);
			}						
		}

		private void cmdBufferAnalysis_Click(object sender, System.EventArgs e)
		{
		   SpatialQuery(Sgeometry);
			label3.Text="总共有" + iTotal.ToString() + "个地物落在缓冲区里,具体如下:";
		}
		private string GetMapUnits()
		{
			esriUnits mapUnits = pMapControl.MapUnits;
             string sMapUnits="米";
			switch (mapUnits)
			{
				case esriUnits.esriCentimeters:
					sMapUnits = "厘米";
					break;
				
				case esriUnits.esriDecimeters:
					sMapUnits = "分米";
					break;
				case esriUnits.esriFeet:
					sMapUnits = "英尺";
					break;
				
				case esriUnits.esriKilometers:
					sMapUnits = "千米";
					break;
				case esriUnits.esriMeters:
					sMapUnits = "米";
					break;
				case esriUnits.esriMiles:
					sMapUnits = "Miles";
					break;
				case esriUnits.esriMillimeters:
					sMapUnits = "毫米";
					break;
				case esriUnits.esriNauticalMiles:
					sMapUnits = "海里";
					break;
				case esriUnits.esriPoints:
					sMapUnits = "点";
					break;
				case esriUnits.esriUnknownUnits:
					sMapUnits = "未知";
					break;
				case esriUnits.esriYards:
					sMapUnits = "码";
					break;
			}
			return sMapUnits;
			
		}

		private void BufferAnalysisFrm_Load(object sender, System.EventArgs e)
		{
			label4.Text=GetMapUnits();
		}

		

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -