Esempio n. 1
0
        public IRasterLayer RasterRenderedLayer(IRasterLayer pRL, bool renderType, int grayBandIndex, int[] rgbBandIndex)
        {
            //实例新的栅格图层
            IRasterLayer   rlayer        = new RasterLayerClass();
            string         fullPath      = pRL.FilePath;
            IRasterDataset rasterDataset = OpenFileRasterDataset(fullPath);

            //单波段
            if (rgbBandIndex == null)
            {
                //如果grayBandIndex=-1
                try
                {
                    //定义拉伸颜色条
                    IRgbColor pFromColor = new RgbColorClass();
                    pFromColor.Red   = this.userControl_Color1.FromColor.R;
                    pFromColor.Green = this.userControl_Color1.FromColor.G;
                    pFromColor.Blue  = this.userControl_Color1.FromColor.B;
                    IRgbColor pToColor = new RgbColorClass();
                    pToColor.Red   = this.userControl_Color1.ToColor.R;
                    pToColor.Green = this.userControl_Color1.ToColor.G;
                    pToColor.Blue  = this.userControl_Color1.ToColor.B;
                    IRasterRenderer render = null;
                    render = BandCombinationShow.StretchRenderer(rasterDataset, grayBandIndex, this.stretchType, pFromColor, pToColor);
                    rlayer.CreateFromDataset(rasterDataset);
                    rlayer.Renderer = render as IRasterRenderer;
                    return(rlayer);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(null);
                }
            }
            else//多波段显示
            {
                try
                {
                    //设置彩色合成顺序 生成新的渲染模式
                    IRasterRGBRenderer render = new RasterRGBRendererClass();
                    render.RedBandIndex   = rgbBandIndex[0];
                    render.GreenBandIndex = rgbBandIndex[1];
                    render.BlueBandIndex  = rgbBandIndex[2];

                    IRasterStretch stretchType = (IRasterStretch)render;
                    stretchType.StretchType             = this.stretchType;
                    stretchType.StandardDeviationsParam = 2;


                    rlayer.CreateFromDataset(rasterDataset);
                    rlayer.Renderer = render as IRasterRenderer;
                    return(rlayer);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(null);
                }
            }
        }
Esempio n. 2
0
        private void AddRasterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();

            if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string pFullpath = pOpenFileDialog.FileName;
                if (pFullpath == "")
                {
                    return;
                }

                //获得文件名和文件路径
                string pFilePath = System.IO.Path.GetDirectoryName(pFullpath);
                string pFileName = System.IO.Path.GetFileName(pFullpath);

                //获得工作空间,用栅格数据工作空间初始化
                IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();
                IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(pFilePath, 0);
                //三步,最后转为栅格工作空间
                IRasterWorkspace pRasterWorkspace = pWorkspace as IRasterWorkspace;
                //打开栅格数据集
                IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pFileName);
                //将栅格数据集转为图层
                IRasterLayer pRasterLayer = new RasterLayerClass();
                pRasterLayer.CreateFromDataset(pRasterDataset);
                axMapControl1.AddLayer(pRasterLayer, 0);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 矢量点转栅格
        /// </summary>
        /// <param name="xjFeatureLayer">矢量图层</param>
        /// <param name="RasterPath">栅格绝对路径</param>
        /// <param name="CellSize">栅格边长</param>
        /// <param name="SecletctedField">所选字段(高程等)</param>
        /// <returns>返回栅格图层</returns>
        private ILayer xjShpPointToRaster(IFeatureLayer xjFeatureLayer, string RasterPath, double CellSize, string SecletctedField)
        {
            IFeatureClass           xjFeatureClass           = xjFeatureLayer.FeatureClass;
            IFeatureClassDescriptor xjFeatureClassDescriptor = new FeatureClassDescriptorClass();//using ESRI.ArcGIS.GeoAnalyst;

            xjFeatureClassDescriptor.Create(xjFeatureClass, null, SecletctedField);
            IGeoDataset xjGeoDataset = xjFeatureClassDescriptor as IGeoDataset;

            IWorkspaceFactory          xjwsf          = new RasterWorkspaceFactoryClass(); //using ESRI.ArcGIS.DataSourcesRaster;
            string                     xjRasterFolder = System.IO.Path.GetDirectoryName(RasterPath);
            IWorkspace                 xjws           = xjwsf.OpenFromFile(xjRasterFolder, 0);
            IConversionOp              xjConversionOp = new RasterConversionOpClass();
            IRasterAnalysisEnvironment xjRasteren     = xjConversionOp as IRasterAnalysisEnvironment;

            object xjCellSize = CellSize as object;

            xjRasteren.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref xjCellSize);

            string         xjFileName = System.IO.Path.GetFileName(RasterPath);
            IRasterDataset xjdaset2   = xjConversionOp.ToRasterDataset(xjGeoDataset, "TIFF", xjws, xjFileName);

            IRasterLayer xjRasterLayer = new RasterLayerClass();

            xjRasterLayer.CreateFromDataset(xjdaset2);
            ILayer xjLayer = xjRasterLayer;

            xjRasterLayer.Name = xjFileName;

            return(xjLayer);
        }
Esempio n. 4
0
        /// <summary>
        /// 图层切割栅格数据
        /// </summary>
        /// <param name="rasterLayer">栅格数据图层</param>
        /// <param name="clipLayer">切割适量图层</param>
        /// <param name="outputFullPath">切割栅格完整路径</param>
        public void ClipRasterByLayer(ILayer rasterLayer, ILayer clipLayer, string outputFullPath)
        {
            string rasterPath = GetLayerPath(rasterLayer);
            string clipPath   = GetLayerPath(clipLayer);

            ExtractByMask clipTool = new ExtractByMask();

            clipTool.in_raster    = rasterPath;
            clipTool.in_mask_data = clipPath;
            clipTool.out_raster   = outputFullPath;

            Geoprocessor processor = new Geoprocessor();
            IGPProcess   process   = null;

            processor.OverwriteOutput = true;
            process = clipTool;
            processor.Validate(process, true);
            processor.Execute(process, null);

            DirectoryInfo     di        = new DirectoryInfo(outputFullPath);
            string            rasterDir = di.Parent.FullName;
            string            name      = di.Name;
            IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace  rasterWorkspace        = rasterWorkspaceFactory.OpenFromFile(rasterDir, 0) as IRasterWorkspace;
            IRasterDataset    rasterDataset          = rasterWorkspace.OpenRasterDataset(name);
            IRasterLayer      rasterLyr = new RasterLayerClass();

            rasterLyr.CreateFromDataset(rasterDataset);
            m_mapControl.Map.AddLayer(rasterLyr as ILayer);
        }
Esempio n. 5
0
        /// <summary>
        /// 加载栅格图层
        /// </summary>
        /// <param name="shpFile"></param>
        public IRasterLayer LoadDem(string shpFile)
        {
            string strFullPath = shpFile;

            if (strFullPath == "")
            {
                return(null);
            }
            int               Index             = strFullPath.LastIndexOf("\\");
            string            filePath          = strFullPath.Substring(0, Index);
            string            fileName          = strFullPath.Substring(Index + 1);
            IWorkspaceFactory pWSFact           = new RasterWorkspaceFactoryClass();
            IWorkspace        pWS               = pWSFact.OpenFromFile(filePath, 0);
            IRasterWorkspace  pRasterWorkspace1 = pWS as IRasterWorkspace;
            IRasterLayer      pRasterLayer      = new RasterLayerClass();

            try
            {
                IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace1.OpenRasterDataset(fileName);
                pRasterLayer.CreateFromDataset(pRasterDataset);
                ILayer pLayer = pRasterLayer as ILayer;
                pLayer.Name = pRasterLayer.Name;
                return(pRasterLayer);
            }
            catch (Exception err)
            {
                throw (err);
            }
        }
Esempio n. 6
0
        private void 加载高光谱文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string         fullFilePath;
            OpenFileDialog openFile = new OpenFileDialog();

            //openFile.Filter = "数据集|datasets";
            openFile.Multiselect = true;
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                fullFilePath = openFile.FileName;
                //获得文件路径
                int    index    = fullFilePath.LastIndexOf("\\");
                string filePath = fullFilePath.Substring(0, index);
                //获得文件名称
                string            fileName   = fullFilePath.Substring(index + 1);
                IWorkspaceFactory workspcFac = new RasterWorkspaceFactory();
                IRasterWorkspace  rasterWorkspc;
                IRasterDataset    rasterDatset = new RasterDatasetClass();
                IRasterLayer      rasterLay    = new RasterLayerClass();
                rasterWorkspc = workspcFac.OpenFromFile(filePath, 0) as IRasterWorkspace;
                rasterDatset  = rasterWorkspc.OpenRasterDataset(fileName);
                rasterLay.CreateFromDataset(rasterDatset);
                //axMapControl1.ClearLayers();
                rasterLay.Name = (num).ToString();
                num++;
                axMapControl1.AddLayer(rasterLay);
                axMapControl1.Refresh();
            }
        }
Esempio n. 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //create raster dataset from the JPIP service url
                Type factoryType           = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
                IWorkspaceFactory wsFact   = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
                string            tempPath = Path.GetTempPath();
                IRasterWorkspace2 ws       = wsFact.OpenFromFile(tempPath, 0) as IRasterWorkspace2;
                IRasterDataset    rds      = ws.OpenRasterDataset(txtJPIPUrl.Text);

                //create a layer from the raster dataset
                IRasterLayer rasterLayer = new RasterLayerClass();
                rasterLayer.CreateFromDataset(rds);
                string layerName = txtLayerName.Text;
                if (layerName == "")
                {
                    layerName = txtJPIPUrl.Text.Substring(txtJPIPUrl.Text.LastIndexOf("/") + 1, txtJPIPUrl.Text.Length - txtJPIPUrl.Text.LastIndexOf("/") - 1);
                }
                rasterLayer.Name = layerName;

                //add the JPIP layer to the current data frame of ArcMap
                ArcMap.Document.FocusMap.AddLayer(rasterLayer);
                this.Close();
            }
            catch
            {
                MessageBox.Show("Couldn't connect to the specified URL, sample url: jpip://myserver:8080/JP2Server/imagealias");
            }
        }
