Exemple #1
2
 public static void LoadGeoData(AxMapControl axMapControl1, AxMapControl axMapControl2, string strFileN)
 {
     string strFExtenN = System.IO.Path.GetExtension(strFileN);
     switch (strFExtenN)
     {
         case ".shp":
             {
                 string strPath = System.IO.Path.GetDirectoryName(strFileN);
                 string strFile = System.IO.Path.GetFileNameWithoutExtension(strFileN);
                 axMapControl1.AddShapeFile(strPath, strFile);
                 axMapControl2.ClearLayers();
                 axMapControl2.AddShapeFile(strPath, strFile);
                 axMapControl2.Extent = axMapControl2.FullExtent;
                 break;
             }
         case ".bmp":
         case ".tif":
         case ".jpg":
         case ".img":
             {
                 IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                 string pathName = System.IO.Path.GetDirectoryName(strFileN);
                 string fileName = System.IO.Path.GetFileName(strFileN);
                 IWorkspace pWS = pWSF.OpenFromFile(pathName, 0);
                 IRasterWorkspace pRWS = pWS as IRasterWorkspace;
                 IRasterDataset pRasterDataSet = pRWS.OpenRasterDataset(fileName);
                 IRasterPyramid pRasPyramid = pRasterDataSet as IRasterPyramid;
                 if (pRasPyramid != null)
                 {
                     if (!(pRasPyramid.Present))
                     {
                         pRasPyramid.Create();
                     }
                 }
                 IRaster pRaster = pRasterDataSet.CreateDefaultRaster();
                 IRasterLayer pRasterLayer = new RasterLayerClass();
                 pRasterLayer.CreateFromRaster(pRaster);
                 ILayer pLayer = pRasterLayer as ILayer;
                 axMapControl1.AddLayer(pLayer, 0);
                 axMapControl2.ClearLayers();
                 axMapControl2.AddLayer(pLayer, 0);
                 axMapControl2.Extent = axMapControl2.FullExtent;
                 break;
             }
         case ".mxd":
             {
                 if (axMapControl1.CheckMxFile(strFExtenN))
                 {
                     axMapControl1.LoadMxFile(strFExtenN);
                 }
                 else
                     MessageBox.Show("所选择的文件不是Mxd文件!", "提示信息");
                 break;
             }
         default:
             break;
     }
 }
Exemple #2
0
        /// <summary>
        /// 计算DEM坡向
        /// </summary>
        /// <param name="rasterLayer">输入DEM图层</param>
        /// <param name="outputFullPath">输出坡度图路径,类型为IMAGE,文件名为img</param>
        public void CreateRasterAspect(ILayer rasterLayer, string outputFullPath)
        {
            if (File.Exists(outputFullPath))
            {
                MessageBox.Show(outputFullPath + "已经存在,请重命名");
                return;
            }
            IRasterLayer rasterLyr = rasterLayer as IRasterLayer;
            IRaster raster = rasterLyr.Raster;
            RasterSurfaceOpClass rasterOpCls = new RasterSurfaceOpClass();
            IGeoDataset geoDataset = raster as IGeoDataset;
            IGeoDataset outGeodataset = rasterOpCls.Aspect(geoDataset);
            IRaster pRaster = outGeodataset as IRaster;

            FileInfo fi = new FileInfo(outputFullPath);
            string fileDir = fi.Directory.FullName;
            string name = fi.Name;
            if (!Directory.Exists(fileDir))
                Directory.CreateDirectory(fileDir);
            IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
            IWorkspace pWS = pWSF.OpenFromFile(fileDir, 0);
            ISaveAs pSaveAs = pRaster as ISaveAs;
            pSaveAs.SaveAs(name, pWS, "IMAGINE Image");
            IRasterLayer rasterLyr2 = new RasterLayerClass();
            rasterLyr2.CreateFromRaster(pRaster);
            rasterLyr2.Name = name;
            m_mapControl.Map.AddLayer(rasterLyr2 as ILayer);
        }
        //#######################以下函数可配合使用########################

        //**************************Load Raster Begin****************************

        //函数编号:RasterLoad-01
        //函数名:DirToMosaic
        //函数功能:把文件夹中的Raster文件合并到新的Raster文件中去
        //参数:sDir:栅格文件夹
        //      pDataset:最后合并的RasterDataset
        //备注:pDataset可以使Geodataset中的参数,如果不存在利用函数创建
        public void DirToMosaic(string sDir, IRasterDataset pDataset)
        {
            //load all raster datasets in the input directory to the raster dataset
            //the geodatabase raster dataset has to exist,
            //if not create it first with proper storage parameters.
            IWorkspaceFactory pWsFact = new RasterWorkspaceFactoryClass();;
            IWorkspace        pFileWs = pWsFact.OpenFromFile(sDir, 0);

            IRasterDatasetEdit pSDEDs = pDataset as IRasterDatasetEdit;

            IRasterDataset2 pRasterDs;

            // load raster datasets from the dir
            IEnumDataset pEunmDatasets = pFileWs.get_Datasets(esriDatasetType.esriDTRasterDataset);

            pEunmDatasets.Reset();

            pRasterDs = pEunmDatasets.Next() as IRasterDataset2;
            while (!(pRasterDs == null))
            {
                //!!!pRasterDs.CompleteName;
                pSDEDs.Mosaic(pRasterDs.CreateFullRaster(), 0.5);
                //!!!注意IRasterDataset2::CreateFullRaster()方法可以简单实现从RasterDataset到Raster的转换
                pRasterDs = pEunmDatasets.Next() as IRasterDataset2;
            }

            //cleanup

            pEunmDatasets = null;
            pRasterDs     = null;
            pWsFact       = null;
            pSDEDs        = null;
            pFileWs       = null;
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        private IInterpolationOp SetRasterInterpolationAnalysisEnv(String rasterpath, double cellsize, IFeatureLayer pFeatLayer)
        {
            object            Missing = Type.Missing;
            IWorkspaceFactory pWSF;

            pWSF = new RasterWorkspaceFactoryClass();
            IWorkspace                 pWorkspace       = pWSF.OpenFromFile(rasterpath, 0);
            IInterpolationOp           pInterpolationOp = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment pRsEnv           = (IRasterAnalysisEnvironment)pInterpolationOp;

            pRsEnv.OutWorkspace = pWorkspace;
            //装箱操作
            object objCellSize = cellsize;

            pRsEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objCellSize);

            IEnvelope pEnv = new EnvelopeClass();

            pEnv.XMin = pFeatLayer.AreaOfInterest.XMin;
            pEnv.XMax = pFeatLayer.AreaOfInterest.XMax;
            pEnv.YMin = pFeatLayer.AreaOfInterest.YMin;
            pEnv.YMax = pFeatLayer.AreaOfInterest.YMax;
            object objExtent = pEnv;

            pRsEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref Missing);
            return(pInterpolationOp);
        }
Exemple #6
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);
            }
        }
        /// <summary>
        /// 获取栅格工作空间
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns></returns>
        public static IWorkspace GetRasterWorkspace(string filePath)
        {
            string            directory   = Path.GetDirectoryName(filePath);
            IWorkspaceFactory workFactory = new RasterWorkspaceFactoryClass();

            return(workFactory.OpenFromFile(directory, 0));
        }
