コード例 #1
0
        /// <summary>
        /// 根据栅格和字段获取几何数据集
        /// </summary>
        /// <param name="raster">栅格</param>
        /// <param name="field">字段</param>
        /// <returns></returns>
        public static IGeoDataset GetGeoDatasetByRaster(IRaster raster, string field)
        {
            IRasterDescriptor rasDescriptor = new RasterDescriptorClass();

            rasDescriptor.Create(raster, null, field);
            IGeoDataset geoDataset = (IGeoDataset)rasDescriptor;

            return(geoDataset);
        }
コード例 #2
0
        //
        private void buttonApply_Click(object sender, System.EventArgs e)
        {
            try
            {
                IQueryFilter pQueryFilter = new QueryFilterClass();
                AxMapControl axMap        = pMainFrm.getMapControl();
                string       sLayerName   = comboBoxLayer.Text;
                bool         bLayerType   = GetLayerType(sLayerName);
                IActiveView  pActiveView  = axMap.Map as IActiveView;

                if (bLayerType == false)
                {
                    pQueryFilter.WhereClause = textBox1.Text;
                    IFeatureCursor pFeatCursor = m_pFeatCls.Search(pQueryFilter, false);
                    IFeature       pFeature    = pFeatCursor.NextFeature();

                    axMap.Map.ClearSelection();
                    IEnvelope pEnvelope = new EnvelopeClass();
                    ILayer    pLayer    = GetLayerFromName(sLayerName);

                    while (pFeature != null)
                    {
                        axMap.Map.SelectFeature(pLayer, pFeature);
                        pEnvelope.Union(pFeature.Extent.Envelope);
                        pFeature = pFeatCursor.NextFeature();
                    }
                    axMap.Extent = pEnvelope;
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                    pActiveView.Refresh();
                }
                else
                {
                    IRasterDescriptor pRasDes = new RasterDescriptorClass();
                    pQueryFilter.WhereClause = textBox1.Text;
                    pRasDes.Create(m_pRaster, pQueryFilter, listBoxField.Text);
                    IExtractionOp pExtrOp  = new RasterExtractionOpClass();
                    IRaster       pRaster  = pExtrOp.Attribute(pRasDes) as Raster;
                    IRasterLayer  pRsLayer = new RasterLayerClass();
                    pRsLayer.CreateFromRaster(pRaster);
                    axMap.Map.AddLayer(pRsLayer);
                    pActiveView.Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
        /// <summary>
        /// 设置显示的原值--新值
        /// </summary>
        /// <param name="pInRaster"></param>
        /// <param name="sField"></param>
        /// <returns></returns>
        public void setViewValue(IRaster pInRaster, string sField)
        {
            try
            {
                IRasterDescriptor pRD = new RasterDescriptorClass();
                pRD.Create(pInRaster, new QueryFilterClass(), sField);
                IGeoDataset           pGeodataset = pInRaster as IGeoDataset;
                IRasterLayer          pRLayer     = new RasterLayerClass();
                IRasterBandCollection pRsBandCol  = pGeodataset as IRasterBandCollection;
                IRasterBand           pRasterBand = pRsBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();
                IRasterStatistics pRasterStatistic = pRasterBand.Statistics;

                double dMaxValue = pRasterStatistic.Maximum;
                double dMinValue = pRasterStatistic.Minimum;

                if ((dMaxValue - dMinValue) / iReClassCount >= 1)
                {
                    double dItemInterval = (dMaxValue - dMinValue) / iReClassCount;
                    double dMinTemp      = dMinValue;
                    if (this.cmbFieldsName.Items.Count > 0)
                    {
                        this.lsvValue.Items.Clear();
                    }
                    for (int i = 0; i < iReClassCount; i++)
                    {
                        ListViewItem li = new ListViewItem();
                        li.SubItems.Clear();
                        li.SubItems[0].Text = dMinTemp.ToString() + " - " + (dMinTemp + dItemInterval).ToString("N4");
                        li.SubItems.Add(i.ToString());
                        this.lsvValue.Items.Add(li);
                        dMinTemp = dMinTemp + dItemInterval;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
コード例 #4
0
ファイル: frmRasterReClass.cs プロジェクト: lovelll/DQHP
        /// <summary>
        /// ������ʾ��ԭֵ--��ֵ
        /// </summary>
        /// <param name="pInRaster"></param>
        /// <param name="sField"></param>
        /// <returns></returns>
        public void setViewValue(IRaster pInRaster, string sField)
        {
            try
            {
                IRasterDescriptor pRD = new RasterDescriptorClass();
                pRD.Create(pInRaster, new QueryFilterClass(), sField);
                IGeoDataset pGeodataset = pInRaster as IGeoDataset;
                IRasterLayer pRLayer = new RasterLayerClass();
                IRasterBandCollection pRsBandCol = pGeodataset as IRasterBandCollection;
                IRasterBand pRasterBand = pRsBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();
                IRasterStatistics pRasterStatistic = pRasterBand.Statistics;

                double dMaxValue = pRasterStatistic.Maximum;
                double dMinValue = pRasterStatistic.Minimum;

                if ((dMaxValue - dMinValue) / iReClassCount >= 1)
                {
                    double dItemInterval = (dMaxValue - dMinValue) / iReClassCount;
                    double dMinTemp = dMinValue;
                    if (this.cmbFieldsName.Items.Count > 0)
                        this.lsvValue.Items.Clear();
                    for (int i = 0; i < iReClassCount; i++)
                    {
                        ListViewItem li = new ListViewItem();
                        li.SubItems.Clear();
                        li.SubItems[0].Text = dMinTemp.ToString() + " - " + (dMinTemp + dItemInterval).ToString("N4");
                        li.SubItems.Add(i.ToString());
                        this.lsvValue.Items.Add(li);
                        dMinTemp = dMinTemp + dItemInterval;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
コード例 #5
0
ファイル: frmRasterToFeature.cs プロジェクト: lovelll/DQHP
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int startX, endX;
            string shpDir;
            object Missing = Type.Missing;
            //if (bFeatDataPath == true)
            //{
            //    fileName = comboBoxInData.Text;
            //    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);
            //}
            if (bRasterDataPath == true)
            {
                fileName = txtOutPath.Text;
                shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX = fileName.LastIndexOf("\\");
                endX = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
            }
            else
            {
                shpDir = txtOutPath.Text;
                shpFile = "դ��ת����";
            }
            try
            {
                //ɾ����ʱ�����ļ�
                DelFeatFile(shpDir, shpFile);
                //���դ�����ݼ�
                IRasterDescriptor pRsDescriptor = new RasterDescriptorClass();
                pRsDescriptor.Create(m_pInRaster, new QueryFilterClass(), comboBoxField.Text);
                //�����������ռ�
                IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
                IWorkspace pWS = pWSF.OpenFromFile(shpDir, 0);
                //ת��դ��Ϊ������
                IConversionOp pConversionOp = new RasterConversionOpClass();
                IFeatureClass pOutFeatCls = null;
                switch (comboBoxGeomeryType.Text)
                {
                    case "��":
                        pOutFeatCls = pConversionOp.RasterDataToPointFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile) as IFeatureClass;
                        break;
                    case "��":
                        pOutFeatCls = pConversionOp.RasterDataToLineFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile, false, false, ref Missing) as IFeatureClass;
                        break;
                    case "��":
                        pOutFeatCls = pConversionOp.RasterDataToPolygonFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile, false) as IFeatureClass;
                        break;
                }
                IFeatureLayer pFeatLyr = new FeatureLayerClass();
                pFeatLyr.FeatureClass = pOutFeatCls;
                pMap.AddLayer(pFeatLyr);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
コード例 #6
0
        //Ϊդ��ͼ�����ݽ���ͨ�ӷ�����ɫ
        public static IRasterLayer SetViewShedRenderer(IRaster pInRaster, string sField, string sPath)
        {
            IRasterDescriptor pRD = new RasterDescriptorClass();
            pRD.Create(pInRaster, new QueryFilterClass(), sField);
            IReclassOp pReclassOp = new RasterReclassOpClass();
            IGeoDataset pGeodataset = pInRaster as IGeoDataset;
            IRasterAnalysisEnvironment pEnv = pReclassOp as IRasterAnalysisEnvironment;
            IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
            IWorkspace pWS = pWSF.OpenFromFile(sPath, 0);
            pEnv.OutWorkspace = pWS;
            object objSnap = null;
            object objExtent = pGeodataset.Extent;
            pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref objSnap);
            pEnv.OutSpatialReference = pGeodataset.SpatialReference;
            IRasterLayer pRLayer = new RasterLayerClass();
            IRasterBandCollection pRsBandCol = pGeodataset as IRasterBandCollection;
            IRasterBand pRasterBand = pRsBandCol.Item(0);
            pRasterBand.ComputeStatsAndHist();
            IRasterStatistics pRasterStatistic = pRasterBand.Statistics;
            double dMaxValue = pRasterStatistic.Maximum;
            double dMinValue = pRasterStatistic.Minimum;

            INumberRemap pNumRemap = new NumberRemapClass();
            pNumRemap.MapRange(dMinValue, 0, 0);
            pNumRemap.MapRange(0, dMaxValue, 1);
            IRemap pRemap = pNumRemap as IRemap;

            IRaster pOutRaster = pReclassOp.ReclassByRemap(pGeodataset, pRemap, false) as IRaster;
            pRLayer.CreateFromRaster(pOutRaster);

            return pRLayer;
        }
コード例 #7
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int    startX, endX;
            string shpDir;
            object Missing = Type.Missing;

            //if (bFeatDataPath == true)
            //{
            //    fileName = comboBoxInData.Text;
            //    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);
            //}
            if (bRasterDataPath == true)
            {
                fileName = txtOutPath.Text;
                shpDir   = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX   = fileName.LastIndexOf("\\");
                endX     = fileName.Length;
                shpFile  = fileName.Substring(startX + 1, endX - startX - 1);
            }
            else
            {
                shpDir  = txtOutPath.Text;
                shpFile = "栅格转特征";
            }
            try
            {
                //删除临时特征文件
                DelFeatFile(shpDir, shpFile);
                //获得栅格数据集
                IRasterDescriptor pRsDescriptor = new RasterDescriptorClass();
                pRsDescriptor.Create(m_pInRaster, new QueryFilterClass(), comboBoxField.Text);
                //获得输出工作空间
                IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
                IWorkspace        pWS  = pWSF.OpenFromFile(shpDir, 0);
                //转换栅格为特征类
                IConversionOp pConversionOp = new RasterConversionOpClass();
                IFeatureClass pOutFeatCls   = null;
                switch (comboBoxGeomeryType.Text)
                {
                case "点":
                    pOutFeatCls = pConversionOp.RasterDataToPointFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile) as IFeatureClass;
                    break;

                case "线":
                    pOutFeatCls = pConversionOp.RasterDataToLineFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile, false, false, ref Missing) as IFeatureClass;
                    break;

                case "面":
                    pOutFeatCls = pConversionOp.RasterDataToPolygonFeatureData(pRsDescriptor as IGeoDataset, pWS, shpFile, false) as IFeatureClass;
                    break;
                }
                IFeatureLayer pFeatLyr = new FeatureLayerClass();
                pFeatLyr.FeatureClass = pOutFeatCls;
                pMainFrm.getMapControl().AddLayer(pFeatLyr, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #8
0
ファイル: frmRasterReClass.cs プロジェクト: lovelll/DQHP
        private IRasterLayer SetViewShedRenderer(IRaster pInRaster, string sField, string sPath,double[,] dValue)
        {
            try
            {
                if (dValue == null)
                    return null;
                if (sField.Trim() == "")
                    return null;
                string path="";
                string fileName="";
                int iPath=sPath.LastIndexOf('\\');
                path=sPath.Substring(0,iPath);
                fileName=sPath.Substring(iPath+1,sPath.Length-iPath-1);

                IRasterDescriptor pRD = new RasterDescriptorClass();
                pRD.Create(pInRaster, null, sField);
                IReclassOp pReclassOp = new RasterReclassOpClass();

                IGeoDataset pGeodataset = pInRaster as IGeoDataset;
                IRasterAnalysisEnvironment pEnv = pReclassOp as IRasterAnalysisEnvironment;
                IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                IWorkspace pWS = pWSF.OpenFromFile(path, 0);
                //pEnv.OutWorkspace = pWS;
                //object objSnap = null;
                //object objExtent = pGeodataset.Extent;
                //pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref objSnap);
                //pEnv.OutSpatialReference = pGeodataset.SpatialReference;

                IRasterBandCollection pRsBandCol = pGeodataset as IRasterBandCollection;
                IRasterBand pRasterBand = pRsBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();
                IRasterStatistics pRasterStatistic = pRasterBand.Statistics;
                double dMaxValue = pRasterStatistic.Maximum;
                double dMinValue = pRasterStatistic.Minimum;

                INumberRemap pNumRemap = new NumberRemapClass();
                for (int i = 0; i < (dValue.Length/3); i++)
                {
                    pNumRemap.MapRange(dValue[i, 0], dValue[i, 1], (Int32)dValue[i, 2]);
                }
                IRemap pRemap = pNumRemap as IRemap;

                IGeoDataset pGeoDs = new RasterDatasetClass();
                pGeoDs=pReclassOp.ReclassByRemap(pGeodataset, pRemap, false);
                IRasterBandCollection pRasBandCol = (IRasterBandCollection)pGeoDs;
                pRasBandCol.SaveAs(fileName, pWS, "GRID");//"IMAGINE Image"
                IRaster pOutRaster =pGeoDs as IRaster;
                IRasterLayer pRLayer = new RasterLayerClass();

                pRLayer.CreateFromRaster(pOutRaster);
                pRLayer.Name = fileName;
                return pRLayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return null;
            }
        }
コード例 #9
0
        //դ���ط���
        private IRasterLayer calMValve(IRaster pInRaster, string sField)
        {
            try
            {
                if (sField.Trim() == "")
                    return null;
                IRasterDescriptor pRD = new RasterDescriptorClass();
                pRD.Create(pInRaster, null, sField);
                IReclassOp pReclassOp = new RasterReclassOpClass();

                IGeoDataset pGeodataset = pInRaster as IGeoDataset;
                IRasterAnalysisEnvironment pEnv = pReclassOp as IRasterAnalysisEnvironment;

                IRasterBandCollection pRsBandCol = pGeodataset as IRasterBandCollection;
                IRasterBand pRasterBand = pRsBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();
                IRasterStatistics pRasterStatistic = pRasterBand.Statistics;
                double dMaxValue = pRasterStatistic.Maximum;
                double dMinValue = pRasterStatistic.Minimum;

                INumberRemap pNumRemap = new NumberRemapClass();
                //m���������� ���¶�Ϊ 0-7.5; 7.5-12.5; 12.5-17.5; 17.5--22.5; >22.5;
                //mֵ�ֱ�Ϊ�� 0.1;0.15;0.2;0.25,0.3
                //��ֵ������100��
                pNumRemap.MapRange(dMinValue, 7.5, 10);
                pNumRemap.MapRange(7.5, 12.5, 15);
                pNumRemap.MapRange(12.5, 17.5, 20);
                pNumRemap.MapRange(17.5, 22.5, 25);
                pNumRemap.MapRange(22.5, dMaxValue, 30);
                IRemap pRemap = pNumRemap as IRemap;

                IGeoDataset pGeoDs = new RasterDatasetClass();
                pGeoDs = pReclassOp.ReclassByRemap(pGeodataset, pRemap, false);
                IRaster pOutRaster = pGeoDs as IRaster;
                IRasterLayer pRLayer = new RasterLayerClass();
                pRLayer.CreateFromRaster(pOutRaster);
                return pRLayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return null;
            }
        }
コード例 #10
0
        private IRasterLayer SetViewShedRenderer(IRaster pInRaster, string sField, string sPath, double[,] dValue)
        {
            try
            {
                if (dValue == null)
                {
                    return(null);
                }
                if (sField.Trim() == "")
                {
                    return(null);
                }
                string path     = "";
                string fileName = "";
                int    iPath    = sPath.LastIndexOf('\\');
                path     = sPath.Substring(0, iPath);
                fileName = sPath.Substring(iPath + 1, sPath.Length - iPath - 1);

                IRasterDescriptor pRD = new RasterDescriptorClass();
                pRD.Create(pInRaster, null, sField);
                IReclassOp pReclassOp = new RasterReclassOpClass();

                IGeoDataset pGeodataset         = pInRaster as IGeoDataset;
                IRasterAnalysisEnvironment pEnv = pReclassOp as IRasterAnalysisEnvironment;
                IWorkspaceFactory          pWSF = new RasterWorkspaceFactoryClass();
                IWorkspace pWS = pWSF.OpenFromFile(path, 0);
                //pEnv.OutWorkspace = pWS;
                //object objSnap = null;
                //object objExtent = pGeodataset.Extent;
                //pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref objSnap);
                //pEnv.OutSpatialReference = pGeodataset.SpatialReference;

                IRasterBandCollection pRsBandCol  = pGeodataset as IRasterBandCollection;
                IRasterBand           pRasterBand = pRsBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();
                IRasterStatistics pRasterStatistic = pRasterBand.Statistics;
                double            dMaxValue        = pRasterStatistic.Maximum;
                double            dMinValue        = pRasterStatistic.Minimum;

                INumberRemap pNumRemap = new NumberRemapClass();
                for (int i = 0; i < (dValue.Length / 3); i++)
                {
                    pNumRemap.MapRange(dValue[i, 0], dValue[i, 1], (Int32)dValue[i, 2]);
                }
                IRemap pRemap = pNumRemap as IRemap;

                IGeoDataset pGeoDs = new RasterDatasetClass();
                pGeoDs = pReclassOp.ReclassByRemap(pGeodataset, pRemap, false);
                IRasterBandCollection pRasBandCol = (IRasterBandCollection)pGeoDs;
                pRasBandCol.SaveAs(fileName, pWS, "GRID");//"IMAGINE Image"
                IRaster      pOutRaster = pGeoDs as IRaster;
                IRasterLayer pRLayer    = new RasterLayerClass();

                pRLayer.CreateFromRaster(pOutRaster);
                pRLayer.Name = fileName;
                return(pRLayer);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return(null);
            }
        }
コード例 #11
0
ファイル: frmFind.cs プロジェクト: chinasio/Control
       //
		private void buttonApply_Click(object sender, System.EventArgs e)
		{
			try
			{
				IQueryFilter pQueryFilter=new QueryFilterClass();
				AxMapControl axMap=pMainFrm.getMapControl();
				string sLayerName=comboBoxLayer.Text;
				bool bLayerType=GetLayerType(sLayerName);
				IActiveView pActiveView=axMap.Map as IActiveView ;
			                 
				if(bLayerType==false)
				{
					pQueryFilter.WhereClause=textBox1.Text;		 
					IFeatureCursor pFeatCursor=m_pFeatCls.Search(pQueryFilter,false);
					IFeature pFeature=pFeatCursor.NextFeature();
 
					axMap.Map.ClearSelection();
					IEnvelope pEnvelope=new EnvelopeClass();
					ILayer pLayer=GetLayerFromName(sLayerName);
					
					while(pFeature!=null)
					{
						axMap.Map.SelectFeature(pLayer,pFeature);
						pEnvelope.Union(pFeature.Extent.Envelope);
						pFeature=pFeatCursor.NextFeature();
					}		
					axMap.Extent=pEnvelope;
					pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,null,null);	
					pActiveView.Refresh();
				 
				}
				else
				{
					IRasterDescriptor pRasDes=new RasterDescriptorClass();
					pQueryFilter.WhereClause=textBox1.Text;		
					pRasDes.Create(m_pRaster,pQueryFilter,listBoxField.Text);
					IExtractionOp pExtrOp=new RasterExtractionOpClass();
					IRaster pRaster=pExtrOp.Attribute(pRasDes) as Raster ;
					IRasterLayer pRsLayer=new RasterLayerClass();
					pRsLayer.CreateFromRaster(pRaster);
					axMap.Map.AddLayer(pRsLayer);
					pActiveView.Refresh();
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			
			}

		}