Esempio n. 8
0
        public void Init()
        {
            try
            {
                IConvolutionFunctionArguments rasterFunctionArguments = (IConvolutionFunctionArguments) new ConvolutionFunctionArguments();

                //设置输入栅格数据
                rasterFunctionArguments.Raster = m_raster;
                rasterFunctionArguments.Type   = (esriRasterFilterTypeEnum)type;
                //创建Raster Function对象
                IRasterFunction            rasterFunction            = new ConvolutionFunction();
                IFunctionRasterDataset     functionRasterDataset     = new FunctionRasterDataset();
                IFunctionRasterDatasetName functionRasterDatasetName = (IFunctionRasterDatasetName) new FunctionRasterDatasetNameClass();
                functionRasterDatasetName.FullName = @"D:\\RDB" + "\\" + outputRaster;
                functionRasterDataset.FullName     = (IName)functionRasterDatasetName;
                functionRasterDataset.Init(rasterFunction, rasterFunctionArguments);

                IRasterDataset rasData   = functionRasterDataset as IRasterDataset;
                IRasterLayer   pRstLayer = new RasterLayerClass();
                pRstLayer.CreateFromDataset(rasData);

                m_raster = pRstLayer.Raster;
            }
            catch (System.Exception ex)//异常处理,输出错误信息
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 9
0
        private void getRasterBandItem(DevComponents.AdvTree.Node parentNode, string dataType)
        {
            //获取当前的栅格文件
            FileInfo       file     = (FileInfo)parentNode.Tag;
            string         dataPath = file.FullName;
            IRasterDataset pRasterDataset;

            pRasterDataset = GetRasterDataset(file.FullName, dataType);
            IRasterLayer pRasterLayer = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(pRasterDataset);
            IRaster pRaster = pRasterLayer.Raster;
            IRasterBandCollection pRasterBandCol = (IRasterBandCollection)pRaster;

            IRasterBand pRasterBand = null;

            for (int i = 0; i < pRasterBandCol.Count; i++)
            {
                pRasterBand = pRasterBandCol.Item(i);
                ListViewItem item = new ListViewItem();
                item.Tag        = pRasterBand;
                item.Name       = pRasterBand.Bandname;
                item.Text       = pRasterBand.Bandname;
                item.ImageIndex = 14;
                lvwData.Items.Add(item);
            }
        }
Esempio n. 10
0
        public void LoadDem(string shpFile)
        {
            string strFullPath = shpFile;

            if (strFullPath == "")
            {
                return;
            }
            int               Index             = strFullPath.LastIndexOf("\\");
            string            filePath          = strFullPath.Substring(0, Index);
            string            fileName          = strFullPath.Substring(Index + 1);
            IWorkspaceFactory pWSFact           = new RasterWorkspaceFactoryClass();
            IWorkspace        pWS               = pWSFact.OpenFromFile(filePath, 0);
            IRasterWorkspace  pRasterWorkspace1 = pWS as IRasterWorkspace;
            IRasterLayer      pRasterLayer      = new RasterLayerClass();

            try
            {
                IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace1.OpenRasterDataset(fileName);
                pRasterLayer.CreateFromDataset(pRasterDataset);
                ILayer pLayer = pRasterLayer as ILayer;
                pLayer.Name = pRasterLayer.Name;
                mapControl.Map.AddLayer(pLayer);
                mapControl.ActiveView.Refresh();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
 /// <summary>
 /// 根据指定的影像路径显示影像
 /// </summary>
 /// <param name="imgPath">影像路径</param>
 public void DisplayImg(string imgPath)
 {
     if (File.Exists(imgPath))
     {
         //获取文件路径和文件名
         string imgDirectory = Path.GetDirectoryName(imgPath);
         string imgFileName  = Path.GetFileName(imgPath);
         //
         IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();
         IRasterWorkspace  pRasterWorkspace  = pWorkspaceFactory.OpenFromFile(imgDirectory, 0) as IRasterWorkspace;
         if (pRasterWorkspace != null)
         {
             IRasterDataset  pRasterDataset = pRasterWorkspace.OpenRasterDataset(imgFileName);
             IRasterPyramid3 prPyramid3     = pRasterDataset as IRasterPyramid3;
             if (prPyramid3 != null && !prPyramid3.Present)
             {
                 //进度条怎么写
                 MessageBox.Show("正在建立金字塔!");
                 prPyramid3.BuildPyramid(5, rstResamplingTypes.RSP_BilinearInterpolation);
                 MessageBox.Show("完成建立金字塔!");
             }
             IRasterLayer rasterLayer = new RasterLayerClass();
             rasterLayer.CreateFromDataset(pRasterDataset);
             rasterLayer.Name = Path.GetFileNameWithoutExtension(imgPath);
             this._pMap.AddLayer(rasterLayer);
         }
     }
     else
     {
         MessageBox.Show("指定的影像路径" + imgPath + "无效!");
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //create raster dataset from the JPIP service url
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
                IWorkspaceFactory wsFact = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
                string tempPath = Path.GetTempPath();
                IRasterWorkspace2 ws = wsFact.OpenFromFile(tempPath, 0) as IRasterWorkspace2;
                IRasterDataset rds = ws.OpenRasterDataset(txtJPIPUrl.Text);

                //create a layer from the raster dataset
                IRasterLayer rasterLayer = new RasterLayerClass();
                rasterLayer.CreateFromDataset(rds);
                string layerName = txtLayerName.Text;
                if (layerName == "")
                    layerName = txtJPIPUrl.Text.Substring(txtJPIPUrl.Text.LastIndexOf("/") + 1, txtJPIPUrl.Text.Length - txtJPIPUrl.Text.LastIndexOf("/") - 1);
                rasterLayer.Name = layerName;

                //add the JPIP layer to the current data frame of ArcMap
                ArcMap.Document.FocusMap.AddLayer(rasterLayer);
                this.Close();
            }
            catch
            {                
                MessageBox.Show("Couldn't connect to the specified URL, sample url: jpip://myserver:8080/JP2Server/imagealias");
            }
        }
Esempio n. 13
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string ftrPath = cmbFtrCls.Text;
            string imgPath = txtImgWks.Text;
            string outPath = txtOutWks.Text;

            if (ftrPath == "" || ftrPath == null)
            {
                MessageBox.Show("Missing Feature Class");
                return;
            }
            if (imgPath == "" || imgPath == null)
            {
                MessageBox.Show("Missing image directory\\workspace");
                return;
            }
            if (outPath == "" || outPath == null)
            {
                MessageBox.Show("Missing output workspace");
                return;
            }
            RunningProcess.frmRunningProcessDialog rd = new RunningProcess.frmRunningProcessDialog(false);
            this.Visible = false;
            rd.addMessage("Making Tiles. This may take a while....");
            rd.stepPGBar(10);
            rd.TopMost = true;
            DateTime dt = DateTime.Now;

            rd.Show();
            try
            {
                IFeatureClass            ftrCls  = ftrDic[ftrPath];
                IWorkspace               imgWks  = geoUtil.OpenRasterWorkspace(imgPath);
                IWorkspace               outWks  = geoUtil.OpenWorkSpace(outPath);
                IFunctionRasterDataset[] outDset = ftrUtil.tiledMosaics(ftrCls, imgWks, outWks);
                for (int i = 0; i < outDset.Length; i++)
                {
                    IRasterLayer lyr = new RasterLayerClass();
                    lyr.Name = "Tile_" + (i + 1).ToString();
                    lyr.CreateFromDataset((IRasterDataset)outDset[i]);
                    frmHlp.TheMap.AddLayer(lyr);
                }
            }
            catch (Exception ex)
            {
                rd.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rd.stepPGBar(100);
                rd.addMessage("Finished Making Tiles" + t);
                rd.enableClose();
                this.Close();
                rd.stepPGBar(100);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 加载数据集
        /// </summary>
        /// <param name="workspace">数据集所在工作空间</param>
        /// <param name="mapControl">要加载的地图控件</param>
        public void AddAllDataset(IWorkspace workspace, AxMapControl mapControl)
        {
            IEnumDataset enumDataset = workspace.get_Datasets(esriDatasetType.esriDTAny);

            enumDataset.Reset();
            IDataset dataset;

            while ((dataset = enumDataset.Next()) != null)
            {
                if (dataset is IFeatureDataset)     //要素数据集
                {
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                    IFeatureDataset   featureDataset   = featureWorkspace.OpenFeatureDataset(dataset.Name);
                    IEnumDataset      enumDatasetSub   = featureDataset.Subsets;
                    enumDatasetSub.Reset();
                    IDataset datasetSub;
                    while ((datasetSub = enumDatasetSub.Next()) != null)
                    {
                        if (datasetSub is FeatureClass)
                        {
                            IFeatureLayer featureLayer = new FeatureLayerClass();
                            featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(datasetSub.Name);
                            if (featureLayer.FeatureClass != null)
                            {
                                featureLayer.Name = featureLayer.FeatureClass.AliasName;
                                mapControl.AddLayer(featureLayer);
                            }
                        }
                    }
                }
                else if (dataset is IFeatureClass)  //要素类
                {
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                    IFeatureClass     featureClass     = featureWorkspace.OpenFeatureClass(dataset.Name);
                    IFeatureLayer     featureLayer     = new FeatureLayerClass();
                    featureLayer.FeatureClass = featureClass;
                    featureLayer.Name         = featureClass.AliasName;
                    mapControl.AddLayer(featureLayer);
                }
                else if (dataset is IRasterDataset) //栅格数据集
                {
                    IRasterWorkspaceEx rasterWorkspace = (IRasterWorkspaceEx)workspace;
                    IRasterDataset     rasterDataset   = rasterWorkspace.OpenRasterDataset(dataset.Name);
                    IRasterPyramid3    rasPyramid      = rasterDataset as IRasterPyramid3;
                    if (rasPyramid != null)
                    {
                        if (!rasPyramid.Present)
                        {
                            rasPyramid.Create();
                        }
                    }
                    IRasterLayer rasterLayer = new RasterLayerClass();
                    rasterLayer.CreateFromDataset(rasterDataset);
                    ILayer layer = rasterLayer as ILayer;
                    mapControl.AddLayer(layer, 0);
                }
            }
            mapControl.ActiveView.Refresh();
        }
Esempio n. 15
0
        /// <summary>
        /// 加载栅格库体
        /// </summary>
        /// <param name="m_Hook">主程序hook</param>
        /// <param name="DbEleInfo">矢量库体对应的库体信息XmlElement</param>
        /// <param name="ex">输出错误信息</param>
        public static void AddRasterLayer(Plugin.Application.IAppDBIntegraRef m_Hook, XmlElement DbEleInfo, out Exception ex)
        {
            ex = null;
            try
            {
                IGroupLayer pGroupLayer = new GroupLayerClass();
                pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.DataKeyString + "_" + m_Hook.ProjectTree.SelectedNode.Text;
                // string rasterDBType = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).GetAttribute("存储类型");
                // string rasterDBType = DbEleInfo.GetAttribute("存储类型");
                string     rasterDBType = string.Empty;
                XmlElement RasterEle    = DbEleInfo.SelectSingleNode(".//栅格数据库") as XmlElement;
                rasterDBType = RasterEle.GetAttribute("存储类型").Trim();
                XmlElement elementTemp   = DbEleInfo.SelectSingleNode(".//栅格数据库/连接信息") as XmlElement;
                IWorkspace TempWorkSpace = ModDBOperate.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace;
                if (TempWorkSpace == null)
                {
                    // SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!");
                    ex = new Exception("连接数据库失发生异常");
                    return;
                }
                IRasterWorkspaceEx pRasterWS = TempWorkSpace as IRasterWorkspaceEx;
                if (pRasterWS == null)
                {
                    return;
                }
                string feaclsName = (elementTemp.FirstChild as XmlElement).GetAttribute("名称");
                if (rasterDBType.Trim() == "栅格编目")
                {
                    //栅格编目数据加载
                    IRasterCatalog         pRasterCatalog = pRasterWS.OpenRasterCatalog(feaclsName);
                    IGdbRasterCatalogLayer pGDBRCLayer    = new GdbRasterCatalogLayerClass();
                    if (!pGDBRCLayer.Setup(pRasterCatalog as ITable))
                    {
                        return;
                    }
                    IFeatureLayer mFeaLayer = pGDBRCLayer as IFeatureLayer;
                    pGroupLayer.Add(mFeaLayer as ILayer);
                }
                else if (rasterDBType.Trim() == "栅格数据集")
                {
                    //栅格数据集加载

                    IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(feaclsName);
                    IRasterLayer   pRasterLayer   = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(pRasterDataset);
                    if (pRasterLayer == null)
                    {
                        return;
                    }
                    pGroupLayer.Add(pRasterLayer as ILayer);
                }
                m_Hook.MapControl.Map.AddLayer(pGroupLayer);
            }
            catch (Exception eError)
            {
                ex = eError;
                return;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 获取栅格图层
        /// </summary>
        /// <param name="filePath">图层文件路径</param>
        /// <returns></returns>
        public static IRasterLayer GetRasterLayer(string filePath)
        {
            IRasterDataset rasDataset  = GetRasterDataset(filePath);
            IRasterLayer   rasterLayer = new RasterLayerClass();

            rasterLayer.CreateFromDataset(rasDataset);
            return(rasterLayer);
        }
Esempio n. 17
0
        private void btnSure_Click(object sender, EventArgs e)
        {
            SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条");
            try
            {
                if (txtSave.Text == "" || comboBoxOpenfeatures.Text == "" || comboBoxOpenraster.Text == "")
                {
                    MessageBox.Show("参数未设置完全!", "提示");
                    return;
                }
                vProgress.EnableCancel    = false;//设置进度条
                vProgress.ShowDescription = true;
                vProgress.FakeProgress    = true;
                vProgress.TopMost         = true;
                vProgress.ShowProgress();
                vProgress.SetProgress("正在进行通视分析");
                string Unit;
                if (checkBox1.Checked)
                {
                    Unit = "CURVED_EARTH";
                }
                else
                {
                    Unit = "FLAT_EARTH";
                }
                double    Z          = Convert.ToDouble(txtZFactor.Text.ToString());
                string    SavName    = System.IO.Path.GetDirectoryName(txtSave.Text);
                ClsGPTool pClsGPTool = new ClsGPTool();
                pClsGPTool.ViewshedAnalyseGP(filePath_features, filePath_raster, txtSave.Text, Unit, Z);//进行通视分析
                vProgress.Close();
                if (MessageBox.Show("通视分析成功,是否加载分析结果", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();                                            // 张琪  20110611
                    IRasterWorkspace  pRasterWorkspace  = pWorkspaceFactory.OpenFromFile(SavName, 0) as IRasterWorkspace;
                    IRasterDataset    pRasterDataset    = pRasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(txtSave.Text)); //包含扩展名的表面数据集
                    IRasterLayer      pRasterLayer      = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(pRasterDataset);
                    ILayer pLayer = pRasterLayer as ILayer;
                    m_pCurrentSceneControl.Scene.AddLayer(pLayer, true);
                    m_pCurrentSceneControl.SceneGraph.RefreshViewers();
                    if (this.WriteLog)
                    {
                        Plugin.LogTable.Writelog("通视分析,表面集为" + comboBoxOpenraster.Text + ",观测点为" + comboBoxOpenfeatures.Text);
                        Plugin.LogTable.Writelog("输出栅格路径为:" + txtSave.Text);
                    }
                    vProgress.Close();
                }

                this.Close();
            }
            catch
            {
                vProgress.Close();
                this.Close();
                MessageBox.Show("很抱歉,操作失败!", "提示!");
                return;
            }
        }
Esempio n. 18
0
        private void OpenRaster(string rasterFileName)
        {
            //文件名处理

            string ws = System.IO.Path.GetDirectoryName(rasterFileName);

            string fbs = System.IO.Path.GetFileName(rasterFileName);

            //创建工作空间

            IWorkspaceFactory pWork = new RasterWorkspaceFactoryClass();

            //打开工作空间路径,工作空间的参数是目录,不是具体的文件名

            IRasterWorkspace pRasterWS = (IRasterWorkspace)pWork.OpenFromFile(ws, 0);

            //打开工作空间下的文件,

            IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(fbs);


            IRasterLayer pRasterLayer = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(pRasterDataset);

            //添加到图层控制中
            IRaster pRaster = pRasterLayer.Raster;

            IGeoDataset           pGeodataset = pRaster as IGeoDataset;
            IRasterBandCollection pRsBandCol  = pGeodataset as IRasterBandCollection;
            int bandCount;

            bandCount = pRsBandCol.Count;
            if (bandCount == 1)
            {
                IRasterBand pRasterBand1 = pRsBandCol.Item(0);
                pRasterBand1.ComputeStatsAndHist();
            }
            if (bandCount > 1)
            {
                IRasterBand pRasterBand1 = pRsBandCol.Item(0);
                pRasterBand1.ComputeStatsAndHist();
                IRasterBand pRasterBand2 = pRsBandCol.Item(1);
                pRasterBand2.ComputeStatsAndHist();
                IRasterBand pRasterBand3 = pRsBandCol.Item(2);
                pRasterBand3.ComputeStatsAndHist();
            }


            IRasterDataset pRasterDataset2 = pRasterWS.OpenRasterDataset(fbs);
            IRasterLayer   pRasterLayer2   = new RasterLayerClass();

            pRasterLayer2.CreateFromDataset(pRasterDataset2);

            //添加到图层控制中

            pMap.AddLayer(pRasterLayer2 as ILayer);
        }
        /// <summary>
        /// 打开栅格数据集,返回RasterLayer
        /// </summary>
        /// <param name="path"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public IRasterLayer RasterLayer(string path, string filename)
        {
            IRasterWorkspaceEx workspaceEx   = (IRasterWorkspaceEx)workspaceFactory.OpenFromFile(path, 0);
            IRasterLayer       rasterLayer   = new RasterLayerClass();
            IRasterDataset     rasterDataset = workspaceEx.OpenRasterDataset(filename);

            rasterLayer.CreateFromDataset(rasterDataset);
            return(rasterLayer);
        }
Esempio n. 20
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string rstNm   = cmbRaster.Text;
            string wksNm   = txtWorkspace.Text;
            string outNm   = txtOutName.Text;
            string outType = cmbType.Text;
            int    blSize  = System.Convert.ToInt32(nudBS.Value);

            if (outWks == null || wksNm == "" || wksNm == null || rstNm == "" || rstNm == null || outNm == "" || outNm == null)
            {
                MessageBox.Show("Raster, Workspace, or Output Name are not specified!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            object noDataVl = null;

            if (rsUtil.isNumeric(txtNoDataVl.Text) && txtNoDataVl.Visible)
            {
                noDataVl = System.Convert.ToDouble(txtNoDataVl.Text);
            }
            rasterUtil.rasterType rType = (rasterUtil.rasterType)Enum.Parse(typeof(rasterUtil.rasterType), outType);
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            rp.addMessage("Saving raster");
            rp.addMessage("This may take a while...");
            rp.stepPGBar(20);
            rp.Show();
            rp.Refresh();

            DateTime dt1 = DateTime.Now;

            try
            {
                IRaster        rs     = rstDic[rstNm];
                IRasterDataset rsDset = rsUtil.saveRasterToDatasetM(rs, outNm, outWks, rType, noDataVl, blSize, blSize);
                DateTime       dt2    = DateTime.Now;
                IRasterLayer   rsLyr  = new RasterLayerClass();
                rsLyr.CreateFromDataset(rsDset);
                rsLyr.Name    = outNm;
                rsLyr.Visible = false;
                mp.AddLayer((ILayer)rsLyr);
                TimeSpan ts      = dt2.Subtract(dt1);
                string   prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
                rp.addMessage(prcTime);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                rp.stepPGBar(100);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 21
0
        public void LoadDEM(string rastername, ref Dictionary <int, float> resultdic) // 加ref防止null rasterdic
        {
            resultdic   = new Dictionary <int, float>();
            rasterkey   = new List <int>();
            rastervalue = new List <float>();
            IWorkspaceFactory pWSF     = new RasterWorkspaceFactory();
            string            fileName = @"D:\study\ao\MortonCode\slopedata";
            IRasterWorkspace  pRWS     = pWSF.OpenFromFile(fileName, 0) as IRasterWorkspace;

            if (pRWS == null)
            {
                MessageBox.Show("Could not open raster workspace");
                return;
            }
            IRasterDataset rasterData = pRWS.OpenRasterDataset(rastername);

            if (rasterData == null)
            {
                MessageBox.Show("Could not open raster dataset");
                return;
            }
            IRaster2     raster      = rasterData.CreateDefaultRaster() as IRaster2;
            IRasterLayer rasterlayer = new RasterLayerClass();

            rasterlayer.CreateFromDataset(rasterData);
            int   col;
            int   row;
            float pixelValue;
            int   maxrow = rasterlayer.RowCount;
            int   maxcol = rasterlayer.ColumnCount;

            for (row = 0; row < maxrow; row++)
            {
                for (col = 0; col < maxcol; col++)
                {
                    rasterkey.Add(GetMorton(row, col, maxrow));
                    pixelValue = raster.GetPixelValue(0, col, row);
                    rastervalue.Add(pixelValue);
                }
            }
            for (int i = 0; i < maxcol * maxrow; i++)
            {
                resultdic.Add(rasterkey[i], rastervalue[i]);
            }
            //foreach (KeyValuePair<int, double> kvp in rasterdic1)
            //{
            //    MessageBox.Show("MD: " + kvp.Key + "  Slope: " + kvp.Value);
            //}
            MessageBox.Show("Number of pixels: " + resultdic.Count);

            //rasterdic1_sort = (from entry in rasterdic1
            //orderby entry.Key ascending
            //select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
            //MessageBox.Show("Number of sorted pixel: " + rasterdic1_sort.Count);
            //MessageBox.Show(rasterdic1_sort.Keys.ToString());
        }
Esempio n. 22
0
        private void 现势性检查ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IWorkspaceFactory pFileGDBWorkspaceFactory;

            pFileGDBWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
            IWorkspace   pWorkspace   = pFileGDBWorkspaceFactory.OpenFromFile(Path, 0);
            IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);

            pEnumDataset.Reset();
            IDataset  pDataset        = pEnumDataset.Next();
            DataTable SpatialRefTable = new DataTable();

            SpatialRefTable.Columns.Add(new DataColumn("影像名称", typeof(string)));
            SpatialRefTable.Columns.Add(new DataColumn("影像拍摄时间", typeof(string)));
            SpatialRefTable.Columns.Add(new DataColumn("时间现势性检查", typeof(string)));

            //判断数据集是否有数据
            while (pDataset != null)
            {
                if (pDataset is IRasterDataset) //栅格数据集
                {
                    IRasterWorkspaceEx pRasterWorkspace = (IRasterWorkspaceEx)pWorkspace;
                    IRasterDataset     pRasterDataset   = pRasterWorkspace.OpenRasterDataset(pDataset.Name);
                    //影像金字塔判断与创建
                    ISpatialReference pSpatialRef = (pRasterDataset as IGeoDataset).SpatialReference;
                    string            spatialref  = pSpatialRef.Name.ToString();
                    string            rastername  = pDataset.Name.ToString();
                    string[]          strArray    = rastername.Split('_');

                    DataRow dr = SpatialRefTable.NewRow();
                    dr["影像名称"]   = pDataset.Name.ToString();
                    dr["影像拍摄时间"] = strArray[1].Substring(0, 8);
                    IRasterLayer pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(pRasterDataset);
                    if (int.Parse(strArray[1].Substring(0, 8)) < 20170000 && int.Parse(strArray[1].Substring(0, 8)) > 20120000)
                    {
                        dr["时间现势性检查"] = "√";
                    }
                    else
                    {
                        dr["时间现势性检查"] = "×";
                    }
                    SpatialRefTable.Rows.Add(dr);
                }
                pDataset = pEnumDataset.Next();
            }
            // ExportExcel(SpatialRefTable);
            //弹出显示框
            TimeCheck tc = new TimeCheck();

            tc.Text = "影像质量检查";
            tc.dataGridView1.DataSource       = SpatialRefTable;
            tc.dataGridView1.Columns[1].Width = 200;
            tc.dataGridView1.Columns[2].Width = 300;
            tc.Show();
        }
Esempio n. 23
0
        /* private void getCADlayer(object fileData)
         * {
         *   //获取CAD文件
         *   FileInfo file = (FileInfo)fileData;
         *   string dwgPath = file.FullName;//得到CAD文件的全路径
         *   int indexdwg = dwgPath.LastIndexOf("\\");
         *   string filedwgPath = dwgPath.Substring(0, indexdwg);
         *   string filedwgName = dwgPath.Substring(indexdwg + 1);
         *   //获取CAD文件的Workspace
         *   IWorkspace dwgWorkspace = GetWorkspace(filedwgPath, "dwg");
         *   IFeatureWorkspace pFeatureWorkspace = dwgWorkspace as IFeatureWorkspace;
         *   IFeatureDataset pFeatureDataset;
         *   //IFeatureLayer pFeatureLayer = null;
         *   //得到CAD文件的FeatureDataset
         *   pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(filedwgName);
         *
         *   IFeatureClassContainer pFeatureClassContainer = null;
         *   pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;
         *   //遍历并打开CAD文件
         *   for (int i = 0; i < pFeatureClassContainer.ClassCount - 1; i++)
         *   {
         *       IFeatureClass pFeatureClass;
         *       //得到FeatureClass
         *       pFeatureClass = pFeatureClassContainer.get_Class(i);
         *       /*if (pFeatureClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
         *       {
         *           pFeatureLayer = new CadAnnotationLayerClass();
         *       }
         *       else
         *       {
         *           pFeatureLayer = new FeatureLayerClass();
         *       }
         *       //pFeatureLayer.FeatureClass = pFeatureClass;
         *       m_pFeaturelayer.FeatureClass = pFeatureClass;
         *       // pFeatureLayer.Name = pFeatureClass.AliasName;
         *       // pMap.AddLayer(pFeatureLayer);
         *       //m_pActiveView.Refresh();
         *   }
         * }*/
        private void AddRasterDataset(object rasterDataset, IMap pMap)
        {
            IRasterDataset pRasterDataset;

            pRasterDataset = (IRasterDataset)rasterDataset;
            IRasterLayer pRasterLayer = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(pRasterDataset);
            pMap.AddLayer(pRasterLayer);
        }
Esempio n. 24
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedItems == null)
            {
                MessageBox.Show("请选择图幅名!");
                return;
            }

            string sqlText = "";

            for (int i = 0; i < this.listBox1.SelectedItems.Count; i++)
            {
                sqlText = "select name,DATASTRUCTURE from sheetmetadata where NAME='" + listBox1.SelectedItems[i] + "'";
                m_oraCmd.CommandText = sqlText;
                OracleDataReader dr = m_oraCmd.ExecuteReader();
                if (!dr.HasRows)
                {
                    MessageBox.Show("图幅不存在!");
                    return;
                }
                while (dr.Read())
                {
                    // this.listBox1.Items.Add(dr.GetValue(0).ToString());
                    if (dr.GetValue(1).ToString() == "矢量")
                    {
                        IFeatureLayer feaLyr;
                        feaLyr = m_gdata.AddFeatureClassToMap(dr.GetValue(0).ToString());
                        this.m_mapControl.Map.AddLayer(feaLyr);
                    }
                    if (dr.GetValue(1).ToString() == "影像")
                    {
                        IRasterWorkspaceEx rasterWS      = m_workSpace as IRasterWorkspaceEx;
                        IRasterCatalog     rasterCatalog = rasterWS.OpenRasterCatalog("COASTALGIS." + dr.GetValue(1).ToString());
                        ITable             table         = rasterCatalog as ITable;
                        ICursor            cursor        = table.Search(null, false);
                        IRow           row      = cursor.NextRow();
                        IRasterDataset rasterDS = null;
                        while (row != null)
                        {
                            IRasterCatalogItem rasterCatalogItem = row as IRasterCatalogItem;

                            if (dr.GetValue(0).ToString() == row.get_Value(cursor.FindField("NAME")).ToString())
                            {
                                rasterDS = rasterCatalogItem.RasterDataset;
                                break;
                            }
                            row = cursor.NextRow();
                        }
                        IRasterLayer rasterLayer = new RasterLayerClass();
                        rasterLayer.CreateFromDataset(rasterDS);
                        this.m_mapControl.Map.AddLayer(rasterLayer);
                    }
                }
            }
        }
Esempio n. 25
0
        private void btnSure_Click(object sender, EventArgs e)
        {
            SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条");
            try
            {
                if (txtSave.Text == "" || comboBoxFortraster.Text == "" || comboBoxToraster.Text == "")
                {
                    MessageBox.Show("参数未设置完全!", "提示");
                    return;
                }

                vProgress.EnableCancel    = false;//设置进度条
                vProgress.ShowDescription = true;
                vProgress.FakeProgress    = true;
                vProgress.TopMost         = true;
                vProgress.ShowProgress();
                vProgress.SetProgress("正在进行填挖方分析");
                double Z       = Convert.ToDouble(txtZFactor.Text.ToString());
                string SavName = System.IO.Path.GetDirectoryName(txtSave.Text);

                ClsGPTool pClsGPTool = new ClsGPTool();
                pClsGPTool.CutFillGP(fortraster_Path, toraster_Path, txtSave.Text, Z);//进行填挖方分析
                vProgress.Close();
                if (MessageBox.Show("填挖方分析成功,是否加载分析结果", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    if (this.WriteLog)
                    {
                        Plugin.LogTable.Writelog("填挖方分析,填挖前表面集:" + comboBoxFortraster.Text + ",填挖后表面集:" + comboBoxToraster.Text);
                        Plugin.LogTable.Writelog("输出栅格路径为:" + txtSave.Text);
                    }
                    vProgress.ShowProgress();
                    vProgress.SetProgress("正在进行加载结果数据");
                    IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();                                            // 张琪  20110627
                    IRasterWorkspace  pRasterWorkspace  = pWorkspaceFactory.OpenFromFile(SavName, 0) as IRasterWorkspace;
                    IRasterDataset    pRasterDataset    = pRasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(txtSave.Text)); //包含扩展名的表面数据集
                    IRasterLayer      pRasterLayer      = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(pRasterDataset);
                    ILayer pLayer = pRasterLayer as ILayer;
                    m_pCurrentSceneControl.Scene.AddLayer(pLayer, true);
                    m_pCurrentSceneControl.SceneGraph.RefreshViewers();
                    vProgress.Close();
                }


                this.Close();
            }
            catch
            {
                vProgress.Close();
                this.Close();
                MessageBox.Show("很抱歉,操作失败!", "提示!");
                return;
            }
        }
        public static ILayer OpenRasterFile(string spacePath, string fileName)
        {
            IWorkspace       myWorkspace     = rWorkspaceFactory.OpenFromFile(spacePath, 0);
            IRasterWorkspace rasterWorkspace = myWorkspace as IRasterWorkspace;
            IRasterDataset   rasterDataset   = new RasterDatasetClass();
            IRasterLayer     rasterLayer     = new RasterLayerClass();

            rasterDataset = rasterWorkspace.OpenRasterDataset(fileName);
            rasterLayer.CreateFromDataset(rasterDataset);
            return(rasterLayer);
        }
Esempio n. 27
0
        // 从地理数据库中加载栅格数据
        private void AddRasterFromGDB(string rastername)
        {
            FileGDBWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
            IWorkspace         pWorkspace             = pWorkspaceFactory.OpenFromFile(DATADIR + "Database.gdb", 0);
            IRasterWorkspaceEx pRasterWorkspace       = pWorkspace as IRasterWorkspaceEx;
            IRasterDataset     pRasterDataset         = pRasterWorkspace.OpenRasterDataset(rastername);
            IRasterLayer       pRasterLayer           = new RasterLayerClass();

            pRasterLayer.CreateFromDataset(pRasterDataset);
            m_pMapC2.AddLayer(pRasterLayer);
        }
Esempio n. 28
0
        private void 加载图像ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //打开选择文件对话框用于选取图形文件
            string fullFilePath;  //存储打开文件的全路径
            //设置OpenFileDialog的属性,使其能打开多种类型文件
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Multiselect = true;
            openFile.Filter      = "shape文件(*.shp)|*.shp";
            openFile.Filter     += "|栅格数据(*.jpg,*.bmp,*.tiff)|*.jpg;*.bmp;*.tiff;*.tif;*.img";
            openFile.Title       = "打开文件";
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                fullFilePath = openFile.FileName;
                //获得文件路径
                int    index    = fullFilePath.LastIndexOf("\\");
                string filePath = fullFilePath.Substring(0, index);
                //获得文件名称
                string fileName = fullFilePath.Substring(index + 1);
                //加载shape文件
                if (openFile.FilterIndex == 1)
                {
                    //打开工作空间工厂
                    IWorkspaceFactory workspcFac = new ShapefileWorkspaceFactory();
                    IFeatureWorkspace featureWorkspc;
                    IFeatureLayer     featureLay = new FeatureLayerClass();
                    //打开路径
                    featureWorkspc = workspcFac.OpenFromFile(filePath, 0) as IFeatureWorkspace;
                    //打开类要素
                    featureLay.FeatureClass = featureWorkspc.OpenFeatureClass(fileName);
                    featureLay.Name         = fileName;
                    //添加图层
                    axMapControl1.AddLayer(featureLay);
                    axMapControl1.Refresh();
                }
                //加载栅格图像
                else if (openFile.FilterIndex == 2)
                {
                    IWorkspaceFactory workspcFac = new RasterWorkspaceFactory();
                    IRasterWorkspace  rasterWorkspc;
                    IRasterDataset    rasterDatset = new RasterDatasetClass();
                    IRasterLayer      rasterLay    = new RasterLayerClass();
                    rasterWorkspc = workspcFac.OpenFromFile(filePath, 0) as IRasterWorkspace;
                    rasterDatset  = rasterWorkspc.OpenRasterDataset(fileName);
                    rasterLay.CreateFromDataset(rasterDatset);
                    axMapControl1.ClearLayers();
                    rasterLay.Name = fileName;
                    axMapControl1.AddLayer(rasterLay);
                    axMapControl1.Refresh();
                }
            }
        }
        public static ILayer OpenRasterFile(string fullFilePath)
        {
            String           path            = System.IO.Path.GetDirectoryName(fullFilePath); //路径
            String           _name           = System.IO.Path.GetFileName(fullFilePath);      //文件名
            IWorkspace       myWorkspace     = rWorkspaceFactory.OpenFromFile(path, 0);
            IRasterWorkspace rasterWorkspace = myWorkspace as IRasterWorkspace;
            IRasterDataset   rasterDataset   = new RasterDatasetClass();
            IRasterLayer     rasterLayer     = new RasterLayerClass();

            rasterDataset = rasterWorkspace.OpenRasterDataset(_name);
            rasterLayer.CreateFromDataset(rasterDataset);
            return(rasterLayer);
        }
Esempio n. 30
0
        public IRaster2 MapXY2RowCol(double x, double y, string rasname)
        {
            string         filepath    = @"D:\study\ao\MortonCode\slopedata";
            IRasterDataset rasds       = OpenRaterDS(filepath, rasname);
            IRaster2       ras         = rasds.CreateDefaultRaster() as IRaster2;
            IRasterLayer   rasterlayer = new RasterLayerClass();

            rasterlayer.CreateFromDataset(rasds);
            bitsize = rasterlayer.RowCount;
            col     = ras.ToPixelColumn(x);
            row     = ras.ToPixelRow(y);
            return(ras);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            string rstNm = cmbRaster.Text;
            string wksNm = txtWorkspace.Text;
            string outNm = txtOutName.Text;
            string outType = cmbType.Text;
            int blSize = System.Convert.ToInt32(nudBS.Value);
            if (outWks == null || wksNm == "" || wksNm == null || rstNm == "" || rstNm == null || outNm==""||outNm==null)
            {
                MessageBox.Show("Raster, Workspace, or Output Name are not specified!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            object noDataVl = null;
            if (rsUtil.isNumeric(txtNoDataVl.Text)&&txtNoDataVl.Visible) noDataVl = System.Convert.ToDouble(txtNoDataVl.Text);
            rasterUtil.rasterType rType = (rasterUtil.rasterType)Enum.Parse(typeof(rasterUtil.rasterType), outType);
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            rp.addMessage("Saving raster");
            rp.addMessage("This may take a while...");
            rp.stepPGBar(20);
            rp.Show();
            rp.Refresh();

            DateTime dt1 = DateTime.Now;
            try
            {
                IRaster rs = rstDic[rstNm];
                IRasterDataset rsDset = rsUtil.saveRasterToDatasetM(rs, outNm, outWks, rType, noDataVl,blSize,blSize);//rsUtil.saveRasterToDataset(rs, outNm, outWks);
                DateTime dt2 = DateTime.Now;
                IRasterLayer rsLyr = new RasterLayerClass();
                rsLyr.CreateFromDataset(rsDset);
                rsLyr.Name = outNm;
                rsLyr.Visible = false;
                mp.AddLayer((ILayer)rsLyr);
                TimeSpan ts = dt2.Subtract(dt1);
                string prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
                rp.addMessage(prcTime);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                rp.stepPGBar(100);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 32
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("��ѡ�񲨶�����!");
                return;
            }

            IRasterBand rb = m_rc.Item(m_rc.get_BandIndex(this.comboBox1.SelectedItem.ToString().Trim()));
            IRasterDataset rasterDS = rb as IRasterDataset;
            IRasterLayer rasterLayer = new RasterLayerClass();
            rasterLayer.CreateFromDataset(rasterDS);
            this.m_mapCon.Map.AddLayer(rasterLayer);
        }
Esempio n. 33
0
        private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!DBHelper.ifLogin)
            {
                MessageBox.Show("请登录");
                return;
            }

            ArrayList test = DBHelper.queryAll("NAME LIKE '%52%'");

            for (int i = 0; i < test.Count; i++)
            {
                MessageBox.Show(((NameAndType)test[i]).name + "");
            }
            object data = DBHelper.openByTypeAndName(((NameAndType)test[0]).name, ((NameAndType)test[0]).type);

            //显示矢量图的方法
            if (((NameAndType)test[0]).type.StartsWith("f"))
            {
                IFeatureDataset        queryData        = (IFeatureDataset)data;
                IFeatureClassContainer datasetContainer = (IFeatureClassContainer)queryData;
                IFeatureLayer          m_FeatureLayer;
                for (int i = 0; i < datasetContainer.ClassCount; i++)
                {
                    IFeatureClass pFeatureClass = datasetContainer.get_Class(i);
                    if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        m_FeatureLayer = new CadAnnotationLayerClass();
                        MessageBox.Show("");
                    }
                    else
                    {
                        m_FeatureLayer              = new FeatureLayerClass();
                        m_FeatureLayer.Name         = pFeatureClass.AliasName;
                        m_FeatureLayer.FeatureClass = pFeatureClass;

                        m_mapControl.Map.AddLayer(m_FeatureLayer);
                    }
                }
            }

            //显示栅格图的方法
            if (((NameAndType)test[0]).type.StartsWith("r"))
            {
                IRasterDataset queryData    = (IRasterDataset)data;
                IRasterLayer   pRasterLayer = new RasterLayerClass();
                pRasterLayer.CreateFromDataset(queryData);
                m_mapControl.Map.AddLayer(pRasterLayer as ILayer);
            }
        }
Esempio n. 34
0
 //定义栅格打开函数
 public static void OpenRaster(string rasterFileName, AxMapControl _MapControl)
 {
     if (!File.Exists(rasterFileName))
     {
         return;
     }
     try
     {
         //文件名处理
         string ws = System.IO.Path.GetDirectoryName(rasterFileName);
         string fbs = System.IO.Path.GetFileName(rasterFileName);
         //创建工作空间
         IWorkspaceFactory pWork = new RasterWorkspaceFactoryClass();
         //打开工作空间路径,工作空间的参数是目录,不是具体的文件名
         IRasterWorkspace pRasterWS = (IRasterWorkspace)pWork.OpenFromFile(ws, 0);
         //打开工作空间下的文件,
         IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(fbs);
         IRasterLayer pRasterLayer = new RasterLayerClass();
         pRasterLayer.CreateFromDataset(pRasterDataset);
         //添加到图层控制中
         _MapControl.Map.AddLayer(pRasterLayer as ILayer);
     }
     catch { }
 }
        private void btnClip_Click(object sender, EventArgs e)
        {
            string ftrNm = cmbSampleFeatureClass.Text;
            string rstNm = cmbRaster.Text;
            string outNm = txtOutRasterName.Text;
            bool chErase = chbErase.Checked;
            esriRasterClippingType clType = esriRasterClippingType.esriRasterClippingOutside;
            if (ftrNm == "" || ftrNm == null || rstNm == "" || rstNm == null)
            {
                MessageBox.Show("You must have a polygon and raster layer selected", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if(outNm==""||outNm==null)
            {
                MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if(chErase)
            {
                clType= esriRasterClippingType.esriRasterClippingInside;
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;
            rp.addMessage("Clipping Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                IRaster rst = rstDic[rstNm];
                IFeatureClass ftrCls = ftrDic[ftrNm];
                IGeometry geo = geoUtil.createGeometry(ftrCls);
                IFunctionRasterDataset outraster = rsUtil.clipRasterFunction(rst, geo, clType);
                if (mp != null&&addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromDataset((IRasterDataset)outraster);
                    rstLyr.Name = outNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername = outNm;
                this.DialogResult = DialogResult.OK;

            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts = dt2.Subtract(dt);
                string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Clipping Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 36
0
        private void 视域分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IRasterWorkspace pRasterWs = GetRasterWorkspace(@".\data\IDW数据");

             IRasterDataset pRasterDataset = pRasterWs.OpenRasterDataset("dem.img");

             IRasterLayer pRasterLayer = new RasterLayerClass();

             pRasterLayer.CreateFromDataset(pRasterDataset);

             axMapControl1.Map.AddLayer(pRasterLayer as ILayer);

             pFlag = 4;
        }
        public void addFunctionRasterToMap(IMap map)
        {
            try
            {
                ofd.Title = "Add Function Model to map";
                ofd.Filter = "Function Dataset|*.fds|Batch Datasets|*.bch|NetCdf|*.nc";
                ofd.Multiselect = false;
                ofd.FilterIndex = 2;
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    FunctionDatasetPath = ofd.FileName;
                    int fIndex = ofd.FilterIndex;
                    string outName = "";
                    object outobj = null;
                    string outDesc = "";
                    if (fIndex == 1)
                    {
                        IRaster outRs;
                        createFunctionRaster(out outName, out outRs, out outDesc);
                        outobj = outRs;
                    }
                    else if (fIndex == 2)
                    {
                        createBatchRaster(out outName, out outobj, out outDesc);
                    }
                    else
                    {
                        createNetCdf(out outName, out outobj, out outDesc);
                    }
                    if (outobj is IFunctionRasterDataset)
                    {
                        IRasterLayer rsLyr = new RasterLayerClass();
                        rsLyr.CreateFromDataset((IRasterDataset)outobj);
                        rsLyr.Name = outName;
                        rsLyr.Visible = false;
                        map.AddLayer((ILayer)rsLyr);
                    }
                    else if (outobj is IRaster)
                    {
                        IRasterLayer rsLyr = new RasterLayerClass();
                        rsLyr.CreateFromRaster((IRaster)outobj);
                        rsLyr.Name = outName;
                        rsLyr.Visible = false;
                        map.AddLayer((ILayer)rsLyr);
                    }
                    else if (outobj is FeatureClass)
                    {
                        IFeatureLayer ftrLyr = new FeatureLayerClass();
                        ftrLyr.Name = outName;
                        ftrLyr.Visible = false;
                        ftrLyr.FeatureClass = (IFeatureClass)outobj;
                        map.AddLayer((ILayer)ftrLyr);
                    }
                    else if (outobj is Table)
                    {
                        IStandaloneTableCollection stCol = (IStandaloneTableCollection)map;
                        IStandaloneTable stTbl = new StandaloneTableClass();
                        stTbl.Table = (ITable)outobj;
                        stTbl.Name = outName;
                        stCol.AddStandaloneTable(stTbl);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("There was a problem parsing the model. Please check your model file");
                    }

                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Could not add output to the map:" + e.ToString(), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Esempio n. 38
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedItems == null)
            {
                MessageBox.Show("请选择图幅名!");
                return;
            }

            string sqlText = "";
            for (int i = 0; i < this.listBox1.SelectedItems.Count; i++)
            {
                sqlText = "select name,DATASTRUCTURE from sheetmetadata where NAME='" + listBox1.SelectedItems[i] + "'";
                m_oraCmd.CommandText = sqlText;
                OracleDataReader dr = m_oraCmd.ExecuteReader();
                if (!dr.HasRows)
                {
                    MessageBox.Show("图幅不存在!");
                    return;
                }
                while (dr.Read())
                {
                   // this.listBox1.Items.Add(dr.GetValue(0).ToString());
                    if (dr.GetValue(1).ToString() == "矢量")
                    {
                        IFeatureLayer feaLyr;
                        feaLyr = m_gdata.AddFeatureClassToMap(dr.GetValue(0).ToString());
                        this.m_mapControl.Map.AddLayer(feaLyr);
                    }
                    if (dr.GetValue(1).ToString() == "影像")
                    {
                        IRasterWorkspaceEx rasterWS = m_workSpace as IRasterWorkspaceEx;
                        IRasterCatalog rasterCatalog = rasterWS.OpenRasterCatalog("COASTALGIS." + dr.GetValue(1).ToString());
                        ITable table = rasterCatalog as ITable;
                        ICursor cursor = table.Search(null, false);
                        IRow row = cursor.NextRow();
                        IRasterDataset rasterDS = null;
                        while (row != null)
                        {
                            IRasterCatalogItem rasterCatalogItem = row as IRasterCatalogItem;

                            if (dr.GetValue(0).ToString() == row.get_Value(cursor.FindField("NAME")).ToString())
                            {
                                rasterDS = rasterCatalogItem.RasterDataset;
                                break;
                            }
                            row = cursor.NextRow();
                        }
                        IRasterLayer rasterLayer = new RasterLayerClass();
                        rasterLayer.CreateFromDataset(rasterDS);
                        this.m_mapControl.Map.AddLayer(rasterLayer);
                    }
                }

            }
        }
Esempio n. 39
0
        public void StandardToolLibrary(string toolName)
        {
            switch (toolName)
            {
                case "AddData":
                    m_command = new ControlsAddDataCommandClass();
                    break;
                case"New":
                    m_command = new CreateNewDocument();
                    break;
                case"Open":
                    m_command = new ControlsOpenDocCommandClass();
                    break;
                case"Save":
                    break;
                case"SaveAs":
                    m_command = new ControlsSaveAsDocCommandClass();
                    break;
                case "CADToVec":
                    m_command = new AddCADToFeatures();
                    break;

                case "CADToRas":
                    m_command = new AddCADToRaster();
                    break;
            }
            if(m_command!=null)
            {
                m_command.OnCreate(m_mapControl.Object);
                m_command.OnClick();
                m_command = null;
            }

            if (toolName == "Open")
            {
                m_frmMian.ControlsSynchronizer.ReplaceMap(m_mapControl.Map);
            }

            if (toolName == "AddTin")
            {
                FolderBrowserDialog fdlg = new FolderBrowserDialog();
                fdlg.Description = "打开TIN";
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    IWorkspaceFactory wsFac = new TinWorkspaceFactoryClass();
                    if (wsFac.IsWorkspace(System.IO.Path.GetDirectoryName(fdlg.SelectedPath)))
                    {
                        ITinWorkspace tinWS = wsFac.OpenFromFile(System.IO.Path.GetDirectoryName(fdlg.SelectedPath), 0) as ITinWorkspace;
                        ITinLayer tinLyr = new TinLayerClass();
                        try
                        {
                            tinLyr.Dataset = tinWS.OpenTin(System.IO.Path.GetFileName(fdlg.SelectedPath));
                            tinLyr.Name = System.IO.Path.GetFileName(fdlg.SelectedPath);
                            this.m_mapControl.Map.AddLayer((ILayer)tinLyr);
                        }
                        catch
                        {
                            MessageBox.Show("请选择有效的TIN文件!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("请选择有效的TIN文件!");
                        return;
                    }

                }
            }

            if (toolName == "AddDEM")
            {
                FolderBrowserDialog fdlg = new FolderBrowserDialog();
                fdlg.Description = "打开DEM";
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    IWorkspaceFactory wsFac = new RasterWorkspaceFactoryClass();
                    if (wsFac.IsWorkspace(System.IO.Path.GetDirectoryName(fdlg.SelectedPath)))
                    {
                        IRasterWorkspace tinWS = wsFac.OpenFromFile(System.IO.Path.GetDirectoryName(fdlg.SelectedPath), 0) as IRasterWorkspace;
                        IRasterLayer rasLyr = new RasterLayerClass();
                        try
                        {
                            rasLyr.CreateFromDataset(tinWS.OpenRasterDataset(System.IO.Path.GetFileName(fdlg.SelectedPath)));
                            this.m_mapControl.Map.AddLayer((ILayer)rasLyr);
                        }
                        catch
                        {
                            MessageBox.Show("请选择有效的DEM文件!");
                        }

                    }
                    else
                    {
                        MessageBox.Show("请选择有效的DEM文件!");
                        return;
                    }

                }
            }
        }
 private void btnExecute_Click(object sender, EventArgs e)
 {
     string rstNm = txtOutNm.Text;
     string funNm = cmbFunction.Text;
     int before = System.Convert.ToInt32(nudBefore.Value);
     int after = System.Convert.ToInt32(nudAfter.Value);
     if (rstNm == null || rstNm == "")
     {
         MessageBox.Show("You must specify a output name","No Output",MessageBoxButtons.OK,MessageBoxIcon.Error);
         return;
     }
     if (lsbRaster.Items.Count < 1)
     {
         MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if ( funNm==null||funNm=="")
     {
         MessageBox.Show("You must select at least on function", "No Function Selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     IRasterBandCollection rsBc = new RasterClass();
     for (int i = 0; i < lsbRaster.Items.Count; i++)
     {
         rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);
     }
     IFunctionRasterDataset fdset = rsUtil.compositeBandFunction(rsBc);
     rasterUtil.localType op = (rasterUtil.localType)Enum.Parse(typeof(rasterUtil.localType),funNm);
     this.Visible = false;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Calculating raster values. This may take a while...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     rp.Show();
     try
     {
         outraster = rsUtil.focalBandfunction(fdset,op,before,after);
         //rp.addMessage("Number of bands = " + ((IRasterBandCollection)outraster).Count);
         if (mp != null&&addToMap)
         {
             rp.addMessage("Calculating Statistics...");
             rp.Refresh();
             IRasterLayer rstLyr = new RasterLayerClass();
             //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
             rstLyr.CreateFromDataset((IRasterDataset)outraster);
             rstLyr.Name = rstNm;
             rstLyr.Visible = false;
             mp.AddLayer(rstLyr);
         }
         outrastername = rstNm;
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         rp.addMessage(ex.ToString());
     }
     finally
     {
         DateTime dt2 = DateTime.Now;
         TimeSpan ts = dt2.Subtract(dt);
         string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
         rp.stepPGBar(100);
         rp.addMessage("Finished Creating Rasters" + t);
         rp.enableClose();
         this.Close();
     }
 }
Esempio n. 41
0
        /// <summary>
        /// 图层切割栅格数据
        /// </summary>
        /// <param name="rasterLayer">栅格数据图层</param>
        /// <param name="clipLayer">切割适量图层</param>
        /// <param name="outputFullPath">切割栅格完整路径</param>
        public void ClipRasterByLayer(ILayer rasterLayer, ILayer clipLayer, string outputFullPath)
        {
            string rasterPath = GetLayerPath(rasterLayer);
            string clipPath = GetLayerPath(clipLayer);

            ExtractByMask clipTool = new ExtractByMask();
            clipTool.in_raster = rasterPath;
            clipTool.in_mask_data = clipPath;
            clipTool.out_raster = outputFullPath;

            Geoprocessor processor = new Geoprocessor();
            IGPProcess process = null;
            processor.OverwriteOutput = true;
            process = clipTool;
            processor.Validate(process, true);
            processor.Execute(process, null);

            DirectoryInfo di = new DirectoryInfo(outputFullPath);
            string rasterDir = di.Parent.FullName;
            string name = di.Name;
            IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace rasterWorkspace = rasterWorkspaceFactory.OpenFromFile(rasterDir, 0) as IRasterWorkspace;
            IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(name);
            IRasterLayer rasterLyr = new RasterLayerClass();
            rasterLyr.CreateFromDataset(rasterDataset);
            m_mapControl.Map.AddLayer(rasterLyr as ILayer);
        }
Esempio n. 42
0
        public static ILayer CreateLayer(ICatalogItem catalogItem)
        {
            if (catalogItem == null || catalogItem.Dataset==null)
                return null;

            ILayer lyrNew = null;
            enumCatalogType catalogType = catalogItem.Type;
            switch(catalogType)
            {
                case enumCatalogType.Workpace:
                case enumCatalogType.FeatureDataset:
                case enumCatalogType.Table:
                    return null;

                case enumCatalogType.FeatureClassPoint:
                case enumCatalogType.FeatureClassLine:
                case enumCatalogType.FeatureClassArea:
                case enumCatalogType.FeatureClassAnnotation:
                case enumCatalogType.FeatureClassEmpty:
                case enumCatalogType.FeatureClass3D:
                case enumCatalogType.RasterCatalog:
                    IFeatureLayer lyrFeature= new FeatureLayerClass();
                    lyrFeature.FeatureClass = catalogItem.Dataset as IFeatureClass;
                    lyrNew = lyrFeature;
                    break;

                case enumCatalogType.RasterMosaic:
                case enumCatalogType.RasterSet:
                    IRasterLayer lyrRaster = new RasterLayerClass();
                    lyrRaster.CreateFromDataset(catalogItem.Dataset as IRasterDataset);
                    lyrNew = lyrRaster;
                    break;

                case enumCatalogType.RasterBand:
                    IRasterLayer lyrRasterBand = new RasterLayerClass();
                    IRasterBand rasterBand = catalogItem.Dataset as IRasterBand;
                    IRasterBandCollection colRasterBand = new RasterClass();
                    colRasterBand.Add(rasterBand, 0);
                    lyrRasterBand.CreateFromRaster(colRasterBand as IRaster);

                    lyrNew = lyrRasterBand;
                    break;

                case enumCatalogType.Tin:
                    ITinLayer lyrTin = new TinLayerClass();
                    lyrTin.Dataset = catalogItem.Dataset as ITin;
                    lyrNew = lyrTin;
                    break;

                case enumCatalogType.Terrain:
                    ITerrainLayer lyrTerrain = new TerrainLayerClass();
                    lyrTerrain.Terrain = catalogItem.Dataset as ITerrain;
                    lyrNew = lyrTerrain;
                    break;

                case enumCatalogType.Topology:
                    ITopologyLayer lyrTopology = new TopologyLayerClass();
                    lyrTopology.Topology = catalogItem.Dataset as ITopology;
                    lyrNew = lyrTopology as ILayer;
                    break;
            }

            return lyrNew;
        }
Esempio n. 43
0
        public void ThreeDToolLibrary(string toolName)
        {
            switch (toolName)
            {
                case"3DOpen":
                    m_command = new ControlsSceneOpenDocCommandClass();
                    break;

                case "Navigation":
                    m_command = new ControlsSceneNavigateToolClass();
                    break;

                case"3DZoomIn":
                    m_command = new ControlsSceneZoomInToolClass();
                    break;

                case "3DZoomOut":
                    m_command = new ControlsSceneZoomOutToolClass();
                    break;

                case "3DPan":
                    m_command = new ControlsScenePanToolClass();
                    break;

                case"3DExtent":
                    m_command = new ControlsSceneFullExtentCommandClass();
                    break;

                case"3DSel":
                    m_command = new ControlsSceneSelectGraphicsToolClass();
                    break;

            }
            if (m_command is ITool)
            {
                m_command.OnCreate(m_sceneControl.Object);
                m_sceneControl.CurrentTool = (ITool)m_command;
            }
            if (m_command is ICommand)
            {
                m_command.OnCreate(m_sceneControl.Object);
                m_command.OnClick();
            }
            m_command = null;

            if (toolName == "3DAddTIN")
            {
                FolderBrowserDialog fdlg = new FolderBrowserDialog();
                fdlg.Description = "打开TIN";
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    IWorkspaceFactory wsFac = new TinWorkspaceFactoryClass();
                    if (wsFac.IsWorkspace(System.IO.Path.GetDirectoryName(fdlg.SelectedPath)))
                    {
                        ITinWorkspace tinWS = wsFac.OpenFromFile(System.IO.Path.GetDirectoryName(fdlg.SelectedPath), 0) as ITinWorkspace;
                        ITinLayer tinLyr = new TinLayerClass();
                        try
                        {
                            tinLyr.Dataset = tinWS.OpenTin(System.IO.Path.GetFileName(fdlg.SelectedPath));
                            this.m_sceneControl.Scene.AddLayer((ILayer)tinLyr,false);
                            SetTinAsBase(tinLyr);

                        }
                        catch
                        {
                            MessageBox.Show("请选择有效的TIN文件!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("请选择有效的TIN文件!");
                        return;
                    }

                }
            }

            if (toolName == "3DAddDEM")
            {
                FolderBrowserDialog fdlg = new FolderBrowserDialog();
                fdlg.Description = "打开DEM";
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    IWorkspaceFactory wsFac = new RasterWorkspaceFactoryClass();
                    if (wsFac.IsWorkspace(System.IO.Path.GetDirectoryName(fdlg.SelectedPath)))
                    {
                        IRasterWorkspace tinWS = wsFac.OpenFromFile(System.IO.Path.GetDirectoryName(fdlg.SelectedPath), 0) as IRasterWorkspace;
                        IRasterLayer rasLyr = new RasterLayerClass();
                        try
                        {
                            rasLyr.CreateFromDataset(tinWS.OpenRasterDataset(System.IO.Path.GetFileName(fdlg.SelectedPath)));
                            this.m_sceneControl.Scene.AddLayer((ILayer)rasLyr, false);
                            SetlayerSurface(rasLyr, 1);
                            //this.axSceneControl1.Refresh();
                        }
                        catch
                        {
                            MessageBox.Show("请选择有效的DEM文件!");
                        }

                    }
                    else
                    {
                        MessageBox.Show("请选择有效的DEM文件!");
                        return;
                    }

                }
            }
        }
Esempio n. 44
0
        private void uiCommandManager1_CommandClick(object sender, Janus.Windows.UI.CommandBars.CommandEventArgs e)
        {
            this.m_mapControl.CurrentTool = null;
            this.StatusBar.Panels[0].Text = "当前任务:" + e.Command.Text.ToString();
            this.m_rasterMeasureDis = false;
            this.m_rasterMeasureArea = false;
            //this.mapCtlMain.CurrentTool = null;
            if (e.Command.Key == "menuExit") //退出程序
            {
                Application.Exit();
            }

            switch (e.Command.CategoryName)
            {

                #region 标准工具栏
                case "Standard":
                    m_toolLib.StandardToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;
                #endregion

                #region 导航工具栏
                case"Navigation":
                    m_toolLib.NavigationToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;
                 #endregion 导航工具栏

                #region 数据库工具栏
                case "DB":
                    m_toolLib.DBToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));

                    break;
                #endregion 数据库工具栏

                #region 工具工具栏
                case "Tool":
                    m_toolLib.ToolToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;
                #endregion 工具工具栏

                case"CallMap":
                    m_toolLib.CallMapToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;

                case"3D":
                    m_toolLib.ThreeDToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;

                case"Index":
                    m_toolLib.IndexToolibrry(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;
            }

            #region 出图制图栏
            if (e.Command.Key == "menuLegend") //设置比例尺
            {
                DesignPageLayout designPageLayout = new DesignPageLayout(m_mapControl, m_pageLayoutControl);
                designPageLayout.AddLegend();//添加图例
            }

            if (e.Command.Key == "menuText")
            {
                m_designPageLayout = new DesignPageLayout(m_mapControl, m_pageLayoutControl);
                m_designPageLayout.AddText();//添加文字
            }

            if (e.Command.Key == "menuNorthArrow")
            {
                m_designPageLayout = new DesignPageLayout(m_mapControl, m_pageLayoutControl);
                m_designPageLayout.AddNorthArrow();//添加指北针

            }

            if (e.Command.Key == "menuScaleBar")
            {
                m_designPageLayout = new DesignPageLayout(m_pageLayoutControl);
                m_designPageLayout.AddScaleBar();//添加比例尺
            }

            if (e.Command.Key == "menuScaleText")
            {
                m_designPageLayout = new DesignPageLayout(m_pageLayoutControl);
                m_designPageLayout.AddTextScale();//添加文字比例尺

            }

            if (e.Command.Key == "menuMapGrid")
            {
                m_designPageLayout = new DesignPageLayout(m_pageLayoutControl);
                m_designPageLayout.AddMapGrid();//添加地图格网
            }

            if (e.Command.Key == "menuPageAndPrintaSet")
            {
                #region//页面设置
                DialogResult result = pageSetupDialog1.ShowDialog();
                document.PrinterSettings = pageSetupDialog1.PrinterSettings;
                document.DefaultPageSettings = pageSetupDialog1.PageSettings;

                int i;
                IEnumerator paperSizes = pageSetupDialog1.PrinterSettings.PaperSizes.GetEnumerator();
                paperSizes.Reset();
                for (i = 0; i < pageSetupDialog1.PrinterSettings.PaperSizes.Count; ++i)
                {
                    paperSizes.MoveNext();
                    if (((PaperSize)paperSizes.Current).Kind == document.DefaultPageSettings.PaperSize.Kind)
                    {
                        document.DefaultPageSettings.PaperSize = ((PaperSize)paperSizes.Current);
                    }
                }
                IPaper paper;
                paper = new PaperClass(); //create a paper object

                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                printer.Paper = paper;
                m_pageLayoutControl.Printer = printer;
                #endregion
            }

            if (e.Command.Key == "menuPrintView")
            {
                #region//打印预览
                m_CurrentPrintPage = 0;
                if (axPageLayoutControl1.ActiveView.FocusMap == null) return;
                document.DocumentName = axPageLayoutControl1.DocumentFilename;
                printPreviewDialog1.Document = document;
                printPreviewDialog1.ShowDialog();
                #endregion

            }

            if (e.Command.Key == "menuPrintExport")
            {
                #region //打印
                //allow the user to choose the page range to be printed
                printDialog1.AllowSomePages = true;
                //show the help button.
                printDialog1.ShowHelp = true;

                //set the Document property to the PrintDocument for which the PrintPage Event
                //has been handled. To display the dialog, either this property or the
                //PrinterSettings property must be set
                printDialog1.Document = document;

                //show the print dialog and wait for user input
                DialogResult result = printDialog1.ShowDialog();

                // If the result is OK then print the document.
                if (result == DialogResult.OK) document.Print();
                #endregion

            }

            if (e.Command.Key == "menuPrintByAnyPolygonRegion")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!", "提示");
                    return;
                }
                ICommand pArePrintMapClass = new ExportMapProj.AreaPrintMapClass(this.mapCtlMain.Map);
                pArePrintMapClass.OnCreate(this.mapCtlMain.Object);
                this.mapCtlMain.CurrentTool = (ITool)pArePrintMapClass;
                mapCtlMain.ActiveView.Refresh();
            }

            if (e.Command.Key == "menuExportMap")
            {
                ICommand pExportMapAsPicture = new ExportMapProj.CmdExoprtMapAsPicture();
                pExportMapAsPicture.OnCreate(m_pageLayoutControl.Object);
                pExportMapAsPicture.OnClick();

            }
            #endregion

            #region 要素编辑
            if (e.Command.Key == "menuStart")
            {

                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先加载数据!");
                    return;
                }
                m_Map = mapCtlMain.Map;

                IFeatureLayer feaLayer = null;
                IDataset dataSet = null;
                IWorkspaceEdit wsEdit = null;
                for (int i = 0; i < m_Map.LayerCount; i++)
                {
                    if (m_Map.get_Layer(i) is IFeatureLayer)
                    {
                        feaLayer = m_Map.get_Layer(i) as IFeatureLayer;
                        dataSet = (IDataset)feaLayer.FeatureClass;
                        wsEdit = dataSet.Workspace as IWorkspaceEdit;
                        uiComboBox5.Items.Add(m_Map.get_Layer(i).Name);
                    }

                    if (wsEdit.IsBeingEdited()==true)
                    {
                        return;
                    }
                }

                this.menuStart.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                this.menuStop2.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuSketch1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuSaveEditing2.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuDelete1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuRedoEditing1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuUndoEditing1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuTask1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuLayer1.Enabled = Janus.Windows.UI.InheritableBoolean.True;

                uiComboBox5.SelectedIndex = 0;
                for (int i = 0; i < m_Map.LayerCount; i++)
                {
                    if (m_Map.get_Layer(i).Name == uiComboBox5.Text)
                    {
                        m_CurrentLayer = m_Map.get_Layer(i);
                        break;
                    }
                }
                m_bModify = false;
                m_bSketch = true;
                uiComboBox4.SelectedIndex = 0;
                StartEditing();
                MapEditing.CreatShape m_CreateShapeStart = new CreatShape(m_CurrentLayer,this.m_dig);
                mapCtlMain.CurrentTool = (ITool)m_CreateShapeStart;
                m_CreateShapeStart.OnCreate(this.mapCtlMain.Object);
            }

            if (e.Command.Key == "menuStop")
            {
                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请加载数据!");
                    return;
                }
                if (StopEditing() == 1)
                {
                    mapCtlMain.Map.ClearSelection();
                    mapCtlMain.ActiveView.Refresh();
                    mapCtlMain.MousePointer = esriControlsMousePointer.esriPointerDefault;
                    this.menuStart.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                    this.menuStop2.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuSketch1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuSaveEditing2.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.uiComboBox4.Text = "";
                    this.uiComboBox5.Text ="";
                    this.menuDelete1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuRedoEditing1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuUndoEditing1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuTask1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuLayer1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.uiComboBox5.Items.Clear();
                }
            }

            if (e.Command.Key == "menuSaveEditing")
            {
                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请加载数据!");
                    return;
                }
                if (SaveEditing() == 1)
                {
                    mapCtlMain.Map.ClearSelection();
                    mapCtlMain.ActiveView.Refresh();
                }
            }

            if (e.Command.Key == "menuSketch")        //草图画笔工具
            {
                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请加载数据!");
                    return;
                }
                if (m_bSketch)
                {
                    CreatShape m_CreateShapeSketch = new CreatShape(m_CurrentLayer,this.m_dig);
                    mapCtlMain.CurrentTool = (ITool)m_CreateShapeSketch;
                    m_CreateShapeSketch.OnCreate(this.mapCtlMain.Object);
                }
                else if (m_bModify)
                {
                    ModifyShape m_ModifyShape = new ModifyShape(m_CurrentLayer);
                    mapCtlMain.CurrentTool = (ITool)m_ModifyShape;
                    m_ModifyShape.OnCreate(this.mapCtlMain.Object);
                }
                else if (m_bEditNode)
                {

                }
                else
                {
                    MessageBox.Show("编辑操作尚未开始,请先开始编辑!");
                    return;
                }
                StartEditing();//开始编辑
            }

            if (e.Command.Key == "menuDelete")
            {
                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先加载数据!");
                    return;
                }
                DeleteSelectedFeatures();            //调用删除要素方法
            }

            if (e.Command.Key == "menuUndoEditing")
            {
                if (m_CurrentLayer == null)
                    return;
                IWorkspaceEdit pWorkSpaceEdit = GetWorkspaceEdit();
                bool bHasUndos = false;
                pWorkSpaceEdit.HasUndos(ref bHasUndos);
                if (bHasUndos)
                    pWorkSpaceEdit.UndoEditOperation();
                IActiveView pActiveView = m_Map as IActiveView;
                pActiveView.Refresh();
            }

            if (e.Command.Key == "menuRedoEditing")
            {
                if (m_CurrentLayer == null)
                    return;
                IWorkspaceEdit pWorkSpaceEdit = GetWorkspaceEdit();
                bool bHasRedo = false;
                pWorkSpaceEdit.HasRedos(ref bHasRedo);
                if (bHasRedo)
                    pWorkSpaceEdit.RedoEditOperation();
                IActiveView pActiveView = m_Map as IActiveView;
                pActiveView.Refresh();
            }
            #endregion

            if (e.Command.Key == "menuSelectbyAttribute")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }
                QueryForm pQueryForm = new QueryForm(this.m_mapControl);
                pQueryForm.Show();
            }

            if (e.Command.Key == "menuSelectbyLocation")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }
                SpatialQueryForm pSpatialQueryForm = new SpatialQueryForm(this.m_mapControl);
                pSpatialQueryForm.Show();
            }

            if (e.Command.Key == "menuBuffer")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }
                BufferForm pBufferForm = new BufferForm(this.m_mapControl);
                pBufferForm.Show();
            }

            if (e.Command.Key == "menuOverLay")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }
                OverLayerForm pOverLayerForm = new OverLayerForm(this.m_mapControl);
                pOverLayerForm.Show();
            }

            if (e.Command.Key == "menu3DForm")
            {
                if (e.Command.Checked == Janus.Windows.UI.InheritableBoolean.False)
                {
                    this.ThreeDtap.TabVisible = true;
                    this.mapTab.Enabled = false;
                    this.pageTab.Enabled = false;
                    this.uiTab1.SelectedTab = this.ThreeDtap;

                    this.ThreeDBar.Visible = true;

                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.True;
                    this.axTOCControl1.SetBuddyControl(this.axSceneControl1);
                }
                else
                {
                    this.ThreeDtap.TabVisible = false;
                    this.mapTab.Enabled = true;
                    this.pageTab.Enabled = true;
                    this.uiTab1.SelectedTab = this.mapTab;
                    this.ThreeDBar.Visible = false;
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.False;
                    this.axSceneControl1.CurrentTool = null;
                    this.axSceneControl1.Scene.ClearLayers();
                    this.axTOCControl1.SetBuddyControl(this.mapCtlMain);
                }

            }

            if (e.Command.Key == "menuCacu")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }

                ICommand ff = new AreaPrintMapClass();
                ff.OnCreate(this.m_mapControl);
                this.m_mapControl.CurrentTool = (ITool)ff;

            }

            if (e.Command.Key == "menuRasDis")
            {
                this.mapCtlMain.CurrentTool = null;
                bool isRaster = false;
                ILayer layer = null;
                for (int i = 0; i < this.mapCtlMain.LayerCount; i++)
                {
                    layer = this.mapCtlMain.get_Layer(i);
                    if (layer is IRasterLayer)
                    {
                        isRaster = true;
                        break;
                    }
                }
                if (isRaster == false)
                {
                    MessageBox.Show("请先添加影像数据!", "提示");
                    return;
                }
                this.m_rasterMeasureDis = true;
                this.mapCtlMain.MousePointer = esriControlsMousePointer.esriPointerCrosshair;

            }

            if (e.Command.Key == "menuRasArea")
            {
                this.mapCtlMain.CurrentTool = null;
                bool isRaster = false;
                ILayer layer = null;

                for (int i = 0; i < this.mapCtlMain.LayerCount; i++)
                {
                    layer = this.mapCtlMain.get_Layer(i);
                    if (layer is IRasterLayer)
                    {
                        isRaster = true;
                        break;
                    }
                }
                if (isRaster == false)
                {
                    MessageBox.Show("请先添加影像数据!", "提示");
                    return;
                }
                this.m_rasterMeasureArea = true;
                this.mapCtlMain.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
            }

            if (e.Command.Key == "menuTemplate")
            {
                ChoseTemple chosetem = new ChoseTemple();
                chosetem.ShowDialog();
                if (chosetem.m_templateName != "")
                {
                    this.axPageLayoutControl1.ActiveView.Clear();
                    if (chosetem.m_templateName.Contains("\\"))
                    {
                        this.axPageLayoutControl1.LoadMxFile(chosetem.m_templateName, Type.Missing);
                    }
                    else
                    {
                        this.axPageLayoutControl1.LoadMxFile(System.Windows.Forms.Application.StartupPath + @"\pagelayoutTemplate\" + chosetem.m_templateName, Type.Missing);
                    }
                    m_controlsSynchronizer.ReplaceMap(m_mapControl.Map);//重新联动

                    SetMapFrame();
                    m_pageLayoutControl.ActiveView.ShowScrollBars = true;

                }
            }

            if (e.Command.Key == "menuAbout")
            {
                frmAbout frmAbout = new frmAbout();
                frmAbout.ShowDialog();
            }

            if (e.Command.Key == "menuTOCControl")
            {
                if (this.menuTOCControl1.Checked == Janus.Windows.UI.InheritableBoolean.True)
                {
                    this.TOCPanel.Visible = false;
                    this.menuTOCControl1.Checked = Janus.Windows.UI.InheritableBoolean.False;
                }
                else
                {
                    this.TOCPanel.Visible = true;
                    this.menuTOCControl1.Checked = Janus.Windows.UI.InheritableBoolean.True;
                }
            }

            if (e.Command.Key == "menuAtrriWin")
            {
                if (this.menuAtrriWin1.Checked == Janus.Windows.UI.InheritableBoolean.True)
                {
                    this.SearchPanel.Closed = true;
                    this.menuAtrriWin1.Checked = Janus.Windows.UI.InheritableBoolean.False;
                }
                else
                {
                    this.SearchPanel.Closed = false;
                    this.menuAtrriWin1.Checked = Janus.Windows.UI.InheritableBoolean.True;
                }
            }

            if (e.Command.Key == "menuOut")
            {
                if (e.Command.Checked == Janus.Windows.UI.InheritableBoolean.True)
                {
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.False;
                    m_out = false;
                }
                else
                {
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.True;
                    m_out = true;
                    this.mapCtlMain.ClearLayers();

                    IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
                    IWorkspace workspace;
                    workspace = workspaceFactory.OpenFromFile(Application.StartupPath + "\\out", 0); //inPath栅格数据存储路径
                    IRasterWorkspace rastWork = (IRasterWorkspace)workspace;
                    IRasterDataset rastDataset;
                    rastDataset = rastWork.OpenRasterDataset("ps2010.img");//inName栅格文件名
                    IRasterLayer layer = new RasterLayerClass();
                    layer.CreateFromDataset(rastDataset);
                    m_mapControl.AddLayer(layer, 0);
                    m_mapControl.AddShapeFile(Application.StartupPath + "\\out", "WYDCZL.shp");

                    m_mapControl.ActiveView.Refresh();
                }

            }
            if (e.Command.Key == "menuDig")
            {
                if (e.Command.Checked == Janus.Windows.UI.InheritableBoolean.False)
                {
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.True;
                    this.m_dig = true;
                }
                else
                {
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.False;
                    this.m_dig = false;
                }
            }

            if (e.Command.Key == "menuIndexCacu")
            {
                frmCacuIndex index = new frmCacuIndex();
                index.ShowDialog();
            }

            if (e.Command.Key == "menuSKC")
            {
                frmChart chart = new frmChart(this.m_oraCmd);
                chart.ShowDialog();
            }
            //******************************增加----陈*************************************************
            //if (e.Command.Key == "menuKMEANS")
            //{
            //    KMEANS kMEANS = new KMEANS(m_mapControl);
            //    kMEANS.ShowDialog();
            //}
            //if (e.Command.Key == "menuCalibration")
            //{
            //    OpenFileDialog openGD = new OpenFileDialog();
            //    openGD.Filter = "ERDAS格式(*.img)|*.img|所有文件|*.*";
            //    if (openGD.ShowDialog() == DialogResult.OK)
            //    {
            //        string filename = openGD.FileName;
            //        int bandCount;
            //        try
            //        {
            //            IRasterLayer rasterLayer = new RasterLayerClass();
            //            rasterLayer.CreateFromFilePath(filename);
            //            bandCount = rasterLayer.BandCount;
            //        }
            //        catch
            //        {
            //            MessageBox.Show("输入文件有误");
            //            return;
            //        }
            //        Calibration cali = new Calibration(filename, bandCount, m_mapControl);
            //        cali.ShowDialog();
            //    }

            //}
            //if (e.Command.Key == "menuISODATA")
            //{
            //    ISODATA isodata = new ISODATA(m_mapControl);
            //    isodata.ShowDialog();
            //}
            //if (e.Command.Key == "menuNDVI")
            //{
            //    NDVI ndvi = new NDVI(m_mapControl);
            //    ndvi.ShowDialog();
            //}
            //if (e.Command.Key == "menuRVI")
            //{
            //    RVI rvi = new RVI(m_mapControl);
            //    rvi.ShowDialog();
            //}
            //if (e.Command.Key == "menuSAVI")
            //{
            //    SAVI savi = new SAVI(m_mapControl);
            //    savi.ShowDialog();
            //}
            //if (e.Command.Key == "menuVC")
            //{
            //    VegCover vegCover = new VegCover(m_mapControl);
            //    vegCover.ShowDialog();
            //}
            //if (e.Command.Key == "menuTemprature")
            //{
            //    Temperature temperature = new Temperature(m_mapControl);
            //    temperature.ShowDialog();
            //}
            //if (e.Command.Key == "menuChangeD")
            //{
            //    ChangeDetection changeD = new ChangeDetection(m_mapControl);
            //    changeD.ShowDialog();

            //}
            //if (e.Command.Key == "menuIce")
            //{
            //    IceExtract iceExtract = new IceExtract(m_mapControl);
            //    iceExtract.ShowDialog();
            //}
            //if (e.Command.Key == "menuWater")
            //{
            //    WaterExtract waterExtract = new WaterExtract(m_mapControl);
            //    waterExtract.ShowDialog();

            //}
            //if (e.Command.Key == "menuHOT")
            //{
            //    HOT hot = new HOT(m_mapControl);
            //    hot.ShowDialog();

            //}
            //if (e.Command.Key == "menuQAC")
            //{
            //    QAC qac = new QAC(m_mapControl);
            //    qac.ShowDialog();
            //}
            //if (e.Command.Key == "menuLUC")
            //{
            //    LandUseChange luc = new LandUseChange(m_mapControl);
            //    luc.ShowDialog();
            //}
            //if (e.Command.Key == "menuComposite")
            //{
            //    Composite comp = new Composite(m_mapControl);
            //    comp.ShowDialog();
            //}
            //*****************************************************************************************
        }