Exemple #8
0
        private void frmSelectBand_Load(object sender, EventArgs e)
        {
            this.comboBox1.Items.Clear();
            IDataLayer2 dataLayer  = m_rasLayer as IDataLayer2;
            string      dataSource = dataLayer.DataSourceName.NameString;

            if (dataSource.Contains("RASTER")) //Îļþ
            {
                string            path = dataSource.Substring(dataSource.IndexOf('=') + 1, dataSource.IndexOf(';') - dataSource.IndexOf('=') - 2);
                string            name = dataSource.Substring(dataSource.LastIndexOf('=') + 1, dataSource.LastIndexOf(';') - dataSource.LastIndexOf('=') - 1);
                IWorkspaceFactory m_workspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace  rasterWorkspce     = m_workspaceFactory.OpenFromFile(path.Trim(), 0) as IRasterWorkspace;
                IRasterDataset    rasDataset         = rasterWorkspce.OpenRasterDataset(name.Trim());
                m_rc = rasDataset as IRasterBandCollection;
                for (int i = 0; i < m_rc.Count; i++)
                {
                    this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString());
                }
            }
            else
            {
                string             name           = dataSource;
                IRasterWorkspaceEx rasterWorkspce = m_workSpace as IRasterWorkspaceEx;
                IRasterDataset     rasDataset     = rasterWorkspce.OpenRasterDataset(name);
                m_rc = rasDataset as IRasterBandCollection;
                for (int i = 0; i < m_rc.Count; i++)
                {
                    this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString());
                }
            }
        }
        /// <summary>
        /// 执行矢量转栅格
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FtoR_backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            //设置CancellationPending可以退出任务线程
            if (worker.CancellationPending == true)
            {
                e.Cancel = true;
            }
            else
            {
                try
                {
                    FileInfo inputinfo  = new FileInfo(featuretoraster_inputcombox.Text);
                    FileInfo outputinfo = new FileInfo(featuretoraster_output.Text);


                    IWorkspaceFactory outputworkspaceFactory = new RasterWorkspaceFactoryClass();
                    IWorkspace        outputworkspaceop      = outputworkspaceFactory.OpenFromFile(outputinfo.DirectoryName, 0);//创建输出工作空间

                    IWorkspaceFactory       workspacefactory       = new ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace       featureworkspace       = workspacefactory.OpenFromFile(inputinfo.DirectoryName, 0) as IFeatureWorkspace;
                    IFeatureClass           featureclass           = featureworkspace.OpenFeatureClass(inputinfo.Name);
                    IFeatureClassDescriptor featureClassDescriptor = new FeatureClassDescriptorClass();
                    featureClassDescriptor.Create(featureclass, null, featuretoraster_fieldcombox.Text);
                    IGeoDataset geodatasetop = featureClassDescriptor as IGeoDataset;

                    IConversionOp conversionOp = new RasterConversionOpClass();
                    //转换设置
                    IRasterAnalysisEnvironment rasterAnalysisEnvironment = conversionOp as IRasterAnalysisEnvironment;
                    //栅格的大小
                    double dCellSize = Convert.ToDouble(featuretoraster_cellsize.Text);
                    object oCellSize = dCellSize as object;
                    //设置栅格大小
                    rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref oCellSize);
                    string format = "";
                    if (outputinfo.Extension == ".tif")
                    {
                        format = "TIFF";
                    }
                    else if (outputinfo.Extension == ".img")
                    {
                        format = "IMAGINE Image";
                    }
                    else
                    {
                        format = "GRID";
                    }
                    //启动预处理计时
                    watch = new Stopwatch();
                    watch.Start();
                    //执行转换
                    conversionOp.ToRasterDataset(geodatasetop, format, outputworkspaceop, outputinfo.Name);
                }
                catch (Exception erro)
                {
                    MessageBox.Show(erro.Message, "错误");
                }
            }
        }
Exemple #10
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);
        }
Exemple #11
0
        private void GetTask(IList <FileNameCustom> list, string saveDir)
        {
            IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();

            foreach (FileNameCustom fileNameCustom in list)
            {
                string path = fileNameCustom.FilePath;
                if (MyUtils.Utils.CheckFileExists(path))
                {
                    string name     = System.IO.Path.GetFileNameWithoutExtension(path);
                    string saveName = saveDir + "\\" + name + ".img";

                    string pathName = System.IO.Path.GetDirectoryName(path);
                    string fileName = System.IO.Path.GetFileName(path);
                    //定义工作空间工厂并实例化
                    IWorkspace       pWS            = pWSF.OpenFromFile(pathName, 0);
                    IRasterWorkspace pRWS           = pWS as IRasterWorkspace;
                    IRasterDataset   pRasterDataset = pRWS.OpenRasterDataset(fileName);
                    string           str            = pRasterDataset.Format;
                    //影像金字塔的判断与创建
                    IRasterPyramid pRasPyrmid = pRasterDataset as IRasterPyramid;
                    if (pRasPyrmid != null)
                    {
                        if (!pRasPyrmid.Present)
                        {
                            pRasPyrmid.Create();
                        }
                    }
                    IRaster pRaster = pRasterDataset.CreateDefaultRaster();
                    RasterSaveAs(pRaster, saveName);
                }
            }
        }
        /// <summary>
        /// 创建工作空间工厂
        /// </summary>
        /// <returns></returns>
        private static IWorkspaceFactory CreateWksFactory(enumWorkspaceType fileWksType)
        {
            IWorkspaceFactory wksFactory = null;

            switch (fileWksType)
            {
            case enumWorkspaceType.Shapefile:
                wksFactory = new ShapefileWorkspaceFactoryClass();
                break;

            case enumWorkspaceType.Gdb:
                wksFactory = new FileGDBWorkspaceFactoryClass();
                break;

            case enumWorkspaceType.Mdb:
                wksFactory = new AccessWorkspaceFactoryClass();
                break;

            case enumWorkspaceType.Cad:
                wksFactory = new CadWorkspaceFactoryClass();
                break;

            case enumWorkspaceType.RasterFile:
                wksFactory = new RasterWorkspaceFactoryClass();
                break;

            default:
                break;
            }
            return(wksFactory);
        }
Exemple #13
0
        private void IDWInterpolation(IFeatureClass pointFeature, IRaster refRaster, string name)
        {
            IFeatureClassDescriptor pointDescript = new FeatureClassDescriptorClass();

            pointDescript.Create(pointFeature, null, name);
            object                     extend   = (refRaster as IGeoDataset).Extent;
            IRasterProps               refProps = refRaster as IRasterProps;
            object                     cell     = refProps.MeanCellSize().X;
            IInterpolationOp           interpla = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment IDWEnv   = interpla as IRasterAnalysisEnvironment;

            IDWEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cell);
            IDWEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extend);
            IGeoDataset   output = interpla.IDW((IGeoDataset)pointDescript, 2, null, null);
            IGeoDataset   input  = refRaster as IGeoDataset;
            IExtractionOp op     = new RasterExtractionOpClass();

            output = op.Raster(output, input);
            var               clipRaster   = (IRaster)output;
            ISaveAs           pSaveAs      = clipRaster as ISaveAs;
            IWorkspaceFactory workspaceFac = new RasterWorkspaceFactoryClass();
            var               groups       = Regex.Match(name, @"^(\d+)_(\d+)_(\d+)$").Groups;

            name = string.Format("{0:D2}{1:D2}", int.Parse(groups[2].Value), int.Parse(groups[3].Value));
            IDataset outDataset = pSaveAs.SaveAs(fileName + name + ".img", workspaceFac.OpenFromFile(filePath, 0), "IMAGINE Image");

            System.Runtime.InteropServices.Marshal.ReleaseComObject(outDataset);
        }
        //Open file based raster workspace
        static IWorkspace OpenWorkspace(string path)
        {
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
            IWorkspace        rasterWorkspace  = workspaceFactory.OpenFromFile(path, 0);

            return(rasterWorkspace);
        }
Exemple #15
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);
            }
        }
Exemple #16
0
        /// <summary>
        /// Open a Raster file on disk by the given name and file path.
        /// </summary>
        /// <param name="directoryPath">A System.String that is the directory location of the raster file. Example: "C:\raster_data"</param>
        /// <param name="name">A System.String that is the name of the raster file in the directory. Example: "landuse" or "watershed"</param>
        /// <returns></returns>
        /// <remarks>
        /// IRasterWorkspace is used to access a raster stored in a file system in any supported raster format.
        /// RasterWorkspaceFactory must be used to create a raster workspace.
        /// To access raster from geodatabase, use IRasterWorkspaceEx interface.
        /// </remarks>
        public static IRasterDataset OpenRasterFileDataset(string directoryPath, string name)
        {
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace  rasterWorkspace  = (IRasterWorkspace)workspaceFactory.OpenFromFile(directoryPath, 0);

            return(rasterWorkspace.OpenRasterDataset(name));
        }
Exemple #17
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);
        }
Exemple #18
0
        /// <summary>
        /// 获取该栅格图像的相关数据
        /// <remarks>
        /// <list type="bullet">
        /// <item>
        /// <term>
        /// 初始化_pDataset
        /// </term>
        /// <item>
        /// 获取栅格的Height和Width
        /// </item>
        /// </item>
        /// </list>
        /// </remarks>
        /// </summary>
        /// <returns></returns>
        private void Open()
        {
            //Open
            IWorkspaceFactory pRFactory       = new RasterWorkspaceFactoryClass();
            IRasterWorkspace2 rasterWorkspace = pRFactory.OpenFromFile(_rasterWorkSapce, 0) as IRasterWorkspace2;

            if (rasterWorkspace == null)
            {
                throw new ArgumentException("栅格文件无法打开");
            }
            _pDataset = rasterWorkspace.OpenRasterDataset(_rasterName);
            //set height and width

            IRasterProps pRasterProps = (IRasterProps)GetRaster();

            RasterInfo = new RasterInformation()
            {
                Width       = pRasterProps.Width,
                Height      = pRasterProps.Height,
                XCellSize   = pRasterProps.MeanCellSize().X,
                YCellSize   = pRasterProps.MeanCellSize().Y,
                OriginPoint = new PointClass()
                {
                    X = pRasterProps.Extent.XMin, Y = pRasterProps.Extent.YMin
                },
                SpatialReference = ((IGeoDataset)_pDataset).SpatialReference
            };
        }
