コード例 #1
2
ファイル: GeoMapLoad.cs プロジェクト: Krystal001025/temp
 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;
     }
 }
コード例 #2
0
 /// <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 + "无效!");
     }
 }
コード例 #3
0
ファイル: frmSelectBand.cs プロジェクト: chinasio/minegis
        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());
                }

            }
        }
コード例 #4
0
ファイル: TaskAreaHelper.cs プロジェクト: soon14/ColPlanning
        /// <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);
            }
        }
コード例 #5
0
ファイル: ClipLayer.cs プロジェクト: VB6Hobbyst7/minegis
        /// <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);
        }
コード例 #6
0
ファイル: DEMCalc.cs プロジェクト: chinasio/minegis
        /// <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);
        }
コード例 #7
0
        //#######################以下函数可配合使用########################

        //**************************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;
        }
コード例 #8
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);
            }
        }
コード例 #9
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);
        }
コード例 #10
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);              
        }    
コード例 #11
0
        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;
        }
コード例 #12
0
        //设置实验结果矢量数据保存路径
        public static IFeatureWorkspace setFeatureWorkspace(string path)
        {
            IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(path, 0);
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

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

                this.Close();
            }
            catch
            {
                vProgress.Close();
                this.Close();
                MessageBox.Show("很抱歉,操作失败!", "提示!");
                return;
            }
        }
コード例 #14
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();
        }
コード例 #15
0
ファイル: GDBData.cs プロジェクト: VB6Hobbyst7/minegis
        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);
        }
コード例 #16
0
ファイル: RasterRender.cs プロジェクト: xfgxfg/CropWatchField
 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);
 }
コード例 #17
0
ファイル: RasterRender.cs プロジェクト: xfgxfg/CropWatchField
 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;
 }
コード例 #18
0
ファイル: RasterReader.cs プロジェクト: gaufung/Accessibility
 /// <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
     };
    
 }
コード例 #19
0
ファイル: GISLayers.cs プロジェクト: AgentWord/SiPing
 //定义栅格打开函数
 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 { }
 }
コード例 #20
0
ファイル: RasterReader.cs プロジェクト: gaufung/Accessibility
 /// <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);
     }         
 }
コード例 #21
0
        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");
            }
        }
コード例 #22
0
ファイル: GDBData.cs プロジェクト: chinasio/minegis
        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);
        }
コード例 #23
0
ファイル: RibbonForm.cs プロジェクト: xfgxfg/HXCropWatchDB
 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;
     }
 }
コード例 #24
0
        //Ϊդ��ͼ�����ݽ���ͨ�ӷ�����ɫ
        public static IRasterLayer SetViewShedRenderer(IRaster pInRaster, string sField, string sPath)
        {
            IRasterDescriptor pRD = new RasterDescriptorClass();
            pRD.Create(pInRaster, new QueryFilterClass(), sField);
            IReclassOp pReclassOp = new RasterReclassOpClass();
            IGeoDataset pGeodataset = pInRaster as IGeoDataset;
            IRasterAnalysisEnvironment pEnv = pReclassOp as IRasterAnalysisEnvironment;
            IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
            IWorkspace pWS = pWSF.OpenFromFile(sPath, 0);
            pEnv.OutWorkspace = pWS;
            object objSnap = null;
            object objExtent = pGeodataset.Extent;
            pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref objSnap);
            pEnv.OutSpatialReference = pGeodataset.SpatialReference;
            IRasterLayer pRLayer = new RasterLayerClass();
            IRasterBandCollection pRsBandCol = pGeodataset as IRasterBandCollection;
            IRasterBand pRasterBand = pRsBandCol.Item(0);
            pRasterBand.ComputeStatsAndHist();
            IRasterStatistics pRasterStatistic = pRasterBand.Statistics;
            double dMaxValue = pRasterStatistic.Maximum;
            double dMinValue = pRasterStatistic.Minimum;

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

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

            return pRLayer;
        }
コード例 #25
0
        //
        //
        //
        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;
        }
コード例 #26
0
        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;
            }
        }
コード例 #27
0
ファイル: ClassRasterOp.cs プロジェクト: Krystal001025/temp
 //获取栅格数据集的目录
 IRasterWorkspace GetRasterWorkspace(string pWsName)
 {
     try
     {
         IWorkspaceFactory pWorkFact = new RasterWorkspaceFactoryClass();
         return pWorkFact.OpenFromFile(pWsName, 0) as IRasterWorkspace;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
コード例 #28
0
ファイル: ClassRasterOp.cs プロジェクト: Krystal001025/temp
        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;
        }
コード例 #29
0
        /// <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;
            }
        }
コード例 #30
0
ファイル: frmRasterCalculator.cs プロジェクト: lovelll/DQHP
        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());
            }
        }
コード例 #31
0
ファイル: Mainfrm.cs プロジェクト: chinasio/Control
        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)
            {

            }
        }