Esempio n. 45
0
        private void treeVSDE_AfterCheck(object sender, TreeViewEventArgs e)
        {
            IFeatureLayer feaLyr;
            if (e.Node.Checked == true)
            {
                if (e.Node.Tag.ToString() == "point" || e.Node.Tag.ToString() == "line" || e.Node.Tag.ToString() == "polygon" ||e.Node.Tag.ToString() == "Annotation")
                {
                    if (e.Node.Parent.Tag.ToString() == "PLACE")
                    {
                        feaLyr = m_gdata.AddFeatureClassToMap(e.Node.Parent.Text.ToString()+"_" + e.Node.Text.ToString());
                        feaLyr.Name = e.Node.Text.ToString();
                        this.mapCtlMain.Map.AddLayer(feaLyr);
                    }
                    else
                    {
                        feaLyr = m_gdata.AddFeatureClassToMap(e.Node.Text.ToString());
                        feaLyr.Name = e.Node.Text.ToString();
                        this.mapCtlMain.Map.AddLayer(feaLyr);
                    }

                }
                if (e.Node.Tag.ToString() == "Raster")
                {
                    IRasterWorkspaceEx rasterWS = m_workSpace as IRasterWorkspaceEx;
                    IRasterDataset rasterDS = rasterWS.OpenRasterDataset(e.Node.Parent.Text.ToString()+"_"+ e.Node.Text.ToString());
                    IRasterLayer rasterLayer = new RasterLayerClass();
                    rasterLayer.CreateFromDataset(rasterDS);
                    rasterLayer.Name = e.Node.Text;
                    this.mapCtlMain.Map.AddLayer(rasterLayer);
                    this.mapCtlMain.Refresh();
                }
            }
            else
            {
                if (e.Node.Tag.ToString() == "point" || e.Node.Tag.ToString() == "line" || e.Node.Tag.ToString() == "polygon"|| e.Node.Tag.ToString() == "Annotation")
                {
                    for (int i = 0; i < this.mapCtlMain.Map.LayerCount; i++)
                    {
                        ILayer layer=this.mapCtlMain.Map.get_Layer(i);
                        if(e.Node.Text.ToString()==layer.Name.ToString())
                        {
                            this.mapCtlMain.Map.DeleteLayer(layer);
                            this.mapCtlMain.ActiveView.Refresh();
                        }
                    }
                }

                if (e.Node.Tag.ToString() == "Raster")
                {
                    ILayer layer;
                    for (int i = 0; i < this.mapCtlMain.Map.LayerCount; i++)
                    {
                        layer = this.mapCtlMain.Map.get_Layer(i);
                        if (layer.Name.ToString()==e.Node.Text.ToString())
                        {
                            this.mapCtlMain.Map.DeleteLayer(layer);
                            this.mapCtlMain.ActiveView.Refresh();
                        }
                    }
                }
                if (this.mapCtlMain.Map.LayerCount == 0)
                {
                    this.mapCtlMain.SpatialReference = null;
                    this.StatusBar.Panels[2].Text = "";
                    this.StatusBar.Panels[3].Text = "";

                }
            }
        }