Exemple #19
0
        /// <summary>
        /// 计算DEM坡向
        /// </summary>
        /// <param name="rasterLayer">输入DEM图层</param>
        /// <param name="outputFullPath">输出坡度图路径,类型为IMAGE,文件名为img</param>
        public void CreateRasterAspect(ILayer rasterLayer, string outputFullPath)
        {
            if (File.Exists(outputFullPath))
            {
                MessageBox.Show(outputFullPath + "已经存在,请重命名");
                return;
            }
            IRasterLayer         rasterLyr     = rasterLayer as IRasterLayer;
            IRaster              raster        = rasterLyr.Raster;
            RasterSurfaceOpClass rasterOpCls   = new RasterSurfaceOpClass();
            IGeoDataset          geoDataset    = raster as IGeoDataset;
            IGeoDataset          outGeodataset = rasterOpCls.Aspect(geoDataset);
            IRaster              pRaster       = outGeodataset as IRaster;

            FileInfo fi      = new FileInfo(outputFullPath);
            string   fileDir = fi.Directory.FullName;
            string   name    = fi.Name;

            if (!Directory.Exists(fileDir))
            {
                Directory.CreateDirectory(fileDir);
            }
            IWorkspaceFactory pWSF    = new RasterWorkspaceFactoryClass();
            IWorkspace        pWS     = pWSF.OpenFromFile(fileDir, 0);
            ISaveAs           pSaveAs = pRaster as ISaveAs;

            pSaveAs.SaveAs(name, pWS, "IMAGINE Image");
            IRasterLayer rasterLyr2 = new RasterLayerClass();

            rasterLyr2.CreateFromRaster(pRaster);
            rasterLyr2.Name = name;
            m_mapControl.Map.AddLayer(rasterLyr2 as ILayer);
        }
 /// <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 + "无效!");
     }
 }
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="pFeatureClass">要素类</param>
        /// <param name="fieldName">栅格采用的字段</param>
        /// <param name="rasterWorkSpace">输出栅格的工作空间</param>
        /// <param name="newRasterName">新的栅格名称</param>
        public void Convert(IFeatureClass pFeatureClass,
            string fieldName,
            string rasterWorkSpace,
            string newRasterName)
        {
            FileHelper.DeleteFile(rasterWorkSpace, newRasterName, ".tif", ".tfw",".tif.aux");
            IFeatureClassDescriptor featureClassDescriptor = new FeatureClassDescriptorClass();
            featureClassDescriptor.Create(pFeatureClass, null, fieldName);
            IGeoDataset geoDataset = (IGeoDataset)featureClassDescriptor;
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();           
            IWorkspace workspace = workspaceFactory.OpenFromFile(rasterWorkSpace, 0);
            IConversionOp conversionOp = new RasterConversionOpClass();
            IRasterAnalysisEnvironment rasterAnalysisEnvironment = (IRasterAnalysisEnvironment)conversionOp;
            rasterAnalysisEnvironment.OutWorkspace = workspace;

       
            //set cell size
            rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _cellSize);
            //set output extent  
            object objectMissing = Type.Missing;
            rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _extentEnvelope, ref objectMissing);
            //set output spatial reference 
            rasterAnalysisEnvironment.OutSpatialReference = ((IGeoDataset)pFeatureClass).SpatialReference;
            //convertion
            conversionOp.ToRasterDataset(geoDataset, _rasterType, workspace, newRasterName);              
        }    
Exemple #22
0
        private void frmSelectBand_Load(object sender, EventArgs e)
        {
            this.comboBox1.Items.Clear();
            IDataLayer2 dataLayer = m_rasLayer as IDataLayer2;
            string dataSource = dataLayer.DataSourceName.NameString;
            if (dataSource.Contains("RASTER")) //�ļ�
            {
                string path = dataSource.Substring(dataSource.IndexOf('=') + 1, dataSource.IndexOf(';') - dataSource.IndexOf('=') - 2);
                string name = dataSource.Substring(dataSource.LastIndexOf('=') + 1, dataSource.LastIndexOf(';') - dataSource.LastIndexOf('=') - 1);
                IWorkspaceFactory m_workspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace rasterWorkspce = m_workspaceFactory.OpenFromFile(path.Trim(), 0) as IRasterWorkspace;
                IRasterDataset rasDataset = rasterWorkspce.OpenRasterDataset(name.Trim());
                m_rc = rasDataset as IRasterBandCollection;
                for (int i = 0; i < m_rc.Count; i++)
                {
                    this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString());
                }
            }
            else
            {
                string name = dataSource;
                IRasterWorkspaceEx rasterWorkspce = m_workSpace as IRasterWorkspaceEx;
                IRasterDataset rasDataset = rasterWorkspce.OpenRasterDataset(name);
                m_rc = rasDataset as IRasterBandCollection;
                for (int i = 0; i < m_rc.Count; i++)
                {
                    this.comboBox1.Items.Add(m_rc.Item(i).Bandname.ToString());
                }

            }
        }
Exemple #23
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="pFeatureClass">要素类</param>
        /// <param name="fieldName">栅格采用的字段</param>
        /// <param name="rasterWorkSpace">输出栅格的工作空间</param>
        /// <param name="newRasterName">新的栅格名称</param>
        public void Convert(IFeatureClass pFeatureClass,
                            string fieldName,
                            string rasterWorkSpace,
                            string newRasterName)
        {
            FileHelper.DeleteFile(rasterWorkSpace, newRasterName, ".tif", ".tfw", ".tif.aux");
            IFeatureClassDescriptor featureClassDescriptor = new FeatureClassDescriptorClass();

            featureClassDescriptor.Create(pFeatureClass, null, fieldName);
            IGeoDataset                geoDataset                = (IGeoDataset)featureClassDescriptor;
            IWorkspaceFactory          workspaceFactory          = new RasterWorkspaceFactoryClass();
            IWorkspace                 workspace                 = workspaceFactory.OpenFromFile(rasterWorkSpace, 0);
            IConversionOp              conversionOp              = new RasterConversionOpClass();
            IRasterAnalysisEnvironment rasterAnalysisEnvironment = (IRasterAnalysisEnvironment)conversionOp;

            rasterAnalysisEnvironment.OutWorkspace = workspace;


            //set cell size
            rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _cellSize);
            //set output extent
            object objectMissing = Type.Missing;

            rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _extentEnvelope, ref objectMissing);
            //set output spatial reference
            rasterAnalysisEnvironment.OutSpatialReference = ((IGeoDataset)pFeatureClass).SpatialReference;
            //convertion
            conversionOp.ToRasterDataset(geoDataset, _rasterType, workspace, newRasterName);
        }
Exemple #24
0
        /// <summary>
        /// 在geodatabase中创建栅格工作空间
        /// </summary>
        /// <param name="pathName"></param>
        /// <returns></returns>
        private IRasterWorkspace2 CreateRasterWorkspace(string pathName)
        {
            // Create RasterWorkspace
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();

            return(workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspace2);
        }
Exemple #25
0
        private void button2_Click(object sender, EventArgs e)
        {
            IGeoDataset inGeoDataSet;
            IGeoDataset outGeoDataSet;
            ISurfaceOp  SurfaceOp = new RasterSurfaceOpClass();

            ILayer       layer       = GetLayerByName(comboBox1.SelectedItem.ToString());
            IRasterLayer rasterLayer = layer as IRasterLayer;
            IRaster      raster      = rasterLayer.Raster;

            inGeoDataSet = raster as IGeoDataset;

            outGeoDataSet = SurfaceOp.Aspect(inGeoDataSet);

            try
            {
                IWorkspaceFactory pWKSF      = new RasterWorkspaceFactoryClass();
                IWorkspace        pWorkspace = pWKSF.OpenFromFile(System.IO.Path.GetDirectoryName(textBox1.Text), 0);
                ISaveAs           pSaveAs    = outGeoDataSet as ISaveAs;
                pSaveAs.SaveAs(System.IO.Path.GetFileName(textBox1.Text), pWorkspace, "TIFF");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            IRasterLayer pRlayer = new RasterLayer();

            pRlayer.CreateFromRaster((IRaster)outGeoDataSet);
            pRlayer.Name = System.IO.Path.GetFileName(textBox1.Text);
            mainForm.axMapControl1.AddLayer(pRlayer, 0);
        }
Exemple #26
0
        /// <summary>
        /// Save the edition as a specified file.
        /// </summary>
        /// <param name="fileName">New file path of raster layer to be saved.</param>
        /// <param name="activeLayer">Raster layer to be saved.</param>
        /// <param name="edits">Pixel collection that contains edited pixels.</param>
        public static void SaveEditsAs(string fileName, IRasterLayer activeLayer, PixelCollection edits)
        {
            if (activeLayer == null || edits.Count == 0)
            {
                return;
            }

            //Random rnd = new Random();
            //string tempFile = rnd.Next().ToString();

            ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

            // Get the original file
            // IRasterLayer rasterLayer = activeLayer;
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
            //IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(rasterLayer.FilePath), 0);
            //IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(rasterLayer.FilePath));

            // Open the new file save location
            IWorkspace mWorkspace = workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(fileName), 0);

            // Save the original file to a new file
            ISaveAs         saveAs         = (ISaveAs)activeLayer.Raster;
            IRasterDataset2 mRasterDataset = (IRasterDataset2)saveAs.SaveAs(System.IO.Path.GetFileName(fileName),
                                                                            mWorkspace,
                                                                            Raster.GetFormat(System.IO.Path.GetExtension(fileName)));
            IRaster mRaster = mRasterDataset.CreateFullRaster();

            // Save edits to file
            Raster.WriteEdits(mRaster, edits);

            System.Runtime.InteropServices.Marshal.ReleaseComObject(mRaster);
        }
