Example #1
0
        private void ConvertRasterToRsDataset(String sPath, ref IRaster pRaster, String sOutName)
        {
            try
            {
                IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                if (pWSF.IsWorkspace(sPath) == false)
                {
                    return;
                }

                IWorkspace pRWS = pWSF.OpenFromFile(sPath, 0);

                if (System.IO.File.Exists(sPath + "\\" + sOutName + ".img") == true)
                {
                    System.IO.File.Delete(sPath + "\\" + sOutName + ".img");
                }


                IRasterBandCollection pRasBandCol = (IRasterBandCollection)pRaster;

                IDataset          pDS    = pRasBandCol.SaveAs(sOutName + ".img", pRWS, "IMAGINE Image");
                ITemporaryDataset pRsGeo = (ITemporaryDataset)pDS;
                if (pRsGeo.IsTemporary())
                {
                    pRsGeo.MakePermanent();
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        //Open RasterDataset by pathName and fileName
        public IRasterDataset openRasterDataset(string pathName, string fileName)
        {
            IWorkspaceFactory workspaceFactory;
            IRasterWorkspace  rasterWorkspace;
            IRasterDataset    rasterDataset = null;

            workspaceFactory = new RasterWorkspaceFactoryClass();

            //注意程序的健壮性一定要对路径的提前判断
            if (workspaceFactory.IsWorkspace(pathName) == true)
            {
                rasterWorkspace = workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspace;
                rasterDataset   = rasterWorkspace.OpenRasterDataset(fileName);
            }
            return(rasterDataset);
        }
Example #3
0
 /// <summary>
 /// 加载栅格数据文件
 /// </summary>
 /// <param name="axMapControl">地图控件引用</param>
 /// <param name="strFilePath">文件路径</param>
 /// <returns>正常:“”,异常:异常字符;</returns>
 private SystemErrorType LoadRasterFile(ref AxMapControl axMapControl, string strFilePath)
 {
     if (strFilePath == "")
     {
         return(SystemErrorType.enumFilePathIsNull);
     }
     try
     {
         IWorkspaceFactory pWorkspaceFactory = null;
         IRasterWorkspace  pRasterWorkspace  = null;
         IRasterDataset    pRasterDataset    = null;
         IRasterLayer      pRasterLayer      = null;
         String            WorkspacePath     = strFilePath.Substring(0, strFilePath.LastIndexOf('\\'));//e.g.     c:/data/a.shp
         pWorkspaceFactory = new RasterWorkspaceFactoryClass() as IWorkspaceFactory;
         //如果符合要求 , 打开栅格数据文件并加载到地图控件中。
         if (pWorkspaceFactory.IsWorkspace(WorkspacePath))
         {
             pRasterWorkspace = pWorkspaceFactory.OpenFromFile(WorkspacePath, 0) as IRasterWorkspace;
             pRasterDataset   = pRasterWorkspace.OpenRasterDataset(strFilePath.Substring(strFilePath.LastIndexOf('\\') + 1));
             pRasterLayer     = new RasterLayerClass() as IRasterLayer;
             pRasterLayer.CreateFromDataset(pRasterDataset);
             axMapControl.ClearLayers();
             axMapControl.AddLayer(pRasterLayer);
             axMapControl.ActiveView.Refresh();      //axMapControl.Extent = axMapControl.FullExtent;
         }
         else
         {
             return(SystemErrorType.enumDataIsIllegal);
         }
     }
     catch (Exception)
     {
         return(SystemErrorType.enumArcObjectHandleError);
     }
     return(SystemErrorType.enumOK);
 }
Example #4
0
 //
 //
 //
 public static void ConvertRasterToRsDataset(string sPath, IRaster pRaster, string sOutName)
 {
     try
     {
         IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
         if (pWSF.IsWorkspace(sPath) == false)
             return;
         IWorkspace pRWS = pWSF.OpenFromFile(sPath, 0);
         if (File.Exists(sPath + "\\" + sOutName + ".img") == true)
             File.Delete(sPath + "\\" + sOutName + ".img");
         //IRasterDescriptor pRasterDes = new RasterDescriptorClass();
         //pRasterDes.Create(pRaster, null, "Value");
         IRasterBandCollection pRasBandCol = pRaster as IRasterBandCollection;
         //DeleteFile(sPath,sOutName);
         IDataset pDS = pRasBandCol.SaveAs(sOutName + ".img", pRWS, "IMAGINE Image");
         ITemporaryDataset pRsGeo = pDS as ITemporaryDataset;
         if (pRsGeo.IsTemporary())
             pRsGeo.MakePermanent();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Example #5
0
        //
        //��դ�����ݼ�
        //
        public static IRasterDataset OpenRasterDataset(string sDir, string sName)
        {
            try
            {
                IRasterDataset pRSD = null;
                IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                if (pWSF.IsWorkspace(sDir))
                {
                    IWorkspace pWS = pWSF.OpenFromFile(sDir, 0);
                    IRasterWorkspace pRsWs = pWS as IRasterWorkspace;
                    pRSD = pRsWs.OpenRasterDataset(sName);
                }
                return pRSD;
            }
            catch
            {

                  return null;
            }
        }
Example #6
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;
                    }
                }
            }
        }
Example #7
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;
                    }
                }
            }
        }
Example #8
0
 //���������ݵ��ļ���
 private void btnOpenPcp_Click(object sender, EventArgs e)
 {
     FolderBrowserDialog pFBD = new FolderBrowserDialog();
     pFBD.Description = "��ѡ��ˮդ���������ڵ��ļ���";
     DialogResult pDr = pFBD.ShowDialog();
     if (pDr == DialogResult.OK)
     {
         IWorkspaceFactory pWsF;
         pWsF = new RasterWorkspaceFactoryClass();
         if(pWsF.IsWorkspace(pFBD.SelectedPath))
         {
             this.txtPcpPath.Text = pFBD.SelectedPath;
         }
         else
         {
             MessageBox.Show("����ѡ���·��������դ�����ݣ�������ѡ��","��ʾ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
             return;
         }
     }
 }
Example #9
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;
                    }

                }
            }
        }
Example #10
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;
                    }

                }
            }
        }
Example #11
0
        //Open RasterDataset by pathName and fileName
        public IRasterDataset openRasterDataset(string pathName, string fileName)
        {
            IWorkspaceFactory workspaceFactory;
            IRasterWorkspace rasterWorkspace;
            IRasterDataset rasterDataset = null;

            workspaceFactory = new RasterWorkspaceFactoryClass();

            //ע�����Ľ�׳��һ��Ҫ��·������ǰ�ж�
            if (workspaceFactory.IsWorkspace(pathName) == true)
            {
                rasterWorkspace = workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspace;
                rasterDataset = rasterWorkspace.OpenRasterDataset(fileName);
            }
            return rasterDataset;
        }