Esempio n. 46
0
        /// <summary>
        ///对Raster根据数据行进行渲染,可以渲染成单通道灰度显示和RGB合成显示
        /// </summary>
        /// <param name="renderType">渲染方式调节</param>
        /// <returns></returns>
        public IRasterLayer RasterRenderedLayer(IRasterLayer pRL, bool renderType, int grayBandIndex, int[] rgbBandIndex)
        {
            //实例新的栅格图层
            IRasterLayer rlayer = new RasterLayerClass();

            string fullPath = pRL.FilePath;
            IRasterDataset rasterDataset = OpenFileRasterDataset(fullPath);

            //单波段
            if (rgbBandIndex == null)
            {
                //如果grayBandIndex=-1
                try
                {
                    IRasterRenderer render = null;
                    render = BandCombinationShow.StretchRenderer(rasterDataset, grayBandIndex);
                    rlayer.CreateFromDataset(rasterDataset);
                    rlayer.Renderer = render as IRasterRenderer;
                    return rlayer;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return null;
                }
            }
            else//多波段显示
            {

                try
                {
                    if (!renderType)
                    {
                        IRasterRenderer render = BandCombinationShow.StretchRenderer(rasterDataset, grayPos);
                        rlayer.CreateFromDataset(rasterDataset);
                        rlayer.Renderer = render as IRasterRenderer;
                    }
                    else
                    {
                        //设置彩色合成顺序 生成新的渲染模式
                        IRasterRGBRenderer render = new RasterRGBRendererClass();
                        render.RedBandIndex = rgbBandIndex[0];
                        render.GreenBandIndex = rgbBandIndex[1];
                        render.BlueBandIndex = rgbBandIndex[2];

                        IRasterStretch stretchType = (IRasterStretch)render;
                        stretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
                        stretchType.StandardDeviationsParam = 2;

                        rlayer.CreateFromDataset(rasterDataset);
                        rlayer.Renderer = render as IRasterRenderer;

                    }

                    return rlayer;

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return null;
                }
            }
        }