Exemple #27
0
        static void Mosaic(IRasterCatalog rasterCatalog)
        {
            try
            {
                //Mosaics all rasters in the raster catalog to an output raster dataset
                IMosaicRaster mosaicRaster = new MosaicRasterClass();
                mosaicRaster.RasterCatalog = rasterCatalog;

                //Set mosaicking options, you may not need to set these for your data
                mosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;
                mosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;

                //Open output workspace
                IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
                IWorkspace        workspace        = workspaceFactory.OpenFromFile(outputFolder, 0);

                //Save out to a target raster dataset
                //It can be saved to TIFF, IMG, GRID, BMP, GIF, JPEG2000, JPEG, Geodatabase, ect.
                ISaveAs saveas = (ISaveAs)mosaicRaster;
                saveas.SaveAs(outputName, workspace, "TIFF");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
        public static void exportRasterData(string parth, IRasterLayer rasterLayer, float[,] rasterMat)   //输出栅格数据
        {
            string            directory        = parth.Substring(0, parth.LastIndexOf("\\"));
            string            name             = parth.Substring(parth.LastIndexOf("\\") + 1);
            IWorkspaceFactory workspaceFac     = new RasterWorkspaceFactoryClass();
            IRasterWorkspace2 rasterWorkspace2 = workspaceFac.OpenFromFile(directory, 0) as IRasterWorkspace2;

            IRasterInfo rasterInfo  = (rasterLayer.Raster as IRawBlocks).RasterInfo;
            IPoint      originPoint = new Point();

            originPoint.PutCoords(rasterInfo.Origin.X, rasterInfo.Origin.Y - (rasterLayer.Raster as IRasterProps).Height * (rasterLayer.Raster as IRasterProps).MeanCellSize().Y);
            IRasterProps   rasterProps   = rasterLayer.Raster as IRasterProps;
            IRasterDataset rasterDataSet = rasterWorkspace2.CreateRasterDataset(name, "IMAGINE Image", originPoint, rasterProps.Width, rasterProps.Height,
                                                                                rasterProps.MeanCellSize().X, rasterProps.MeanCellSize().Y, 1, rstPixelType.PT_FLOAT, rasterProps.SpatialReference, true) as IRasterDataset2;

            IRaster2 raster2 = rasterDataSet.CreateDefaultRaster() as IRaster2;

            IPnt pntClass = new Pnt();

            pntClass.X = rasterProps.Width;
            pntClass.Y = rasterProps.Height;
            IRasterCursor rasterCursor   = raster2.CreateCursorEx(pntClass);
            IRasterCursor inRasterCursor = (rasterLayer.Raster as IRaster2).CreateCursorEx(pntClass);

            IRasterEdit rasterEdit = raster2 as IRasterEdit;

            if (rasterEdit.CanEdit())
            {
                IPixelBlock3 pixelBlock3   = rasterCursor.PixelBlock as IPixelBlock3;
                IPixelBlock3 inPixelBlock3 = inRasterCursor.PixelBlock as IPixelBlock3;
                System.Array pixels        = (System.Array)rasterMat;
                pixelBlock3.set_PixelData(0, (System.Array)pixels);
                rasterEdit.Write(rasterCursor.TopLeft, (IPixelBlock)pixelBlock3);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pixelBlock3);
            }
            rasterEdit.Refresh();
            IGeoDataset   inDataset   = rasterLayer.Raster as IGeoDataset;
            IGeoDataset   outDataset  = rasterDataSet as IGeoDataset;
            IExtractionOp op          = new RasterExtractionOpClass();
            var           outDataset1 = op.Raster(outDataset, inDataset);
            var           clipRaster  = (IRaster)outDataset1;
            ISaveAs       pSaveAs     = clipRaster as ISaveAs;

            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterCursor);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(raster2);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterDataSet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterWorkspace2);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceFac);
            if (File.Exists(parth))
            {
                File.Delete(parth);
            }
            workspaceFac = new RasterWorkspaceFactoryClass();
            IDataset outdataset = pSaveAs.SaveAs(name, workspaceFac.OpenFromFile(directory, 0), "IMAGINE Image");

            System.Runtime.InteropServices.Marshal.ReleaseComObject(outdataset);
            return;
        }
        //设置实验结果矢量数据保存路径
        public static IFeatureWorkspace setFeatureWorkspace(string path)
        {
            IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(path, 0);
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

            return(pFeatureWorkspace);
        }
Exemple #30
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);
        }
        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;
            }
        }
Exemple #32
0
        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "tif/tiff File(*.tif;*.tiff)|*.tif;*.tiff|Shape File(*.shp)|*.shp|All Files (*.*)|*.*";
            //openFileDialog1.Filter = "(*.tif)|*.tif|(*raw)|*raw";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string extendName = System.IO.Path.GetExtension(openFileDialog.FileName);
                if (extendName == ".shp")
                {
                    try
                    {
                        OpenVectorFile(openFileDialog.FileName);
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show("文件格式不支持!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    IRasterLayer rasterLayer = new RasterLayerClass();
                    try
                    {
                        rasterLayer.CreateFromFilePath(openFileDialog.FileName); // fileName指存本地的栅格文件路径
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show("文件格式不支持!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //设置空间坐标系统
                    try
                    {
                        IWorkspaceFactory pRSTWorkspaceFactory = new RasterWorkspaceFactoryClass();
                        IRasterWorkspace  pRSTWorkspace        = (IRasterWorkspace)pRSTWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(openFileDialog.FileName), 0);
                        IGeoDataset       pGeoDataset          = pRSTWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(openFileDialog.FileName)) as IGeoDataset;

                        //设置空间坐标系统
                        ISpatialReference pTifSpatialReference = pGeoDataset.SpatialReference;
                        axMapControl1.SpatialReference = pTifSpatialReference;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    axMapControl1.AddLayer(rasterLayer, 0);
                    axMapControl1.Refresh();
                    axTOCControl1.Update();
                }
            }
            tabControl1.SelectedIndex = 0;
        }
Exemple #33
0
        private void button4_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            DateTime fechaProcesamiento = sigpi.FechaProcesamiento;

            IWorkspaceFactory pWF        = new RasterWorkspaceFactoryClass();
            IWorkspace        pWorkspace = pWF.OpenFromFile(sigpi.Parametros.RutaSIGPI + "\\" + sigpi.Parametros.Raster, 0);

            IEnumDataset  pEnumDS = pWorkspace.get_Datasets(esriDatasetType.esriDTRasterDataset);
            IDataset      pDS     = pEnumDS.Next();
            List <string> capas   = new List <string>();

            while (pDS != null)
            {
                if (!pDS.Name.ToUpper().Contains("RASTER"))
                {
                    capas.Add(pDS.Name.ToUpper());
                }
                pDS = pEnumDS.Next();
            }

            FrmProbabilidadCalculada frmProbabilidad = new FrmProbabilidadCalculada(capas.ToArray());

            this.Cursor = Cursors.Default;
            if (frmProbabilidad.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            int iNumDias = frmProbabilidad.NumeroDeDias;

            IProgressDialogFactory pProDiaFac = new ProgressDialogFactoryClass();
            IStepProgressor        pStepPro   = pProDiaFac.Create(null, 0);

            pStepPro.MinRange  = 1;
            pStepPro.MaxRange  = 2;
            pStepPro.StepValue = 1;
            IProgressDialog2 pProDia = (IProgressDialog2)pStepPro;

            pProDia.Animation = esriProgressAnimationTypes.esriProgressGlobe;

            pProDia.Title = "Calcular Probabilidad";
            pProDia.ShowDialog();
            pStepPro.Step();
            pStepPro.Message = "Calculando Probabilidad...";
            try
            {
                procesamiento.ProbabilidadCalculada(frmProbabilidad.ModeloBase, iNumDias, sigpi, frmProbabilidad.OpcionDeGuardar);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            pProDia.HideDialog();
            MessageBox.Show("Se ha calculado el modelo y la probabilidad para el dia:\n" + sigpi.FechaProcesamiento);
            txtFechaUltimoModelo.Text = sigpi.FechaProcesamiento.ToLongDateString();
        }
Exemple #34
0
        public static IRasterDataset OpenFileRasterDataset(string fullpath)
        {
            IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(fullpath), 0);
            IRasterWorkspace  pRasterWorkspace  = (IRasterWorkspace)pWorkspace;
            IRasterDataset    pRasterDataset    = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(fullpath));

            return(pRasterDataset);
        }
