Exemplo n.º 1
0
        private void btnGO_Click(object sender, System.EventArgs e)
        {
            IFeatureClass pFClass = null;          //获得输入特征数据类

            IWorkspace pWorkspace;
            object     Missing = Type.Missing;
            string     fileName;
            string     rasterPath;
            string     shpFile;
            int        startX, endX;
            string     sFieldName;        //选择要进行分析的字段

            if (bDataPath == true)
            {
                fileName = comboBoxInData.Text;
                string shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX  = fileName.LastIndexOf("\\");
                endX    = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
                pFClass = Utility.OpenFeatureClassFromShapefile(shpDir, shpFile);
            }
            else
            {
                pFClass = GetFeatureFromMapLyr(comboBoxInData.Text);
            }
            IFeatureLayer pFeatLayer = new FeatureLayerClass();

            pFeatLayer.FeatureClass = pFClass;
            rasterPath = txtRasterPath.Text;
            IFeatureClassDescriptor pFeatClsDes = new FeatureClassDescriptorClass();

            if (comboBoxField.Text != "无")
            {
                pFeatClsDes.Create(pFClass, null, comboBoxField.Text);
            }
            else
            {
                pFeatClsDes.Create(pFClass, null, "");
            }
            try
            {
                IDensityOp pDensityOp = new RasterDensityOpClass();
                string     sCellSize  = txtCellSize.Text;
                double     dCellSize  = Convert.ToDouble(sCellSize);
                string     sRadius    = txtSearchRadius.Text;
                double     dRadius    = Convert.ToDouble(sRadius);
                object     objRadius  = dRadius;
                pDensityOp = Utility.SetRasterDensityAnalysisEnv(rasterPath, dCellSize, pFeatLayer);
                IRasterNeighborhood pRasNeighborhood = new RasterNeighborhoodClass();
                if (comboBoxAreaUnit.Text == "按地图单位")
                {
                    pRasNeighborhood.SetCircle(dRadius, esriGeoAnalysisUnitsEnum.esriUnitsMap);
                }
                else
                {
                    pRasNeighborhood.SetCircle(dRadius, esriGeoAnalysisUnitsEnum.esriUnitsCells);
                }
                IRaster pOutRaster = null;
                switch (pFClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    if (rdoKernel.Checked == false)
                    {
                        pOutRaster = pDensityOp.PointDensity(pFeatClsDes as IGeoDataset, pRasNeighborhood, ref Missing) as IRaster;
                    }
                    else
                    {
                        pOutRaster = pDensityOp.KernelDensity(pFeatClsDes as IGeoDataset, ref objRadius, ref Missing) as IRaster;
                    }
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (rdoKernel.Checked == false)
                    {
                        pOutRaster = pDensityOp.LineDensity(pFeatClsDes as IGeoDataset, ref objRadius, ref Missing) as IRaster;
                    }
                    else
                    {
                        pOutRaster = pDensityOp.KernelDensity(pFeatClsDes as IGeoDataset, ref objRadius, ref Missing) as IRaster;
                    }
                    break;
                }
                //着色
                IRasterLayer pRasterLayer = new RasterLayerClass();
                pRasterLayer.Name = "密度栅格";
                Utility.ConvertRasterToRsDataset(rasterPath, pOutRaster, "密度栅格");
                pRasterLayer = Utility.SetRsLayerClassifiedColor(pOutRaster);
                pMainFrm.getMapControl().AddLayer(pRasterLayer, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the selected density operations on the input feature class.
        /// </summary>
        /// <param name="pFC"></param>
        /// <returns></returns>
        private IRaster Density(IFeatureClass pFC)
        {
            IRaster pRaster = null;

            try
            {
                IDensityOp pDensityOp = new RasterDensityOpClass();

                //create a feature class descriptor to specify a field
                IFeatureClassDescriptor pFCD = new FeatureClassDescriptorClass();
                if (m_sField != "None")
                {
                    pFCD.Create(pFC, null, m_sField);
                }
                else
                {
                    pFCD.Create(pFC, null, null);
                }


                //run the density op
                //set the output resolution

                //make sure this scale factor is always in right units.
                object oScaleFactor = 1;
                switch (m_sDensityUnits + m_sMapUnits)
                {
                case "per square km" + "Meter":
                    oScaleFactor = 1000;
                    break;

                case "per square mile" + "Meter":
                    oScaleFactor = 1609.344;
                    break;

                case "per square mile" + "Foot_US":
                case "per square mile" + "Foot":
                    oScaleFactor = 5280;
                    break;

                case "per square km" + "Foot_US":
                case "per square km" + "Foot":
                    oScaleFactor = 3280.84;
                    break;

                case "per square nm" + "Meter":
                    oScaleFactor = 1852;
                    break;

                case "per square nm" + "Foot_US":
                case "per square nm" + "Foot":
                    oScaleFactor = 6076.12;
                    break;
                }

                object oRadius = m_dRadius;

                IGeoDataset pOutRaster = null;

                if (m_sDensityType == "Kernel")
                {
                    pOutRaster = pDensityOp.KernelDensity((IGeoDataset)pFCD, ref oRadius, ref oScaleFactor);
                }
                else
                {
                    esriGeometryType thisType = pFC.ShapeType;
                    if (thisType == esriGeometryType.esriGeometryPolyline)
                    {
                        pOutRaster = pDensityOp.LineDensity((IGeoDataset)pFCD, ref oRadius, ref oScaleFactor);
                    }
                    else if (thisType == esriGeometryType.esriGeometryPoint)
                    {
                        IRasterNeighborhood pNbr = new RasterNeighborhoodClass();

                        if (m_sRadiusType == "Cells")
                        {
                            pNbr.SetCircle(m_dRadius, esriGeoAnalysisUnitsEnum.esriUnitsCells);
                        }
                        else
                        {
                            pNbr.SetCircle(m_dRadius, esriGeoAnalysisUnitsEnum.esriUnitsMap);
                        }

                        pOutRaster = pDensityOp.PointDensity((IGeoDataset)pFCD, pNbr, ref oScaleFactor); //ref oCellSize);
                    }
                }
                pRaster = (IRaster)pOutRaster;

                //check output spatial reference
                IRasterProps pRProps = (IRasterProps)pRaster;
                pRProps.SpatialReference = m_pLayerSR;


                //save the raster to disk
                IWorkspace pOutWS  = clsStatic.OpenWorkspace(m_sOutPath);
                ISaveAs    pSaveAs = (ISaveAs)pRaster;
                if (pSaveAs.CanSaveAs("GRID") == true)
                {
                    pSaveAs.SaveAs(pFC.AliasName + "_" + m_sOutName, pOutWS, "GRID");
                }

                IMap pMap = ArcMap.Document.FocusMap;

                //calculate raster stats
                IRasterDataset pRDS = clsStatic.OpenRasterDataset(m_sOutPath, pFC.AliasName + "_" + m_sOutName);
                CalcStats(pRDS);

                //add the layer to the map
                IRasterLayer pRL   = clsStatic.RasterDataset2RasterLayer(m_sOutPath, pFC.AliasName + "_" + m_sOutName, false, pMap);
                IRgbColor    pRGB1 = new RgbColorClass();
                IRgbColor    pRGB2 = new RgbColorClass();
                pRGB2.Blue  = 0;
                pRGB2.Green = 0;
                pRGB2.Red   = 255;
                pRGB1.Blue  = 255;
                pRGB1.Green = 0;
                pRGB1.Red   = 0;
                //pRL.CreateFromRaster(pRaster);
                CreateRasterStretchRenderer(pRL, pRGB1, pRGB2);

                pMap.AddLayer(pRL);

                return(pRaster);
            }
            catch (Exception ex)
            {
                clsStatic.ShowErrorMessage(ex.ToString());
            }
            return(pRaster);
        }
Exemplo n.º 3
0
		private void btnGO_Click(object sender, System.EventArgs e)
		{
			IFeatureClass pFClass=null;//获得输入特征数据类
			 
			IWorkspace pWorkspace;
			object Missing = Type.Missing;	
			string fileName;
			string rasterPath;
			string shpFile;
			int startX,endX;
			string sFieldName;//选择要进行分析的字段
			if(bDataPath==true)
			{
				fileName=comboBoxInData.Text;
				string shpDir =fileName.Substring(0, fileName.LastIndexOf("\\")); 
				startX=fileName.LastIndexOf("\\");
				endX=fileName.Length;
				shpFile=fileName.Substring(startX+1,endX-startX-1);
				pFClass=Utility.OpenFeatureClassFromShapefile(shpDir,shpFile);
			}
			else
			{
				pFClass=GetFeatureFromMapLyr(comboBoxInData.Text);
			}
			IFeatureLayer pFeatLayer =new FeatureLayerClass();
			pFeatLayer.FeatureClass=pFClass;
			rasterPath=txtRasterPath.Text;
			IFeatureClassDescriptor pFeatClsDes=new FeatureClassDescriptorClass();
			if(comboBoxField.Text!="无")
				pFeatClsDes.Create(pFClass,null,comboBoxField.Text);
			else
				pFeatClsDes.Create(pFClass,null,"");
			try
			{
				 IDensityOp pDensityOp=new RasterDensityOpClass();
				string sCellSize=txtCellSize.Text ;
				double dCellSize=Convert.ToDouble(sCellSize);
				string sRadius=txtSearchRadius.Text;
				double dRadius=Convert.ToDouble(sRadius);
				object objRadius=dRadius;
				pDensityOp=Utility.SetRasterDensityAnalysisEnv(rasterPath,dCellSize,pFeatLayer);
				IRasterNeighborhood pRasNeighborhood=new RasterNeighborhoodClass();
				if(comboBoxAreaUnit.Text=="按地图单位")
					pRasNeighborhood.SetCircle(dRadius,esriGeoAnalysisUnitsEnum.esriUnitsMap);
				else
					pRasNeighborhood.SetCircle(dRadius,esriGeoAnalysisUnitsEnum.esriUnitsCells);
				IRaster pOutRaster=null;
				switch(pFClass.ShapeType)
				{
					case esriGeometryType.esriGeometryPoint:
						if(rdoKernel.Checked==false)
							pOutRaster= pDensityOp.PointDensity(pFeatClsDes as IGeoDataset,pRasNeighborhood,ref Missing) as IRaster;
						else
							pOutRaster= pDensityOp.KernelDensity(pFeatClsDes as IGeoDataset,ref objRadius,ref Missing) as IRaster;
						break;
					case esriGeometryType.esriGeometryPolyline:
						if(rdoKernel.Checked==false)
							pOutRaster= pDensityOp.LineDensity(pFeatClsDes as IGeoDataset,ref objRadius,ref Missing) as IRaster;
						else
							pOutRaster=pDensityOp.KernelDensity(pFeatClsDes as IGeoDataset,ref objRadius,ref Missing) as IRaster;
						break;
				}
				//着色                
				IRasterLayer pRasterLayer=new RasterLayerClass();
				pRasterLayer.Name="密度栅格";
				Utility.ConvertRasterToRsDataset(rasterPath,pOutRaster,"密度栅格");
                pRasterLayer = Utility.SetRsLayerClassifiedColor(pOutRaster);
				pMainFrm.getMapControl().AddLayer(pRasterLayer,0);		
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			
			}
		
		}