コード例 #32
0
ファイル: Home.cs プロジェクト: gistop/aegis
        private void AddPic()
        {
            System.Windows.Forms.OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "*.bmp|*.bmp|*.jpg|*.jpg|*.tif|*.tif";
            ofd.ShowDialog();




            string filePath = ofd.FileName;

            //此两个路径和文件名作为参数:

            string pathName = System.IO.Path.GetDirectoryName(filePath);
            string fileName = System.IO.Path.GetFileName(filePath);



            //定义工作空间工厂并实例化:

            IWorkspaceFactory pWSF;
            pWSF = new RasterWorkspaceFactoryClass();

            //

            IWorkspace pWS;
            pWS = pWSF.OpenFromFile(pathName, 0);

            IRasterWorkspace pRWS;
            pRWS = pWS as IRasterWorkspace;


            IRasterDataset pRasterDataset;
            pRasterDataset = pRWS.OpenRasterDataset(fileName);

            //影像金字塔的判断与创建
            IRasterPyramid pRasPyrmid;
            pRasPyrmid = pRasterDataset as IRasterPyramid;

            if (pRasPyrmid != null)
            {
                if (!(pRasPyrmid.Present))
                {
                    pRasPyrmid.Create();
                }
            }

            IRaster pRaster;
            pRaster = pRasterDataset.CreateDefaultRaster();

            IRasterLayer pRasterLayer;
            pRasterLayer = new RasterLayerClass();
            pRasterLayer.CreateFromRaster(pRaster);

            ILayer pLayer = pRasterLayer as ILayer;
            Global.mainmap.AddLayer(pLayer, 0);
        }
コード例 #33
0
ファイル: frmRasterReClass.cs プロジェクト: lovelll/DQHP
        private IRasterLayer SetViewShedRenderer(IRaster pInRaster, string sField, string sPath,double[,] dValue)
        {
            try
            {
                if (dValue == null)
                    return null;
                if (sField.Trim() == "")
                    return null;
                string path="";
                string fileName="";
                int iPath=sPath.LastIndexOf('\\');
                path=sPath.Substring(0,iPath);
                fileName=sPath.Substring(iPath+1,sPath.Length-iPath-1);

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

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

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

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

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

                pRLayer.CreateFromRaster(pOutRaster);
                pRLayer.Name = fileName;
                return pRLayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return null;
            }
        }
コード例 #34
0
        //
        //��դ�����ݼ�
        //
        public static IRasterDataset OpenRasterDataset(string sDir, string sName)
        {
            try
            {
                IRasterDataset pRSD = null;
                IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                if (pWSF.IsWorkspace(sDir))
                {
                    IWorkspace pWS = pWSF.OpenFromFile(sDir, 0);
                    IRasterWorkspace pRsWs = pWS as IRasterWorkspace;
                    pRSD = pRsWs.OpenRasterDataset(sName);
                }
                return pRSD;
            }
            catch
            {

                  return null;
            }
        }
コード例 #35
0
        //Open file based raster workspace
        static IWorkspace OpenWorkspace(string path)
        {
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
            IWorkspace rasterWorkspace = workspaceFactory.OpenFromFile(path, 0);

            return rasterWorkspace;

        }
コード例 #36
0
 public static IWorkspace setRasterWorkspace(string sPath)
 {
     IWorkspaceFactory pWSF;
     pWSF = new RasterWorkspaceFactoryClass() as IWorkspaceFactory;
     return pWSF.OpenFromFile(sPath, 0) as IWorkspace;
 }
コード例 #37
0
ファイル: GISTools.cs プロジェクト: AgentWord/SiPing
        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;
            }
        }
コード例 #38
0
 //
 //
 //
 public static void ConvertRasterToRsDataset(string sPath, IRaster pRaster, string sOutName)
 {
     try
     {
         IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
         if (pWSF.IsWorkspace(sPath) == false)
             return;
         IWorkspace pRWS = pWSF.OpenFromFile(sPath, 0);
         if (File.Exists(sPath + "\\" + sOutName + ".img") == true)
             File.Delete(sPath + "\\" + sOutName + ".img");
         //IRasterDescriptor pRasterDes = new RasterDescriptorClass();
         //pRasterDes.Create(pRaster, null, "Value");
         IRasterBandCollection pRasBandCol = pRaster as IRasterBandCollection;
         //DeleteFile(sPath,sOutName);
         IDataset pDS = pRasBandCol.SaveAs(sOutName + ".img", pRWS, "IMAGINE Image");
         ITemporaryDataset pRsGeo = pDS as ITemporaryDataset;
         if (pRsGeo.IsTemporary())
             pRsGeo.MakePermanent();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
コード例 #39
0
ファイル: RasterWriter.cs プロジェクト: gaufung/Accessibility
 private  IRasterWorkspace2 OpenRasterWorkspace()
 {           
    IWorkspaceFactory workspaceFact = new RasterWorkspaceFactoryClass();
    return workspaceFact.OpenFromFile(_workSpace, 0) as IRasterWorkspace2;         
 }
コード例 #40
0
ファイル: frmSlope.cs プロジェクト: lovelll/DQHP
        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);

            }
        }
コード例 #41
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);
            }
        }