Exemple #35
0
 public IRasterBand GetBand(IRasterLayer rasterlayer)
 {
     string fullpath = rasterlayer.FilePath;
     string filePath = System.IO.Path.GetDirectoryName(fullpath);
     string fileName = System.IO.Path.GetFileName(fullpath);
     IWorkspaceFactory wsf = new RasterWorkspaceFactoryClass();
     IWorkspace ws = wsf.OpenFromFile(filePath, 0);
     IRasterWorkspace rasterws = ws as IRasterWorkspace;
     IRasterDataset rastdataset = rasterws.OpenRasterDataset(fileName);
     IRasterBandCollection bandcoll = rastdataset as IRasterBandCollection;
     return bandcoll.Item(0);
 }
Exemple #36
0
 public static List<string> getBandName(IRasterLayer rasterlayer)
 {
     string fullpath = rasterlayer.FilePath;
     string filePath = System.IO.Path.GetDirectoryName(fullpath);
     string fileName = System.IO.Path.GetFileName(fullpath);
     IWorkspaceFactory wsf = new RasterWorkspaceFactoryClass();
     IWorkspace ws = wsf.OpenFromFile(filePath, 0);
     IRasterWorkspace rasterws = ws as IRasterWorkspace;
     IRasterDataset rastdataset = rasterws.OpenRasterDataset(fileName);
     IRasterBandCollection bandcoll = rastdataset as IRasterBandCollection;
     List<string> itemband = new List<string>();
     for (int i = 0; i < bandcoll.Count; i++)
     {
         itemband.Add(bandcoll.Item(i).Bandname);
     }
     return itemband;
 }
Exemple #37
0
 /// <summary>
 /// 获取该栅格图像的相关数据
 /// <remarks>
 /// <list type="bullet">
 /// <item>
 /// <term>
 /// 初始化_pDataset
 /// </term>
 /// <item>
 /// 获取栅格的Height和Width
 /// </item>
 /// </item>
 /// </list>
 /// </remarks>
 /// </summary>
 /// <returns></returns>
 private void Open()
 {
     //Open
     IWorkspaceFactory pRFactory = new RasterWorkspaceFactoryClass();
     IRasterWorkspace2 rasterWorkspace = pRFactory.OpenFromFile(_rasterWorkSapce, 0) as IRasterWorkspace2;
     if (rasterWorkspace == null)
         throw new ArgumentException("栅格文件无法打开");
     _pDataset= rasterWorkspace.OpenRasterDataset(_rasterName);
     //set height and width
     
     IRasterProps pRasterProps = (IRasterProps)GetRaster();
     RasterInfo = new RasterInformation()
     {
         Width = pRasterProps.Width,
         Height = pRasterProps.Height,
         XCellSize = pRasterProps.MeanCellSize().X,
         YCellSize = pRasterProps.MeanCellSize().Y,
         OriginPoint = new PointClass() { X = pRasterProps.Extent.XMin,  Y = pRasterProps.Extent.YMin },
         SpatialReference = ((IGeoDataset) _pDataset).SpatialReference
     };
    
 }
Exemple #38
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 { }
 }
        //
        //
        //
        public static IGeoDataset openRasterfromFile(string fullPath)
        {
            string pathToWorkspace = System.IO.Path.GetDirectoryName(fullPath);
            string rasterfileName = System.IO.Path.GetFileName(fullPath);

            IRasterWorkspace pRWS;//=new ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceClass();
            IWorkspaceFactory pWSF;//=new ESRI.ArcGIS.DataSourcesRaster.WorkspaceFactoryClass()
            IWorkspace pWS;
            IRasterDataset pRasterDataset;
            IRaster pRaster;
            IRasterLayer pRasterLayer = new RasterLayerClass();

            //pRWS=new RasterWorkspaceClass();
            pWSF = new RasterWorkspaceFactoryClass();
            pWS = pWSF.OpenFromFile(pathToWorkspace, 0);
            pRWS = pWS as IRasterWorkspace;
            pRasterDataset = pRWS.OpenRasterDataset(rasterfileName);
            pRaster = pRasterDataset.CreateDefaultRaster();
            //pRasterLayer.CreateFromRaster(pRaster);
            return pRaster as IGeoDataset;
        }
        //
        //��դ�����ݼ�
        //
        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;
            }
        }
        /// <summary>
        /// Raster图层导入到数据库
        /// </summary>
        /// <params name="dbWorkspace">数据库</params>
        /// <params name="strRasterFileDir">本地栅格图层路径</params>
        /// <params name="strRasterFileName">本地栅格图层名称</params>
        /// <params name="strOutName">数据库栅格图层名称</params>
        /// <returns></returns>
        public IRasterDataset RasterFileIntoGDB(IWorkspace dbWorkspace,string strRasterFileDir, 
            string strRasterFileName,string strOutName)
        {
            IWorkspace pSdeWorkSpace = dbWorkspace;
            try
            {
                //判断是否有重名现象
                IWorkspace2 pWS2 = pSdeWorkSpace as IWorkspace2;

                //如果名称已存在
                if (pWS2.get_NameExists(esriDatasetType.esriDTRasterDataset, strOutName))
                {
                    DialogResult result;
                    result = MessageBox.Show("栅格文件名  " + strOutName + "  在数据库中已存在!" +
                        "\r是否覆盖?", "相同文件名", MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                    //覆盖原栅格要素
                    if (result == DialogResult.Yes)
                    {
                        IRasterWorkspaceEx pRWs = pSdeWorkSpace as IRasterWorkspaceEx;
                        IDataset pDataset = pRWs.OpenRasterDataset(strOutName) as IDataset;
                        pDataset.Delete();
                        pDataset = null;
                    }
                    else if (result == DialogResult.No)
                    {
                        //不覆盖,则退出for循环,忽略这个要素,转入下一个要素的导入
                        return null;
                    }
                }

                IWorkspaceFactory pRasterWsFac = new RasterWorkspaceFactoryClass();
                IWorkspace pWs = pRasterWsFac.OpenFromFile(strRasterFileDir, 0);
                IRasterDataset pRasterDs = null;
                IRasterWorkspace pRasterWs;
                if (!(pWs is IRasterWorkspace))
                {
                    MessageBox.Show("错误信息:" + strRasterFileDir + "不是栅格工作空间。");
                    return null;
                }
                pRasterWs = pWs as IRasterWorkspace;
                pRasterDs = pRasterWs.OpenRasterDataset(strRasterFileName);
                ISaveAs2 saveAs2 = (ISaveAs2)pRasterDs;
                IRasterStorageDef rasterStorageDef = new RasterStorageDefClass();
                IRasterStorageDef2 rasterStorageDef2 = (IRasterStorageDef2)rasterStorageDef;
                rasterStorageDef2.CompressionType =
                    esriRasterCompressionType.esriRasterCompressionJPEG2000;

                rasterStorageDef2.CompressionQuality = 50;
                rasterStorageDef2.Tiled = true;
                rasterStorageDef2.TileHeight = 128;
                rasterStorageDef2.TileWidth = 128;

                saveAs2.SaveAsRasterDataset(strOutName, pSdeWorkSpace, "JP2", rasterStorageDef2);

                return pRasterDs;
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误信息:" + ex.Message);
                return null;
            }
        }
Exemple #42
0
 private  IRasterWorkspace2 OpenRasterWorkspace()
 {           
    IWorkspaceFactory workspaceFact = new RasterWorkspaceFactoryClass();
    return workspaceFact.OpenFromFile(_workSpace, 0) as IRasterWorkspace2;         
 }
Exemple #43
0
        /// <summary>
        /// 获取工作空间SDE,文件型数据库,MDB,以及shapefile文件所在工作空间,这里可以用一个枚举
        /// </summary>
        /// <param name="_pDatabase"></param>
        /// <returns></returns>
        public IWorkspace GetWorkspace(String _pDatabase, GDBType pGDBType = GDBType.FGDB)
        {
            ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWsFactory = null;

            IWorkspace pWkspace = null;

            if (pGDBType == GDBType.SHP)
            {

                pWsFactory = new ShapefileWorkspaceFactory();

            }
            else if (pGDBType == GDBType.RWS)
            {

                pWsFactory = new RasterWorkspaceFactoryClass();

            }
            else if (pGDBType == GDBType.MDB)
            {
                pWsFactory = new AccessWorkspaceFactoryClass();
            }
            else if (pGDBType == GDBType.FGDB)
            {

                pWsFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
            }
            else if (pGDBType == GDBType.SDE)
            {

                pWsFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
            }

            try
            {

                pWkspace = pWsFactory.OpenFromFile(_pDatabase, 0);

            }
            catch (Exception EX)
            {
                //MessageBox.Show(EX.ToString());

            }

            return pWkspace;
        }
Exemple #44
0
        public void ExportRaster(IRasterDataset rasterDataset, string path, string sFormat, string sName)
        {
            IWorkspaceFactory wsF = new RasterWorkspaceFactoryClass();
            IWorkspace ws = wsF.OpenFromFile(path,0);

            ISaveAs saveAs = rasterDataset as ISaveAs;
            saveAs.SaveAs(sName, ws, sFormat);
        }
        //Open file based raster workspace
        static IWorkspace OpenWorkspace(string path)
        {
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
            IWorkspace rasterWorkspace = workspaceFactory.OpenFromFile(path, 0);

            return rasterWorkspace;

        }
 //
 //
 //
 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);
     }
 }