Esempio n. 47
0
        private void 改变像素的值ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IRasterWorkspace pRasterWs = GetRasterWorkspace(@".\data\IDW数据");

              IRasterDataset pRasterDataset = pRasterWs.OpenRasterDataset("MOD02HKM.A2010068.0310.005.2010069144441.GEO.tif");
              IRasterLayer pRasterLayer = new RasterLayerClass();

              pRasterLayer.CreateFromDataset(pRasterDataset);

              axMapControl1.Map.AddLayer(pRasterLayer as ILayer); ;

              ChangeNodataValue(pRasterDataset as IRasterDataset2);
              axMapControl1.Refresh();
        }
Esempio n. 48
0
        public bool SwitchPasture(string strName)
        {
            m_activePasture = GetPastureByName(strName);
            if (m_activePasture.strPasture == string.Empty)
                return false;

            //
            m_pastureMap = new Map();
            m_pastureMap.Name = m_activePasture.strPasture;

            IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace workspace =
                (IFeatureWorkspace)workspaceFactory.OpenFromFile(m_activePasture.strDataDir,0);

            DirectoryInfo pastureDir = new DirectoryInfo(m_activePasture.strDataDir);
            FileInfo[] files = pastureDir.GetFiles("*.shp");
            foreach (FileInfo file in files)
            {
                IFeatureLayer featureLayer = new FeatureLayerClass();
                featureLayer.Name = file.Name;
                featureLayer.Visible = true;
                featureLayer.FeatureClass = workspace.OpenFeatureClass(file.Name);

                m_pastureMap.AddLayer(featureLayer);
            }

            //////////////////////////////////////////////////////////////////////////
            if (m_activePasture.strRasLyr != string.Empty)
            {
                IWorkspaceFactory rasWksFactory = new RasterWorkspaceFactory();
                IRasterWorkspace rasWks = rasWksFactory.OpenFromFile(m_activePasture.strDataDir, 0) as IRasterWorkspace;
                IRasterDataset rasDataset = rasWks.OpenRasterDataset(m_activePasture.strRasLyr);

                IRasterLayer rasLyr = new RasterLayerClass();
                rasLyr.CreateFromDataset(rasDataset);
                LayerHelper.SetLayerColor(rasLyr);

                if (m_adminMap.LayerCount == 3)
                {
                    m_adminMap.AddLayer(rasLyr);
                    m_adminMap.MoveLayer(rasLyr,3);
                }
                else if(m_adminMap.LayerCount == 4)
                {
                    ILayer lyr = m_adminMap.get_Layer(3);
                    if (null != lyr)
                        m_adminMap.DeleteLayer(lyr);

                    m_adminMap.AddLayer(rasLyr);
                    m_adminMap.MoveLayer(rasLyr,3);
                }
            }

            //////////////////////////////////////////////////////////////////////////
            Queue<TreeNode> vistor_queue = new Queue<TreeNode>();
            vistor_queue.Enqueue(m_tree.Nodes[0]);
            while (vistor_queue.Count > 0)
            {
                TreeNode node = vistor_queue.Dequeue();
                if (node.Text == strName)
                    node.ForeColor = Color.BlueViolet;
                else
                    node.ForeColor = Color.Black;

                TreeNode child = node.FirstNode;
                while (null != child)
                {
                    vistor_queue.Enqueue(child);
                    child = child.NextNode;
                }

                return true;
            }

            return false;
        }
