Esempio n. 1
0
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            if (this.comboBoxInputRaster.Text.ToString() == "" || this.comboBoxContrastRaster.Text.ToString() == "" || this.comboBoxOutputRaster.Text.ToString() == "")
            {
                MessageBox.Show("请输入参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }//有任意一个空为空则弹出对话框提示:请输入参数。
            string strResultsDBPath = m_pGDBHelper.GetResultsDBPath();//声明变量获取数据库结果路径
            string ToolName         = "minusmethod";

            if (comboBoxMethod.Text == "差值法")
            {
                ToolName = "minusmethod";
            }
            if (comboBoxMethod.Text == "比值法")
            {
                ToolName = "ratiomethod";
            }



            if (Utilities.GDBUtilites.CheckNameExist(strResultsDBPath, this.comboBoxOutputRaster.Text.ToString()) == false)//如果没有同名文件
            {
                //执行PCA分析
                ILayer pInputLayer1 = null;
                ILayer pInputLayer2 = null;

                for (int i = 0; i < m_pMapCtrl.LayerCount; i++)
                {
                    if (m_pMapCtrl.get_Layer(i).Name == this.comboBoxInputRaster.Text.ToString())
                    {
                        pInputLayer1 = m_pMapCtrl.get_Layer(i);
                    }
                    else if (m_pMapCtrl.get_Layer(i).Name == this.comboBoxContrastRaster.Text.ToString())
                    {
                        pInputLayer2 = m_pMapCtrl.get_Layer(i);
                    }
                }

                if (pInputLayer1 != null && pInputLayer2 != null)
                {
                    IRasterLayer pRasterLayer1 = pInputLayer1 as IRasterLayer;
                    IRasterLayer pRasterLayer2 = pInputLayer2 as IRasterLayer;
                    string       rasterpath1   = pRasterLayer1.FilePath;
                    string       rasterpath2   = pRasterLayer2.FilePath;

                    IGeoProcessor2 pGP    = new GeoProcessorClass();
                    string         GPPath = m_pGDBHelper.GetToolboxPath();

                    pGP.AddToolbox(GPPath);



                    IVariantArray gpParameters = new VarArrayClass();
                    //gpParameters.Add(pRasterLayer1.Raster);
                    //gpParameters.Add(pRasterLayer2.Raster);
                    gpParameters.Add(rasterpath1);
                    gpParameters.Add(rasterpath2);
                    gpParameters.Add(strResultsDBPath + "\\" + this.comboBoxOutputRaster.Text);

                    IGeoProcessorResult pGeoProcessorResult = null;


                    pGeoProcessorResult = pGP.Execute(ToolName, gpParameters, null);


                    if (pGeoProcessorResult.Status == esriJobStatus.esriJobSucceeded)
                    {
                        if (this.checkBoxAdd.Checked)
                        {
                            IWorkspaceFactory2 pWKF           = new FileGDBWorkspaceFactoryClass();
                            IRasterWorkspaceEx pRasterWKEx    = (IRasterWorkspaceEx)pWKF.OpenFromFile(m_pGDBHelper.GetResultsDBPath(), 0);
                            IRasterDataset3    pRasterDataset = pRasterWKEx.OpenRasterDataset(this.comboBoxOutputRaster.Text.ToString()) as IRasterDataset3;

                            Utilities.MapUtilites.AddRasterLayer(m_pMapCtrl.ActiveView, pRasterDataset, null);
                        }
                        MessageBox.Show("影像代数分析完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("已存在同名数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
Esempio n. 2
0
        private void comboBoxDataSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            //cyf 20110613 add
            //this.comboBoxFeaClass.Items.Clear();
            //end
            SysGisTable sysTable = new SysGisTable(_tmpWorkspace);
            Exception   eError;
            //根据用户选择的数据源,得到数据源的工作空间
            string DataSourceName = this.comboBoxDataSource.Text;
            string conninfostr    = sysTable.GetFieldValue("DATABASEMD", "CONNECTIONINFO", "DATABASENAME='" + DataSourceName + "'", out eError).ToString();
            int    type           = int.Parse(sysTable.GetFieldValue("DATABASEMD", "DATAFORMATID", "DATABASENAME='" + DataSourceName + "'", out eError).ToString());
            string strDBPara      = sysTable.GetFieldValue("DATABASEMD", "DBPARA", "DATABASENAME='" + DataSourceName + "'", out eError).ToString();
            int    index6         = conninfostr.LastIndexOf("|");
            //string strdataset = conninfostr.Substring(index6 + 1);

            IWorkspace pWorkspace = ModuleMap.GetWorkSpacefromConninfo(conninfostr, type);

            if (pWorkspace == null)
            {
                return;
            }
            _ListDataset.Clear();
            _ListTypeOfDataset.Clear();
            string strDatasets = conninfostr.Substring(index6 + 1);

            string[]          strTemp       = strDatasets.Split(new char[] { ',' });
            IFeatureWorkspace pFeaWorkSpace = pWorkspace as IFeatureWorkspace;

            if (pFeaWorkSpace != null)
            {
                for (int k = 0; k < strTemp.Length; k++)
                {
                    IDataset pTmpdataset = null;
                    if (strDBPara.Contains("栅格数据集"))
                    {
                        IRasterWorkspaceEx rasterWorkspace = (IRasterWorkspaceEx)pFeaWorkSpace;
                        IRasterDataset     pRDataset       = rasterWorkspace.OpenRasterDataset(strTemp[k]);
                        pTmpdataset = pRDataset as IDataset;
                        if (pTmpdataset != null)
                        {
                            _ListTypeOfDataset.Add("RD");
                        }
                    }
                    else if (strDBPara.Contains("栅格编目"))
                    {
                        IRasterWorkspaceEx rasterWorkspace = (IRasterWorkspaceEx)pFeaWorkSpace;
                        IRasterCatalog     pRCatalog       = rasterWorkspace.OpenRasterCatalog(strTemp[k]);
                        pTmpdataset = pRCatalog as IDataset;
                        if (pTmpdataset != null)
                        {
                            _ListTypeOfDataset.Add("RC");
                        }
                    }
                    else
                    {
                        pTmpdataset = pFeaWorkSpace.OpenFeatureDataset(strTemp[k]) as IDataset;
                        if (pTmpdataset != null)
                        {
                            _ListTypeOfDataset.Add("FC");
                        }
                    }
                    if (pTmpdataset != null)
                    {
                        _ListDataset.Add(pTmpdataset);
                    }
                }
            }
            _dataWorkspace = pWorkspace;

            if (pWorkspace == null)
            {
                return;
            }
        }
Esempio n. 3
0
        private void AddAllDataset(IWorkspace pWorkspace, AxMapControl mapControl)
        {
            IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);

            pEnumDataset.Reset();
            //将Enum数据集中的数据一个个读到DataSet中
            IDataset pDataset = pEnumDataset.Next();

            //判断数据集是否有数据
            while (pDataset != null)
            {
                if (pDataset is IFeatureDataset)  //要素数据集
                {
                    IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                    IFeatureDataset   pFeatureDataset   = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
                    IEnumDataset      pEnumDataset1     = pFeatureDataset.Subsets;
                    pEnumDataset1.Reset();
                    IGroupLayer pGroupLayer = new GroupLayerClass();
                    pGroupLayer.Name = pFeatureDataset.Name;
                    IDataset pDataset1 = pEnumDataset1.Next();
                    while (pDataset1 != null)
                    {
                        if (pDataset1 is IFeatureClass)  //要素类
                        {
                            IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                            pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
                            if (pFeatureLayer.FeatureClass != null)
                            {
                                pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                                pGroupLayer.Add(pFeatureLayer);
                                mapControl.Map.AddLayer(pFeatureLayer);
                            }
                        }
                        pDataset1 = pEnumDataset1.Next();
                    }
                }
                else if (pDataset is IFeatureClass) //要素类
                {
                    IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                    IFeatureLayer     pFeatureLayer     = new FeatureLayerClass();
                    pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);

                    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                    mapControl.Map.AddLayer(pFeatureLayer);
                }
                else if (pDataset is IRasterDataset) //栅格数据集
                {
                    IRasterWorkspaceEx pRasterWorkspace = (IRasterWorkspaceEx)pWorkspace;
                    IRasterDataset     pRasterDataset   = pRasterWorkspace.OpenRasterDataset(pDataset.Name);
                    //影像金字塔判断与创建
                    IRasterPyramid3 pRasPyrmid;
                    pRasPyrmid = pRasterDataset as IRasterPyramid3;
                    if (pRasPyrmid != null)
                    {
                        if (!(pRasPyrmid.Present))
                        {
                            pRasPyrmid.Create(); //创建金字塔
                        }
                    }
                    IRasterLayer pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(pRasterDataset);
                    ILayer pLayer = pRasterLayer as ILayer;
                    mapControl.AddLayer(pLayer, 0);
                }
                pDataset = pEnumDataset.Next();
            }

            mapControl.ActiveView.Refresh();
        }
 IRasterDataset OpenGDBRasterDataset(IRasterWorkspaceEx pRasterWorkspaceEx, string pDatasetName)
 {
     //打开存放在数据库中的栅格数据
     return pRasterWorkspaceEx.OpenRasterDataset(pDatasetName);
 }