Exemple #47
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="workSpaceName"></param>
 /// <param name="rasterName"></param>
 public void CopyTo(string workSpaceName, string rasterName)
 {
     IWorkspaceFactory pFactory=new RasterWorkspaceFactoryClass();
     IWorkspace pWorkspace = pFactory.OpenFromFile(workSpaceName, 0);
     if (_pDataset != null)
     {
         _pDataset.Copy(rasterName, pWorkspace);
     }         
 }
        static void Mosaic(IRasterCatalog rasterCatalog)
        {
            try
            {
                //Mosaics all rasters in the raster catalog to an output raster dataset
                IMosaicRaster mosaicRaster = new MosaicRasterClass();
                mosaicRaster.RasterCatalog = rasterCatalog;

                //Set mosaicking options, you may not need to set these for your data
                mosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;
                mosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST;

                //Open output workspace
                IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
                IWorkspace workspace = workspaceFactory.OpenFromFile(outputFolder, 0);

                //Save out to a target raster dataset
                //It can be saved to TIFF, IMG, GRID, BMP, GIF, JPEG2000, JPEG, Geodatabase, ect.
                ISaveAs saveas = (ISaveAs)mosaicRaster;
                saveas.SaveAs(outputName, workspace, "TIFF");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
Exemple #49
0
        private void btnCalculator_Click(object sender, EventArgs e)
        {
            if (this.lstLayer.Items.Count == 0)
            {
                MessageBox.Show("请先在地图中加载要操作的栅格图像.");
            }
            try
            {
                string strOutFileName="";
                if (this.txtExpression.Text.IndexOf(" = ")>0)
                    strOutFileName = this.txtExpression.Text.Substring(0, this.txtExpression.Text.IndexOf(" = "));

                IGeoDataset pGeoDs = pMapAlgebraOp.Execute(this.txtExpression.Text.Trim());
                IRaster pOutRaster = pGeoDs as IRaster;
                IRasterLayer pOutRasterLayer = new RasterLayerClass();
                if(strOutFileName.Trim()!="")
                {
                    IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                    IWorkspace pRWS = pWSF.OpenFromFile(strAnalysisPath, 0);
                    IRasterBandCollection pRasBandCol = (IRasterBandCollection)pGeoDs;
                    pRasBandCol.SaveAs(strOutFileName, pRWS, "GRID");//"IMAGINE Image"
                    pOutRasterLayer = UtilityFunction.SetStretchRenderer(pOutRaster);
                    pOutRasterLayer.Name = strOutFileName;
                    pMap.AddLayer(pOutRasterLayer);
                }
                else
                {
                    pOutRasterLayer = UtilityFunction.SetStretchRenderer(pOutRaster);
                    pMap.AddLayer(pOutRaster as IRasterLayer);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        public static void OpenFileRasterDataset(string inFolderName, string inRasterDatasetName, string inFeatureName, string inFieldName, double outCellSize, string outSummaryFile)
        {
            EnableEsriLiscences();

            //Get feature raster from feature shp
            string outTempRasterName = "tempZoneRasterFromESRI.tif";
            string outZoneRater = inFolderName + "\\" + outTempRasterName;
            int rasterBlockSize = 1024;
            RasterizeEsri.Rasterize(inFeatureName, outZoneRater, inFieldName, outCellSize);

            //Open raster file workspace
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspaceFactory.OpenFromFile(inFolderName, 0);

            //Align raster
            string inValueRaster = inFolderName + "\\" + inRasterDatasetName;
            string inClipFeature = inFeatureName;
            string outClippedRasterName = "tempValueRasterFromESRI.tif";
            string outClippedValueRaster = inFolderName + "\\" + outClippedRasterName;

            ClipRasterBoundaryEsri.ClipRaster(inValueRaster, inClipFeature, outClippedValueRaster);

            //Open zone raster dataset
            IRasterDataset zoneRasterDataset = rasterWorkspace.OpenRasterDataset(outTempRasterName);
            IRasterDataset2 zoneRasterDataset2 = zoneRasterDataset as IRasterDataset2;
            IRaster2 zoneRs2 = zoneRasterDataset2.CreateFullRaster() as IRaster2;

            //Open value raster dataset
            IRasterDataset valueRasterDataset = rasterWorkspace.OpenRasterDataset(outClippedRasterName);
            IRasterDataset2 valueRasterDataset2 = valueRasterDataset as IRasterDataset2;
            IRaster2 valueRs2 = valueRasterDataset2.CreateFullRaster() as IRaster2;

            //Extract bands from the raster
            IRasterBandCollection valueRasterPlanes = valueRasterDataset as IRasterBandCollection;

            //create raster cursor to read block by block
            IPnt blockSize = new PntClass();
            blockSize.SetCoords(rasterBlockSize, rasterBlockSize);

            IRasterCursor valueRasterCursor = valueRs2.CreateCursorEx(blockSize);
            IRasterCursor zoneRasterCursor = zoneRs2.CreateCursorEx(blockSize);

            if (valueRasterPlanes != null)
            {
                Dictionary<int, StatisticsInfo>[] rasInfoDict = new Dictionary<int, StatisticsInfo>[valueRasterPlanes.Count];
                int zoneRasterBandId = 0;

                for (int b = 0; b < valueRasterPlanes.Count; b++)
                {
                    rasInfoDict[b] = new Dictionary<int, StatisticsInfo>();
                }

                do
                {
                    IPixelBlock3 valueRasterPixelBlock3 = valueRasterCursor.PixelBlock as IPixelBlock3;
                    IPixelBlock3 zoneRasterPixelBlock3 = zoneRasterCursor.PixelBlock as IPixelBlock3;

                    //No Idea how esri cursor fills the raster gap if zone is greater than value, so quick and fix using smallest extent

                    int blockWidth = valueRasterPixelBlock3.Width < zoneRasterPixelBlock3.Width ? valueRasterPixelBlock3.Width : zoneRasterPixelBlock3.Width;
                    int blockHeight = valueRasterPixelBlock3.Height < zoneRasterPixelBlock3.Height ? valueRasterPixelBlock3.Height : zoneRasterPixelBlock3.Height;

                    //Console.WriteLine(zoneRasterPixelBlock3.Width);
                    //Console.WriteLine(blockWidth);

                    try
                    {
                        System.Array zoneRasterPixels = (System.Array)zoneRasterPixelBlock3.get_PixelData(zoneRasterBandId);
                        for (int b = 0; b < valueRasterPlanes.Count; b++)
                        {
                            //Console.WriteLine(b);
                            //Get pixel array
                            System.Array valueRasterPixels = (System.Array)valueRasterPixelBlock3.get_PixelData(b);

                            for (int i = 0; i < blockWidth; i++)
                            {
                                for (int j = 0; j < blockHeight; j++)
                                {
                                    //Get pixel value
                                    object pixelValueFromValue = null;
                                    object pixelValueFromZone = null;
                                    try
                                    {
                                        pixelValueFromValue = valueRasterPixels.GetValue(i, j);
                                        pixelValueFromZone = zoneRasterPixels.GetValue(i, j);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }

                                    //process each pixel value
                                    try
                                    {
                                        if (rasInfoDict[b].ContainsKey(Convert.ToInt32(pixelValueFromZone)))
                                        {
                                            StatisticsInfo rastStatistics = rasInfoDict[b][Convert.ToInt32(pixelValueFromZone)];
                                            rastStatistics.Count++;
                                            rastStatistics.Sum = rastStatistics.Sum + Convert.ToDouble(pixelValueFromValue);

                                            rasInfoDict[b][Convert.ToInt32(pixelValueFromZone)] = rastStatistics;
                                        }
                                        else
                                        {
                                            rasInfoDict[b][Convert.ToInt32(pixelValueFromZone)] = new StatisticsInfo() { Count = 1, Sum = Convert.ToDouble(pixelValueFromValue) };
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }

                                    //Console.WriteLine(i +"-"+j);
                                    //Console.WriteLine(pixelValueFromValue + "-" + pixelValueFromZone);

                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                } while (zoneRasterCursor.Next() == true);

                //Export results
                StatisticsExport writer = new StatisticsExport(outSummaryFile);
                writer.ExportZonalStatistics(ref rasInfoDict, outCellSize);

            }
            else
            {
                Console.WriteLine("No band available in the Value Raster");
            }
        }
 public static IWorkspace setRasterWorkspace(string sPath)
 {
     IWorkspaceFactory pWSF;
     pWSF = new RasterWorkspaceFactoryClass() as IWorkspaceFactory;
     return pWSF.OpenFromFile(sPath, 0) as IWorkspace;
 }
Exemple #52
0
        private IRasterLayer SetViewShedRenderer(IRaster pInRaster, string sField, string sPath,double[,] dValue)
        {
            try
            {
                if (dValue == null)
                    return null;
                if (sField.Trim() == "")
                    return null;
                string path="";
                string fileName="";
                int iPath=sPath.LastIndexOf('\\');
                path=sPath.Substring(0,iPath);
                fileName=sPath.Substring(iPath+1,sPath.Length-iPath-1);

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

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

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

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

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

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

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

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

            return pRLayer;
        }
Exemple #54
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;
            }
        }
        private IRasterLayer calWSCons(string  _outPath)
        {
            //��դ�� pMapAlgebraOp
            try
            {
                if (pMapAlgebraOp==null)
                {
                    pMapAlgebraOp = new RasterMapAlgebraOpClass();
                }
                string strExp = "";
                string sRainPath = "";

                //��ֱ���ý�����ʴ�����ݻ��ǽ������ݼ���
                IRaster pRasterR = null;
                if (rbtnR.Checked)
                {
                    pRasterR = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbR.Text)) as IRasterLayer).Raster;
                    pMapAlgebraOp.BindRaster(pRasterR as IGeoDataset, "R");
                }
                else
                {
                    sRainPath = this.txtPcpPath.Text;
                    //
                    IWorkspaceFactory pWsF = new RasterWorkspaceFactoryClass();
                    IRasterWorkspace pRWs;
                    IRasterDataset pRDs = new RasterDatasetClass();
                    IRasterLayer pRLyr = new RasterLayerClass();

                    pRWs = pWsF.OpenFromFile(sRainPath, 0) as IRasterWorkspace;
                    string sFileName="";
                    for (int i = 1; i < 13; i++)
                    {
                        sFileName = this.txtPcpPrefix.Text + i.ToString() + this.txtPcpSuffix.Text;
                        pRDs = pRWs.OpenRasterDataset(sFileName);
                        pMapAlgebraOp.BindRaster(pRDs as IGeoDataset, sFileName);
                        strExp = strExp + "[" + sFileName + "] + ";
                    }
                    //cal total pcp
                    strExp = strExp.TrimEnd("+ ".ToCharArray());
                    IGeoDataset pGeoDsPcp = pMapAlgebraOp.Execute(strExp);
                    pMapAlgebraOp.BindRaster(pGeoDsPcp, "Pcp");

                    //cal Ri
                    strExp = "";
                    string sFileNameE = "",sDsName="",strExpR="";
                    for (int i = 1; i < 13; i++)
                    {
                        sFileName = this.txtPcpPrefix.Text + i.ToString() + this.txtPcpSuffix.Text;
                        sFileNameE="["+sFileName+"]";
                        strExp = "1.735 * pow(10,1.5 * log10((" + sFileNameE + " * " + sFileNameE + ") / [Pcp]) - 0.08188)";
                        IGeoDataset pGeoDsRi = pMapAlgebraOp.Execute(strExp);
                        sDsName = "Pcp" + i.ToString();
                        pMapAlgebraOp.BindRaster(pGeoDsRi, sDsName);
                        pMapAlgebraOp.UnbindRaster(sFileName);
                        strExpR = strExpR + "[" + sDsName + "] + ";
                    }
                    //cal R
                    strExpR = strExpR.TrimEnd("+ ".ToCharArray());
                    IGeoDataset pGeoDsR = pMapAlgebraOp.Execute(strExpR);
                    pMapAlgebraOp.BindRaster(pGeoDsR, "R");
                    for (int i = 1; i < 13; i++)
                    {
                        sDsName = "Pcp" + i.ToString();
                        pMapAlgebraOp.UnbindRaster(sDsName);
                    }
                }

                //����K����
                IRaster pRasterSclay = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbSoilClay.Text)) as IRasterLayer).Raster;
                pMapAlgebraOp.BindRaster(pRasterSclay as IGeoDataset, "clay");

                IRaster pRasterSsand = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbSoilSand.Text)) as IRasterLayer).Raster;
                pMapAlgebraOp.BindRaster(pRasterSsand as IGeoDataset, "sand");

                IRaster pRasterSslit = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbSoilSlit.Text)) as IRasterLayer).Raster;
                pMapAlgebraOp.BindRaster(pRasterSslit as IGeoDataset, "slit");

                IRaster pRasterSOrg = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbSoilOrganic.Text)) as IRasterLayer).Raster;
                pMapAlgebraOp.BindRaster(pRasterSOrg as IGeoDataset, "org");

                //cal K
                //K =(0.2 + 0.3 * exp(-0.0256 * soil_sand * (1.0 - soil_silt / 100.0))) * pow((soil_silt * 1.0 / (soil_clay * 1.0 + soil_silt * 1.0)),0.3) * (1.0 - 0.25 * soil_oc / (soil_oc * 1.0 + exp(3.72 - 2.95 * soil_oc))) * (1.0 - (0.7 * ksd) / (ksd + exp(-5.51 + 22.9 * ksd)))
                strExp = "(0.2 + 0.3 * Exp(-0.0256 * [sand] * (1.0 - [slit] / 100.0))) * Pow(([slit] * 1.0 / ([clay] * 1.0 + [slit] * 1.0)), 0.3) * (1.0 - 0.25 * [org] * 0.58 / ([org] * 0.58 + Exp(3.72 - 2.95 * [org] * 0.58))) * (1.0 - (0.7 * (1.0 - [sand] / 100.0)) / ((1.0 - [sand] / 100.0) + Exp(-5.51 + 22.9 * (1.0 - [sand] / 100.0))))";
                IGeoDataset pGeoDsK = pMapAlgebraOp.Execute(strExp);
                pMapAlgebraOp.BindRaster(pGeoDsK, "K");
                pMapAlgebraOp.UnbindRaster("clay");
                pMapAlgebraOp.UnbindRaster("sand");
                pMapAlgebraOp.UnbindRaster("slit");
                pMapAlgebraOp.UnbindRaster("org");

                //cal L*S
                IHydrologyOp pHydrologyOp = new RasterHydrologyOpClass();
                object objZLimit = System.Type.Missing;
                IRaster pRasterDem = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbDem.Text)) as IRasterLayer).Raster;
                //Fill Dem
                IGeoDataset pGeoDsDemFill =pHydrologyOp.Fill(pRasterDem as IGeoDataset,ref objZLimit);
                // cal FlowDirection
                IGeoDataset pGeoDsFlowDir = pHydrologyOp.Fill(pGeoDsDemFill, ref objZLimit);
                //cal FlowAccumulation
                IGeoDataset pGeoDsFlowAcc = pHydrologyOp.Fill(pGeoDsFlowDir, ref objZLimit);
                pMapAlgebraOp.BindRaster(pGeoDsFlowAcc, "FlowAcc");

                //cal Slope with Deg
                ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass();
                object objZFactor = System.Type.Missing;
                IGeoDataset pGeoDsSlope = pSurfaceOp.Slope(pGeoDsDemFill, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, ref objZFactor);
                // bind raster data "Slope"
                pMapAlgebraOp.BindRaster(pGeoDsSlope, "Slope");
                //cal S
                strExp = "Con([Slope] < 5,10.8 * Sin([Slope] * 3.14 / 180) + 0.03,[Slope] >= 10,21.9 * Sin([Slope] * 3.14 / 180) - 0.96,16.8 * Sin([Slope] * 3.14 / 180) - 0.5)";
                IGeoDataset pGeoDsS = pMapAlgebraOp.Execute(strExp);
                pMapAlgebraOp.BindRaster(pGeoDsS, "S");

                //cal m
                strExp = "Con([Slope] <= 1,0.2,([Slope] > 1 & [Slope] <= 3),0.3,[Slope] >= 5,0.5,0.4)";
                IGeoDataset pGeoDsM = pMapAlgebraOp.Execute(strExp);
                pMapAlgebraOp.BindRaster(pGeoDsM, "m");
                //cal ls
                strExp = "[S] * Pow(([FlowAcc] * "+this.txtCellSize.Text+" / 22.1),[m])";

                IGeoDataset pGeoDsLS = pMapAlgebraOp.Execute(strExp);
                pMapAlgebraOp.BindRaster(pGeoDsLS, "LS");

                pMapAlgebraOp.UnbindRaster("m");
                pMapAlgebraOp.UnbindRaster("S");
                pMapAlgebraOp.UnbindRaster("Slope");
                pMapAlgebraOp.UnbindRaster("FlowAcc");

                IRaster pRasterC = null;
                if (rbtnVegCover.Checked)
                {
                    pRasterC = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbC.Text)) as IRasterLayer).Raster;
                    pMapAlgebraOp.BindRaster(pRasterC as IGeoDataset, "C");
                }
                else
                {
                    //cal vegetation cover
                    IRaster pRasterNDVI = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbC.Text)) as IRasterLayer).Raster;
                    IRasterBandCollection pRasterBandCollection = pRasterNDVI as IRasterBandCollection;
                    IRasterBand pRasterBand = pRasterBandCollection.Item(0);
                    pRasterBand.ComputeStatsAndHist();
                    IRasterStatistics pRasterStatistics = pRasterBand.Statistics;
                    double dMax = pRasterStatistics.Maximum;
                    double dMin = pRasterStatistics.Minimum;
                    pMapAlgebraOp.BindRaster(pRasterNDVI as IGeoDataset, "NDVI");
                    if (dMin < 0)
                    {
                        dMin = 0;
                    }
                    //veg%yr% = (ndvi%yr% - ndvi%yr%min) / (ndvi%yr%max - ndvi%yr%min)
                    strExp = "([NDVI] - "+dMin+") / ("+dMax +" - "+dMin+")";
                    IGeoDataset pGeoDsC = pMapAlgebraOp.Execute(strExp);
                    pMapAlgebraOp.BindRaster(pGeoDsC, "C");
                    pMapAlgebraOp.UnbindRaster("NDVI");
                }
                //����P����
                IRaster pRasterP = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbP.Text)) as IRasterLayer).Raster;
                pMapAlgebraOp.BindRaster(pRasterP as IGeoDataset, "P");
                if (_outPath != "")
                {
                    strExp = _outPath + " = [R] * [K] * [LS] * (1 - [C]) * [P]";
                }
                else
                {
                    strExp = "[R] * [K] * [LS] * (1 - [C]) * [P]";
                }

                IGeoDataset pGeoDsSr = pMapAlgebraOp.Execute(strExp);
                IRaster pOutRaster = pGeoDsSr as IRaster;
                IRasterLayer pOutRasterLayer = new RasterLayerClass();
                pOutRasterLayer.CreateFromRaster(pOutRaster);
                //��������
                //string strOutDir = _outPath.Substring(0, _outPath.LastIndexOf("\\"));
                int startX = _outPath.LastIndexOf("\\");
                int endX = _outPath.Length;
                string sRLyrName = _outPath.Substring(startX + 1, endX - startX - 1);
                pOutRasterLayer.Name = sRLyrName;
                pMapAlgebraOp = null;
                return pOutRasterLayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return null;
            }
        }