Esempio n. 49
0
        public static void AddData_RST(AxMapControl axMapControl1)
        {
            IWorkspaceFactory pWorkspaceFactory;
            IRasterWorkspace pRasterWorkspace;
            OpenFileDialog openFileDialog2 = new OpenFileDialog();
            openFileDialog2.Filter = "Layer File(*.lyr)|*.jpg;*.bmp;*.tiff";
            openFileDialog2.Title = "添加数据";

            //获取当前路径和文件名
            if (openFileDialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string strFullPath = openFileDialog2.FileName;
                if (strFullPath == "") return;
                int Index = strFullPath.LastIndexOf("\\");
                string fileName = strFullPath.Substring(Index + 1);
                string filePath = strFullPath.Substring(0, Index);
                pWorkspaceFactory = new RasterWorkspaceFactoryClass();
                pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
                IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(fileName);
                IRasterLayer pRasterLayer = new RasterLayerClass();
                pRasterLayer.CreateFromDataset(pRasterDataset);
                axMapControl1.Map.AddLayer(pRasterLayer);

                ILayer layer = axMapControl1.get_Layer(0);
                axMapControl1.Extent = layer.AreaOfInterest;
            }
        }
Esempio n. 50
0
        public static void OpenRasterDataset(AxMapControl MapControl,
            IRasterDatasetName pRdName, ListView listview1)
        {
            MapControl.ClearLayers();
            MapControl.SpatialReference = null;
            listview1.Items.Clear();
            listview1.Columns.Clear();
            IDatasetName pDsName = pRdName as IDatasetName;
            string sName = pDsName.Name;

            IName pName = pRdName as IName;

            IRasterDataset pRds = pName.Open() as IRasterDataset;
            IRasterLayer pRL = new RasterLayerClass();
            pRL.CreateFromDataset(pRds);
            pRL.Name = sName;
            MapControl.AddLayer(pRL as ILayer);
            MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
 /// <summary>
 /// adds a layer to the active view
 /// </summary>
 /// <param name="path">full path name</param>
 /// <returns>Ilayer</returns>
 public ILayer addLayer(string path)
 {
     IMap map = (IMap)acView;
     geoDatabaseUtility geoUtil = new geoDatabaseUtility();
     esriDatasetType dType = geoUtil.getDataType(path);
     ILayer lyr = null;
     switch(dType)
     {
         case esriDatasetType.esriDTFeatureClass:
             IFeatureLayer ftrLayer = new FeatureLayerClass();
             ftrLayer.FeatureClass = geoUtil.getFeatureClass(path);
             lyr = (ILayer)ftrLayer;
             lyr.Name = ftrLayer.FeatureClass.AliasName;
             map.AddLayer(lyr);
             break;
         case esriDatasetType.esriDTRasterBand:
         case esriDatasetType.esriDTRasterCatalog:
         case esriDatasetType.esriDTRasterDataset:
             IRasterLayer rasterLayer = new RasterLayerClass();
             rasterLayer.CreateFromDataset(geoUtil.getRasterDataset(path));
             rasterLayer.Name = rasterLayer.Name;
             map.AddLayer((ILayer)rasterLayer);
             break;
         case esriDatasetType.esriDTTable:
             ITable tbl = geoUtil.getTable(path);
             ITableCollection tableCollection = (ITableCollection)map;
             tableCollection.AddTable(tbl);
             break;
         default:
             break;
     }
     acView.Refresh();
     return lyr;
 }
Esempio n. 52
0
        private void 创建栅格数据集ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ISpatialReference pSr = new UnknownCoordinateSystemClass();

              IRasterDataset  pRasterDataset= CreateRasterDataset(@".\data\IDW数据", "RTest","TIFF", pSr);

              IRasterLayer pRasterLayer = new RasterLayerClass();

              pRasterLayer.CreateFromDataset(pRasterDataset);

              axMapControl1.Map.AddLayer(pRasterLayer);
        }