Exemple #56
0
 private static IRasterDataset OpenFileRasterDataset(string fullpath)
 {
     try
     {
         IWorkspaceFactory WorkspaceFactory = new RasterWorkspaceFactoryClass();
         string filePath = System.IO.Path.GetDirectoryName(fullpath);
         string fileName = System.IO.Path.GetFileName(fullpath);
         IWorkspace Workspace = WorkspaceFactory.OpenFromFile(filePath, 0);
         IRasterWorkspace rasterWorkspace = (IRasterWorkspace)Workspace;
         IRasterDataset rasterSet = (IRasterDataset)rasterWorkspace.OpenRasterDataset(fileName);
         return rasterSet;
     }
     catch
     {
         return null;
     }
 }
Exemple #57
0
        private void AddRasterData()
        {
            try
            {
                IRasterLayer pRasterLayer;
                pRasterLayer = new RasterLayerClass();
                String rasterFileName, rasterDirName;
                IRasterWorkspace pRWS;//=new ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceClass();

                IWorkspaceFactory pWSF;//=new ESRI.ArcGIS.DataSourcesRaster.WorkspaceFactoryClass();
                IRaster pRaster;
                IRasterDataset pRasterDataset;

                IWorkspace pWS;
                String rawFileName;
                int startX, endX;
                //IRasterLayer pRasterLayer;

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {

                    rasterFileName = openFileDialog1.FileName;
                    statusBar1.Text = rasterFileName;

                    rasterDirName = rasterFileName.Substring(0, rasterFileName.LastIndexOf("\\"));

                    startX = rasterFileName.LastIndexOf("\\");
                    endX = rasterFileName.Length;

                    rawFileName = rasterFileName.Substring(startX + 1, endX - startX - 1);
                    //sDirName =sRequest.Substring(sRequest.IndexOf("/"), sRequest.LastIndexOf("/")-3);

                    //pRWS=new RasterWorkspaceClass();
                    pWSF = new RasterWorkspaceFactoryClass();

                    pWS = pWSF.OpenFromFile(rasterDirName, 0);

                    pRWS = pWS as IRasterWorkspace;

                    pRasterDataset = pRWS.OpenRasterDataset(rawFileName);

                    pRaster = pRasterDataset.CreateDefaultRaster();

                    pRasterLayer.CreateFromRaster(pRaster);

                    axMapControl1.AddLayer(pRasterLayer as ILayer, 0);

                }

            }
            catch (Exception e)
            {

            }
        }
Exemple #58
0
 //获取栅格数据集的目录
 IRasterWorkspace GetRasterWorkspace(string pWsName)
 {
     try
     {
         IWorkspaceFactory pWorkFact = new RasterWorkspaceFactoryClass();
         return pWorkFact.OpenFromFile(pWsName, 0) as IRasterWorkspace;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
Exemple #59
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string strInFileName;
            string strOutFileName;
            int startX, endX;
            string strOutDir;
            try
            {
                if (bDataPath == true)
                {
                    strInFileName = txtOutPath.Text;
                    strOutDir = strInFileName.Substring(0, strInFileName.LastIndexOf("\\"));
                    startX = strInFileName.LastIndexOf("\\");
                    endX = strInFileName.Length;
                    strOutFileName = strInFileName.Substring(startX + 1, endX - startX - 1);
                }
                else
                {
                    strOutDir = txtOutPath.Text;
                    strOutFileName = "slope";
                }
                if (File.Exists(strOutDir + "\\" + strOutFileName + ".aux") == true)
                {
                    MessageBox.Show("�ļ�" + strOutFileName + "�Ѿ����ڣ�������������");
                    return;
                }
                if (m_pRasterLyr != null)
                {
                    double dCellSize = Convert.ToDouble(txtCellSize.Text);
                    ISurfaceOp pRasterSurfaceOp = new RasterSurfaceOpClass();
                    double dZFactor = Convert.ToDouble(txtZFactor.Text);
                    object objZFactor = dZFactor;

                    IRaster pInRaster = m_pRasterLyr.Raster;
                    IGeoDataset pGeoDs = null;
                    IRasterLayer pOutRasterLayer = new RasterLayerClass();
                    pOutRasterLayer.Name = strOutFileName;
                    if (radioDegree.Checked == true)
                    {
                        pGeoDs = pRasterSurfaceOp.Slope(pInRaster as IGeoDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, ref objZFactor);
                    }
                    else
                    {
                        pGeoDs = pRasterSurfaceOp.Slope(pInRaster as IGeoDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopePercentrise, ref objZFactor);
                    }

                    IRaster pOutRaster = (IRaster)pGeoDs;
                    pOutRasterLayer.CreateFromRaster(pOutRaster);
                    pOutRasterLayer.Name = strOutFileName;
                    IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                    IWorkspace pRWS = pWSF.OpenFromFile(strOutDir, 0);
                    IRasterBandCollection pRasBandCol = (IRasterBandCollection)pGeoDs;
                    pRasBandCol.SaveAs(strOutFileName, pRWS, "GRID");//"IMAGINE Image"
                    pOutRasterLayer = UtilityFunction.SetStretchRenderer(pOutRasterLayer.Raster);
                    pOutRasterLayer.Name = strOutFileName;
                    pMap.AddLayer(pOutRasterLayer);
                }
            }

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

            }
        }
Exemple #60
0
        public IRasterDataset OpenFileRasterDataset(string pFolderName, string pDatasetName)
        {
            IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(pFolderName, 0);

            IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pDatasetName);
            return pRasterDataset;
        }