Esempio n. 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;
     }
 }
Esempio n. 2
0
        public static string ExportLayerImage(IRaster pRaster, string[] bbox, string[] size,string outputUrl,string serveroutDir)
        {
            //判断栅格文件是否已经存在,存在删除,原因是如果存在,不删除的话,保存图片出错

            //创建rasterlayer
            IRasterLayer pRasterLayer = new RasterLayerClass();

            //获取mapServer中所有的图层
            IMap pMap = new MapClass();
            pRasterLayer.CreateFromRaster(pRaster);
            pMap.AddLayer(pRasterLayer as ILayer);            //
            //
            Size pSize = new Size();
            pSize.Width = Convert.ToInt32(size[0]);
            pSize.Height = Convert.ToInt32(size[1]);

            //
            IEnvelope pEnvelop = new EnvelopeClass();
            pEnvelop.PutCoords(Convert.ToDouble(bbox[0]), Convert.ToDouble(bbox[1]), Convert.ToDouble(bbox[2]), Convert.ToDouble(bbox[3]));
            Image pImage = SaveCurrentToImage(pMap, pSize, pEnvelop);
            string imageName = System.DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + ".png";
            //outputUrl="http://localhost:6080/arcgis/rest/directories/arcgisoutput/imageserver/miyunspot_ImageServer/"

            // serveroutDir="D:\arcgisserver\directories\arcgisoutput\imageserver\miyunspot_ImageServer";
            string url = outputUrl + imageName;
            string path = System.IO.Path.Combine(serveroutDir, imageName);
            pImage.Save(path);
            return url;
        }
Esempio n. 3
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);
        }
Esempio n. 4
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 = "aspect";
                }
                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();
                    IRaster pInRaster = m_pRasterLyr.Raster;
                    IRaster pOutRaster = null;
                    IRasterLayer pRasterLayer = new RasterLayerClass();
                    IGeoDataset pGeoDs = pRasterSurfaceOp.Aspect(pInRaster as IGeoDataset);
                    pOutRaster = pGeoDs as IRaster;
                    IRasterLayer pOutRasterLayer = new RasterLayerClass();
                    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);

            }
        }
Esempio n. 5
0
        public static string CreateJPEGFromActiveView(IRaster pRaster,IEnvelope pEnv,string outurl, System.String pathFileName)
        {
            //创建rasterlayer
            IRasterLayer pRasterLayer = new RasterLayerClass();

            //获取mapServer中所有的图层
            IMap pMap = new MapClass();
            pRasterLayer.CreateFromRaster(pRaster);
            pMap.AddLayer(pRasterLayer as ILayer);

            IActiveView activeView = pMap as IActiveView;
            activeView.Extent = pEnv;
            //parameter check
            if (activeView == null)
            {
                return null;
            }
            string imageName = System.DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "") + ".png";
            pathFileName = System.IO.Path.Combine(pathFileName, imageName);

            ESRI.ArcGIS.Output.IExport export = new ESRI.ArcGIS.Output.ExportPNGClass();
            export.ExportFileName = pathFileName;

            // Microsoft Windows default DPI resolution

            ESRI.ArcGIS.esriSystem.tagRECT exportRECT = new ESRI.ArcGIS.esriSystem.tagRECT();
            exportRECT.top = 0;
            exportRECT.left = 0;
            exportRECT.right = 800;
            exportRECT.bottom = 600;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.top,exportRECT.left,exportRECT.right,exportRECT.bottom);
            export.PixelBounds = envelope;
            System.Int32 hDC = export.StartExporting();
            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

            // Finish writing the export file and cleanup any intermediate files
            export.FinishExporting();
            export.Cleanup();

            return outurl + "/" + imageName;
        }
 private void btnDownload_Click(object sender, EventArgs e)
 {
     if (!checkInputs())
     {
         MessageBox.Show("You must have a value for all inputs");
         return;
     }
     mapserviceutility msUtil = new mapserviceutility();
     geoDatabaseUtility geoUtil = new geoDatabaseUtility();
     IImageServerLayer svLyr = getServerLayer();
     ESRI.ArcGIS.Geometry.IEnvelope ext = new ESRI.ArcGIS.Geometry.EnvelopeClass();
     if(cmbExtent.Text.ToLower()=="display")
     {
         ext = av.Extent;
     }
     else
     {
         IFeatureLayer ftrLyr = getFeatureLayer();
         ext = ((ESRI.ArcGIS.Geodatabase.IGeoDataset)ftrLyr).Extent;
     }
     if(svLyr==null)
     {
         MessageBox.Show("You must select a Image server layer");
         return;
     }
     this.Visible = false;
     ESRI.ArcGIS.Geodatabase.IWorkspace wks = geoUtil.OpenWorkSpace(txtGeoDb.Text);
     ESRI.ArcGIS.Geodatabase.IRaster rs = null;
     string msg = msUtil.fillDbRaster(svLyr,wks,ext,svLyr.ServiceInfo.SpatialReference,out rs);
     IMap mp = (IMap)av;
     if (rs != null)
     {
         IRasterLayer rsLyr = new RasterLayerClass();
         rsLyr.CreateFromRaster(rs);
         rsLyr.Name = svLyr.ServiceInfo.Name;
         rsLyr.Visible = false;
         mp.AddLayer((ILayer)rsLyr);
     }
     this.Close();
     //MessageBox.Show(msg);
 }
Esempio n. 7
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;
            }
        }
Esempio n. 8
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm    = cmbRaster.Text;
            string inFocalStat = cmbFocalStat.Text;
            string outNmRst    = txtOutName.Text;

            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Rasterr", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (inFocalStat == "" || inFocalStat == null)
            {
                MessageBox.Show("You must specify an Focal Statistic", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (outNmRst == "" || outNmRst == null)
            {
                MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            HashSet <string> offsets = new HashSet <string>();

            for (int i = 0; i < dgvAzDs.RowCount; i++)
            {
                string az = dgvAzDs[0, i].Value.ToString();
                string ds = dgvAzDs[1, i].Value.ToString();
                offsets.Add(az + ";" + ds);
            }
            if (offsets.Count < 1)
            {
                MessageBox.Show("Nothing specified for offset!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRaster rs1   = rstDic[inRst1Nm];
            IRaster outRs = null;

            rasterUtil.focalType fcType = (rasterUtil.focalType)Enum.Parse(typeof(rasterUtil.focalType), inFocalStat);
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Creating Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                outRs         = rsUtil.createRaster(rsUtil.calcFocalSampleFunction(rs1, offsets, fcType));
                outraster     = outRs;
                outrastername = outNmRst;
                if (mp != null && addToMap)
                {
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rsLyr = new RasterLayerClass();
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name    = OutRasterName;
                    rsLyr.Visible = false;
                    mp.AddLayer(rsLyr);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Focal Sample Analysis" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 9
0
        //打开文件函数
        public static void OpenFile(AxMapControl mapControl, AxPageLayoutControl pageLayoutControl)
        {
            OpenFileDialog OpenFdlg = new OpenFileDialog();

            OpenFdlg.Title            = "选择需要加载的地理数据文件";
            OpenFdlg.Filter           = "mxd文件|*.mxd|Shape文件|*.shp|所有文件|*.*";
            OpenFdlg.RestoreDirectory = true;

            if (OpenFdlg.ShowDialog() == DialogResult.OK)
            {
                string strFileName = OpenFdlg.FileName;//完全名
                if (strFileName == string.Empty)
                {
                    return;
                }
                string pathName    = System.IO.Path.GetDirectoryName(strFileName);            //位置
                string strFExtendN = System.IO.Path.GetExtension(strFileName);                //后缀名
                string fileName    = System.IO.Path.GetFileNameWithoutExtension(strFileName); //单独的文件名
                string fileNameE   = System.IO.Path.GetFileName(strFileName);                 //文件名和扩展名
                switch (strFExtendN)
                {
                case ".shp":
                    mapControl.AddShapeFile(pathName, fileName);
                    OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl);
                    break;

                case ".mxd":
                    if (mapControl.CheckMxFile(strFileName))
                    {
                        mapControl.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                        mapControl.LoadMxFile(strFileName, 0, Type.Missing);
                        mapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
                        OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl);
                    }
                    else
                    {
                        MessageBox.Show("所选文件不是地图文档文件!", "信息提示");
                        return;
                    }
                    break;

                case ".bmp":
                case ".BMP":
                case ".tif":
                case ".TIF":
                case ".jpg":
                case ".JPG":
                case ".img":
                case ".IMG":
                case ".png":
                case ".PNG":
                    IWorkspaceFactory pWSF;
                    pWSF = new RasterWorkspaceFactory();
                    IWorkspace pWS;
                    pWS = pWSF.OpenFromFile(pathName, 0);
                    IRasterWorkspace pRWS;
                    pRWS = pWS as IRasterWorkspace;
                    IRasterDataset pRasterDataset;
                    pRasterDataset = pRWS.OpenRasterDataset(fileNameE);
                    //影像金字塔判断与创建
                    IRasterPyramid pRasPyrmid;
                    pRasPyrmid = pRasterDataset as IRasterDataset 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;
                    mapControl.AddLayer(pLayer, 0);
                    OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl);
                    //OperateFile.ArchieveEagleEyeWhenAddRaster(mapControl, strFileName);
                    break;
                }
            }
        }
Esempio n. 10
0
        public void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm = txtOutNm.Text;

            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();

            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Building " + mStr + " Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                if (this.Text == "Create Composite Raster")
                {
                    outraster = rsUtil.createRaster(rsUtil.compositeBandFunction(rsBc));
                }
                else
                {
                    outraster = rsUtil.createRaster(rsUtil.calcCombineRasterFunction(rsBc));
                }
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished " + mStr + " Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private void btnExecute_Click(object sender, EventArgs e)
 {
     string rstNm = txtOutNm.Text;
     string mtypStr = cmbMergeType.Text;
     if (rstNm == null || rstNm == "")
     {
         MessageBox.Show("You must specify a output name","No Output",MessageBoxButtons.OK,MessageBoxIcon.Error);
         return;
     }
     if (lsbRaster.Items.Count < 1)
     {
         MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     IRaster[] rsArr = new IRaster[lsbRaster.Items.Count];
     for (int i = 0; i < lsbRaster.Items.Count; i++)
     {
         rsArr[i]=rstDic[lsbRaster.Items[i].ToString()];
     }
     if (mtypStr == null || mtypStr == "")
     {
         MessageBox.Show("You must specify a merge type","No merge type",MessageBoxButtons.OK,MessageBoxIcon.Error);
         return;
     }
     rasterUtil.mergeType mType = (rasterUtil.mergeType)Enum.Parse(typeof(rasterUtil.mergeType),mtypStr);
     this.Visible = false;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Merging Rasters. This may take a while...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     rp.Show();
     try
     {
         outraster = rsUtil.createRaster(rsUtil.calcMosaicFunction(rsArr,mType));//rsUtil.mergeRasterFunction(rsArr, mType, rstNm);//
         if (mp != null&&addToMap)
         {
             rp.Refresh();
             IRasterLayer rstLyr = new RasterLayerClass();
             rstLyr.CreateFromRaster(outraster);
             rstLyr.Visible = false;
             rstLyr.Name = rstNm;
             mp.AddLayer((ILayer)rstLyr);
         }
         outrastername = rstNm;
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         rp.addMessage(ex.ToString());
     }
     finally
     {
         DateTime dt2 = DateTime.Now;
         TimeSpan ts = dt2.Subtract(dt);
         string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
         rp.stepPGBar(100);
         rp.addMessage("Finished Mosaic Raster" + t);
         rp.enableClose();
         this.Close();
     }
 }
Esempio n. 12
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;
        }
 private void btnExecute_Click(object sender, EventArgs e)
 {
     string rstNm = txtOutNm.Text;
     string rstIn = cmbInRaster1.Text;
     if (rstNm == null || rstNm == ""||rstIn==null||rstIn=="")
     {
         MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (dgvRanges.Rows.Count < 1)
     {
         MessageBox.Show("You must have at least on range of values selected", "No Ranges", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     IRemapFilter rfilt = new RemapFilterClass();
     for (int i = 0; i < dgvRanges.Rows.Count; i++)
     {
         object obj1 = dgvRanges[0, i].Value;
         object obj2 = dgvRanges[1, i].Value;
         object obj3 = dgvRanges[2, i].Value;
         if ( Convert.IsDBNull(obj1)) obj1 = 0;
         if (Convert.IsDBNull(obj2)) obj2 = 0;
         if (Convert.IsDBNull(obj3)) obj3 = 0;
         double min = System.Convert.ToDouble(obj1);
         double max = System.Convert.ToDouble(obj2);
         double vl = System.Convert.ToDouble(obj3);
         rfilt.AddClass(min,max,vl);
     }
     this.Visible = false;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Remapping Rasters. This may take a while...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     try
     {
         outraster = rsUtil.returnRaster(rsUtil.calcRemapFunction(rstDic[rstIn],rfilt));
         if (mp != null && addToMap)
         {
             rp.addMessage("Calculating Statistics...");
             rp.Show();
             rp.Refresh();
             IRasterLayer rstLyr = new RasterLayerClass();
             //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
             rstLyr.CreateFromRaster(outraster);
             rstLyr.Name = rstNm;
             rstLyr.Visible = false;
             mp.AddLayer(rstLyr);
         }
         outrastername = rstNm;
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         rp.addMessage(ex.ToString());
     }
     finally
     {
         DateTime dt2 = DateTime.Now;
         TimeSpan ts = dt2.Subtract(dt);
         string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
         rp.stepPGBar(100);
         rp.addMessage("Finished Remapping Rasters" + t);
         rp.enableClose();
         this.Close();
     }
 }
        /// <summary>
        /// 生成风险等级栅格
        /// </summary>
        /// <param name="roadEvalName"></param>
        /// <param name="rains"></param>
        /// <param name="saveWorkspace"></param>
        /// <returns></returns>
        public bool RoadRaskCaulte(string roadEvalName, double rains, string saveWorkspace)
        {
            #region 备份
            //  IWorkspaceFactory rWorkspaceFactory = new RasterWorkspaceFactory();
            //  IWorkspace SWorkspace = rWorkspaceFactory.OpenFromFile(saveWorkspace, 0);
            //  IRasterWorkspace rasterWorkspace = SWorkspace as IRasterWorkspace;
            //  //栅格计算器 计算风险级数  先不要签你的三方协议 然后存储  表达式必须隔开
            //  IMapAlgebraOp mapAlgebra = new RasterMapAlgebraOpClass();
            //  IRasterDataset roadEvalRaster = OpenRasterDataSet(rasterWorkspace, roadEvalName);

            //  IGeoDataset geo1 = roadEvalRaster as IGeoDataset;

            //  mapAlgebra.BindRaster(geo1, "EvalRaster");
            //  IGeoDataset raskDataset = mapAlgebra.Execute("[EvalRaster] * 10 / 25");//然后存储  表达式必须间隔开
            //  //将生成的风险栅格重分类
            //  //<0.2	一级:可能性小
            //  //0.2-0.4	二级:可
            //  //能性较小
            //  //0.4-0.6	三级:可能性较大
            //  //0.6-0.8	四级:可能性大
            //  //>0.8	五级:可能性很大
            //  // 输入:raskDataset
            ////   输出:geoDataset_result
            //  IRasterBandCollection pRsBandCol = raskDataset as IRasterBandCollection;
            //  IRasterBand pRasterBand = pRsBandCol.Item(0);
            //  pRasterBand.ComputeStatsAndHist();
            //  IRasterStatistics pRasterStatistic = pRasterBand.Statistics;
            //  double dMaxValue = pRasterStatistic.Maximum;
            //  double dMinValue = pRasterStatistic.Minimum;
            //  IReclassOp pReclassOp = new RasterReclassOpClass();
            //  INumberRemap pNumRemap = new NumberRemapClass();
            //  //pNumRemap.MapRange(dMinValue, 0.2, 1);
            //  //pNumRemap.MapRange(0.2, 0.4, 2);
            //  //pNumRemap.MapRange(0.4, 0.6, 3);
            //  //pNumRemap.MapRange(0.6, dMaxValue, 4);
            //  //pNumRemap.MapRangeToNoData(-1000, 0);
            //  //pNumRemap.MapRange(0.8, 1000, 5);

            //  pNumRemap.MapRange(dMinValue,0.2, 0);
            //  pNumRemap.MapRange(0.2, 0.4, 1);
            //  pNumRemap.MapRange(0.4, 0.6, 2);
            //  pNumRemap.MapRange(0.6, 0.8, 3);
            //  pNumRemap.MapRange(0.8, dMaxValue, 4);
            //  IRemap pRemap = pNumRemap as IRemap;
            //  //IGeoDataset geoDataset_result = pReclassOp.ReclassByRemap(raskDataset, pRemap, true);
            //  IRaster pOutRaster = pReclassOp.ReclassByRemap(raskDataset, pRemap, false) as IRaster;
            //  IRasterLayer rasterLayer = new RasterLayerClass();
            //  rasterLayer.CreateFromRaster(pOutRaster);
            //  if (rasterLayer != null)
            //  {
            //      //string fullPath = Common.RoadshapePath+"道路.shp";
            //      rasterLayer.Name = "公路风险";
            //      Boolean IsEqual = false;
            //      //int Position = fullPath.LastIndexOf("\\");
            //      ////文件目录
            //      //string FilePath = fullPath.Substring(0, Position);
            //      //string ShpName = fullPath.Substring(Position + 1);
            //      //IWorkspaceFactory pWF;
            //      //pWF = new ShapefileWorkspaceFactory();
            //      //IFeatureWorkspace pFWS;
            //      //pFWS = (IFeatureWorkspace)pWF.OpenFromFile(FilePath, 0);
            //      //IFeatureClass pFClass;
            //      //pFClass = pFWS.OpenFeatureClass(ShpName);
            //      //IFeatureLayer pFLayer = new FeatureLayer();
            //      //pFLayer.FeatureClass = pFClass;

            //      for (int i = 0; i < MainFrom.m_mapControl.LayerCount;i++ )
            //      {
            //          ILayer ComLayer=MainFrom.m_mapControl.get_Layer(i);
            //          if (rasterLayer.Name == ComLayer.Name)
            //          {
            //              IsEqual = true;
            //          }
            //      }
            //      if (!IsEqual)
            //      {
            //          //MainFrom.m_mapControl.AddLayer((ILayer)pFLayer);
            //          MainFrom.m_mapControl.AddLayer(rasterLayer);
            //          IEnvelope envelope = rasterLayer.AreaOfInterest;
            //          MainFrom.m_mapControl.ActiveView.Extent = envelope;//缩放至图层
            //      }
            //  }
            //  return true;
            #endregion
            IWorkspaceFactory rWorkspaceFactory = new RasterWorkspaceFactory();
            IWorkspace        SWorkspace        = rWorkspaceFactory.OpenFromFile(saveWorkspace, 0);
            IRasterWorkspace  rasterWorkspace   = SWorkspace as IRasterWorkspace;
            //栅格计算器 计算风险级数  先不要签你的三方协议 然后存储  表达式必须隔开
            IMapAlgebraOp  mapAlgebra     = new RasterMapAlgebraOpClass();
            IRasterDataset roadEvalRaster = OpenRasterDataSet(rasterWorkspace, roadEvalName);
            IGeoDataset    geo1           = roadEvalRaster as IGeoDataset;
            mapAlgebra.BindRaster(geo1, "EvalRaster");
            IGeoDataset raskDataset = mapAlgebra.Execute("[EvalRaster] * " + rains + " / 25");//然后存储  表达式必须间隔开
            //将生成的风险栅格重分类
            //<0.2	一级:可能性小
            //0.2-0.4	二级:可
            //能性较小
            //0.4-0.6	三级:可能性较大
            //0.6-0.8	四级:可能性大
            //>0.8	五级:可能性很大
            // 输入:raskDataset
            //   输出:geoDataset_result
            IRasterBandCollection pRsBandCol  = raskDataset as IRasterBandCollection;
            IRasterBand           pRasterBand = pRsBandCol.Item(0);
            pRasterBand.ComputeStatsAndHist();
            IRasterStatistics            pRasterStatistic = pRasterBand.Statistics;
            double                       dMaxValue        = pRasterStatistic.Maximum;
            double                       dMinValue        = pRasterStatistic.Minimum;
            IReclassOp                   pReclassOp       = new RasterReclassOpClass();
            INumberRemap                 pNumRemap        = new NumberRemapClass();
            IDictionary <int, RoadRange> roadRanges       = this.roadRiskConfig.GetRoadRiskLevelFromConfig();
            foreach (var v in roadRanges)
            {
                pNumRemap.MapRange(v.Value.MinValue, v.Value.MaxValue, v.Key);
            }
            IRemap pRemap = pNumRemap as IRemap;
            //IGeoDataset geoDataset_result = pReclassOp.ReclassByRemap(raskDataset, pRemap, true);
            IRaster      pOutRaster  = pReclassOp.ReclassByRemap(raskDataset, pRemap, false) as IRaster;
            IRasterLayer rasterLayer = new RasterLayerClass();
            rasterLayer.CreateFromRaster(pOutRaster);
            if (rasterLayer != null)
            {
                rasterLayer.Name = "公路风险";
                for (int i = 0; i < MainFrom.m_mapControl.LayerCount; i++)
                {
                    ILayer ComLayer = MainFrom.m_mapControl.get_Layer(i);
                    if (rasterLayer.Name == ComLayer.Name)
                    {
                        MainFrom.m_mapControl.Map.DeleteLayer(ComLayer);
                    }
                }
                Common.funColorForRaster_Classify(rasterLayer, roadRanges.Count);
                IEnvelope envelope = rasterLayer.AreaOfInterest;
                MainFrom.m_mapControl.ActiveView.Extent = envelope;//缩放至图层
            }
            return(true);
        }
Esempio n. 15
0
        private IRasterLayer SetRsLayerClassifiedColor(IRaster pRaster)
        {
            IRasterClassifyColorRampRenderer pClassRen = new RasterClassifyColorRampRendererClass();
            IRasterRenderer pRasRen = (IRasterRenderer)pClassRen;

            //Set raster for the render and update
            pRasRen.Raster       = pRaster;
            pClassRen.ClassCount = 9;
            pRasRen.Update();
            //Create a color ramp to use
            //定义起点和终点颜色
            IColor    pFromColor = new RgbColorClass();
            IRgbColor pRgbColor  = (IRgbColor)pFromColor;

            pRgbColor.Red   = 255;
            pRgbColor.Green = 200;
            pRgbColor.Blue  = 0;
            IColor pToColor = new RgbColorClass();

            pRgbColor       = (IRgbColor)pToColor;
            pRgbColor.Red   = 0;
            pRgbColor.Green = 0;
            pRgbColor.Blue  = 255;
            //创建颜色分级
            IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();

            pRamp.Size      = 9;
            pRamp.FromColor = pFromColor;
            pRamp.ToColor   = pToColor;
            bool ok = true;

            pRamp.CreateRamp(out ok);

            //获得栅格统计数值
            IRasterBandCollection pRsBandCol = (IRasterBandCollection)pRaster;
            IRasterBand           pRsBand    = pRsBandCol.Item(0);

            pRsBand.ComputeStatsAndHist();
            IRasterStatistics pRasterStatistic = pRsBand.Statistics;
            double            dMaxValue        = pRasterStatistic.Maximum;
            double            dMinValue        = pRasterStatistic.Minimum;

            //Create symbol for the classes
            IFillSymbol pFSymbol   = new SimpleFillSymbolClass();
            double      LabelValue = Convert.ToDouble((dMaxValue - dMinValue) / 9);

            for (int i = 0; i < pClassRen.ClassCount; i++)
            {
                pFSymbol.Color = pRamp.get_Color(i);
                pClassRen.set_Symbol(i, (ISymbol)pFSymbol);
                double h1 = (LabelValue * i) + dMinValue;
                double h2 = (LabelValue * (i + 1)) + dMinValue;
                pClassRen.set_Label(i, h1.ToString() + "-" + h2.ToString());
            }

            //Update the renderer and plug into layer
            pRasRen.Update();
            IRasterLayer pRLayer = new RasterLayerClass();

            pRLayer.CreateFromRaster(pRaster);
            pRLayer.Renderer = (IRasterRenderer)pClassRen;
            return(pRLayer);
        }
Esempio n. 16
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm = cmbInRaster1.Text;
            string inRst2Nm = cmbInRaster2.Text;
            string outNmRst = txtOutName.Text;
            int    pChange  = trbPercent.Value;

            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (inRst2Nm == "" || inRst2Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNmRst == "" || outNmRst == null)
            {
                MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRaster rs1 = rstDic[inRst1Nm];
            IRaster rs2 = rstDic[inRst2Nm];

            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Creating Raster. This may take a while...");
            rp.addMessage("Calculating Statistics...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            rp.Refresh();
            normalization nm = new normalization(rsUtil.createIdentityRaster(rs1), rsUtil.createIdentityRaster(rs2), pChange, rsUtil);

            try
            {
                double[][] coef = nm.Coefficients;
                outraster     = rsUtil.createRaster(nm.OutRaster);
                outrastername = outNmRst;
                int bCnt = ((IRasterBandCollection)outraster).Count;
                for (int i = 0; i < bCnt; i++)
                {
                    double[] intSlp    = coef[i];
                    double   intercept = intSlp[0];
                    double   slope     = intSlp[1];
                    double   r2        = intSlp[2];
                    rp.addMessage("R2, Intercept, Slope (" + (i + 1).ToString() + ") = " + r2.ToString() + ", " + intercept.ToString() + ", " + slope.ToString());
                }
                if (!(txtModelPath.Text == "" || txtModelPath.Text == null))
                {
                    nm.writeModel(txtModelPath.Text);
                }
                if (mp != null && aM)
                {
                    //rsUtil.calcStatsAndHist(((IRaster2)outRs).RasterDataset);
                    IRasterLayer rsLyr = new RasterLayerClass();
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name    = outrastername;
                    rsLyr.Visible = false;
                    mp.AddLayer((ILayer)rsLyr);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Normalizing Image" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 17
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);
            }
        }
Esempio n. 18
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm   = txtOutNm.Text;
            string mtypStr = cmbMergeType.Text;

            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRaster[] rsArr = new IRaster[lsbRaster.Items.Count];
            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                rsArr[i] = rstDic[lsbRaster.Items[i].ToString()];
            }
            if (mtypStr == null || mtypStr == "")
            {
                MessageBox.Show("You must specify a merge type", "No merge type", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            rasterUtil.mergeType mType = (rasterUtil.mergeType)Enum.Parse(typeof(rasterUtil.mergeType), mtypStr);
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Merging Rasters. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                outraster = rsUtil.createRaster(rsUtil.calcMosaicFunction(rsArr, mType));//rsUtil.mergeRasterFunction(rsArr, mType, rstNm);//
                if (mp != null && addToMap)
                {
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Visible = false;
                    rstLyr.Name    = rstNm;
                    mp.AddLayer((ILayer)rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Mosaic Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string ftrNm = cmbSampleFeatureClass.Text;
            if (ftrNm == "" || ftrNm == null)
            {
                MessageBox.Show("You must have a sampling layer selected");
                return;
            }
            if (!System.IO.File.Exists(plrR.SasOutputFile))
            {
                MessageBox.Show("Could not find the sas estimate file. You either needed to first create the classificaiton model or select a feature dataset that has been used to create the model!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int paramLength = plrR.OutParameters.Length;
            int rsBndsCnt = lstRasterBands.Items.Count;
            int bCnt = 0;
            for (int i = 0; i < rsBndsCnt; i++)
            {
                bCnt = bCnt + ((IRasterBandCollection)rstDic[lstRasterBands.Items[i].ToString()]).Count;
            }
            if (bCnt < 1||(paramLength-1)!=bCnt)
            {
                MessageBox.Show("Param = " + (paramLength-1).ToString() + " BandCount = " + bCnt.ToString() + "\nYou must have the same number of rasters selected in the same order as parameter estimates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnViewOrder.PerformClick();
                return;

            }
            IRasterBandCollection rsBc = new RasterClass();
            for (int i = 0; i < rsBndsCnt; i++)
            {
                IRaster rs = rstDic[lstRasterBands.Items[i].ToString()];
                rsBc.AppendBands((IRasterBandCollection)rs);
            }
            this.Visible = false;
            plrR.InRaster = (IRaster)rsBc;

            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new esriUtil.Forms.RunningProcess.frmRunningProcessDialog(false);
            System.DateTime dt1 = System.DateTime.Now;
            rp.addMessage("Creating PLR Classification Raster.");
            rp.addMessage("Bands are organized as follows:\n\tBand1=MLC\n\tBand2=BaseCategory");
            int bcCnt = 3;
            foreach (string c in plrR.Categories)
            {
                rp.addMessage("\tBand" + bcCnt.ToString() + "=" + c);
                bcCnt += 1;
            }
            rp.addMessage("This may take some time...");
            rp.Show();
            rp.TopMost = true;
            rp.stepPGBar(20);
            rp.Refresh();
            IRaster rst = plrR.createModelRaster(seed);
            if (mp != null)
            {
                rp.addMessage("Adding Raster to map");
                rp.Refresh();
                IRasterLayer rsLyr1 = new RasterLayerClass();
                rsLyr1.CreateFromRaster(rst);
                rsLyr1.Name = "PLR_OUT";
                rsLyr1.Visible = false;
                mp.AddLayer(rsLyr1);
            }
            rp.stepPGBar(50);
            rp.addMessage("Finished creating raster");
            rp.Refresh();
            System.DateTime dt2 = System.DateTime.Now;
            System.TimeSpan ts = dt2.Subtract(dt1);
            string prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
            rp.addMessage(prcTime);
            rp.stepPGBar(100);
            rp.Refresh();
            rp.enableClose();
            this.Close();
            return;
        }
Esempio n. 20
0
        public static ILayer CreateLayer(ICatalogItem catalogItem)
        {
            if (catalogItem == null || catalogItem.Dataset==null)
                return null;

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

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

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

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

                    lyrNew = lyrRasterBand;
                    break;

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

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

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

            return lyrNew;
        }
        /// <summary>
        /// 风险因素等级划分
        /// </summary>
        /// <param name="RasterWorkspace"></param>
        /// <param name="roadEvalName"></param>
        /// <returns></returns>
        public static bool RaskCaulte(string RasterWorkspace, string roadEvalName)
        {
            IWorkspaceFactory rWorkspaceFactory = new RasterWorkspaceFactory();
            IWorkspace        SWorkspace        = rWorkspaceFactory.OpenFromFile(RasterWorkspace, 0);
            IRasterWorkspace  rasterWorkspace   = SWorkspace as IRasterWorkspace;
            //栅格计算器 计算风险级数  先不要签你的三方协议 然后存储  表达式必须隔开
            IMapAlgebraOp  mapAlgebra     = new RasterMapAlgebraOpClass();
            IRasterDataset roadEvalRaster = rasterWorkspace.OpenRasterDataset(roadEvalName);
            IGeoDataset    geo1           = roadEvalRaster as IGeoDataset;

            mapAlgebra.BindRaster(geo1, "EvalRaster");
            IGeoDataset raskDataset = mapAlgebra.Execute("[EvalRaster]");//然后存储  表达式必须间隔开
            //将生成的风险栅格重分类
            //<0.2	一级:可能性小
            //0.2-0.4	二级:可
            //能性较小
            //0.4-0.6	三级:可能性较大
            //0.6-0.8	四级:可能性大
            //>0.8	五级:可能性很大
            // 输入:raskDataset
            //   输出:geoDataset_result
            IRasterBandCollection pRsBandCol  = raskDataset as IRasterBandCollection;
            IRasterBand           pRasterBand = pRsBandCol.Item(0);

            pRasterBand.ComputeStatsAndHist();
            IRasterStatistics pRasterStatistic = pRasterBand.Statistics;
            double            dMaxValue        = pRasterStatistic.Maximum;
            double            dMinValue        = pRasterStatistic.Minimum;
            IReclassOp        pReclassOp       = new RasterReclassOpClass();
            INumberRemap      pNumRemap        = new NumberRemapClass();
            //等级参数
            List <double> raskRanges = new List <double>();

            for (int n = 0; n < 5; n++)
            {
                raskRanges.Add(dMinValue + (dMaxValue - dMinValue) * n / 4);
            }
            for (int m = 0; m < 4; m++)
            {
                pNumRemap.MapRange(raskRanges[m], raskRanges[m + 1], m + 1);
            }
            IRemap       pRemap      = pNumRemap as IRemap;
            IRaster      pOutRaster  = pReclassOp.ReclassByRemap(raskDataset, pRemap, false) as IRaster;
            IRasterLayer rasterLayer = new RasterLayerClass();

            rasterLayer.CreateFromRaster(pOutRaster);
            if (rasterLayer != null)
            {
                rasterLayer.Name = roadEvalName;
                for (int i = 0; i < MainFrom.m_mapControl.LayerCount; i++)
                {
                    ILayer ComLayer = MainFrom.m_mapControl.get_Layer(i);
                    if (rasterLayer.Name == ComLayer.Name)
                    {
                        MainFrom.m_mapControl.Map.DeleteLayer(ComLayer);
                    }
                }
                Common.funColorForRaster_Classify(rasterLayer, 4);
                IEnvelope envelope = rasterLayer.AreaOfInterest;
                MainFrom.m_mapControl.ActiveView.Extent = envelope;//缩放至图层
            }
            return(true);
        }
Esempio n. 22
0
        //Ϊդ��ͼ�����ݰ��մ���Сֵ�����ֵ�ķ�����ɫ
        public static IRasterLayer SetRsLayerClassifiedColor(IRaster pRaster)
        {
            IRasterClassifyColorRampRenderer pClassRen = new RasterClassifyColorRampRendererClass();
            IRasterRenderer pRasRen = pClassRen as RasterClassifyColorRampRendererClass;
            //Set raster for the render and update
            pRasRen.Raster = pRaster;
            pClassRen.ClassCount = 9;
            pRasRen.Update();
            //Create a color ramp to use
            //���������յ���ɫ
            IColor pFromColor = new RgbColorClass();
            IRgbColor pRgbColor = pFromColor as IRgbColor;
            pRgbColor.Red = 255;
            pRgbColor.Green = 200;
            pRgbColor.Blue = 0;
            IColor pToColor = new RgbColorClass();
            pRgbColor = pToColor as IRgbColor;
            pRgbColor.Red = 0;
            pRgbColor.Green = 0;
            pRgbColor.Blue = 255;
            //������ɫ�ּ�
            IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();
            pRamp.Size = 9;
            pRamp.FromColor = pFromColor;
            pRamp.ToColor = pToColor;
            bool ok = true;
            pRamp.CreateRamp(out ok);
            //���դ��ͳ����ֵ
            IRasterBandCollection pRsBandCol = pRaster as IRasterBandCollection;
            IRasterBand pRsBand = pRsBandCol.Item(0);
            pRsBand.ComputeStatsAndHist();
            IRasterStatistics pRasterStatistic = pRsBand.Statistics;
            double dMaxValue = pRasterStatistic.Maximum;
            double dMinValue = pRasterStatistic.Minimum;
            //Create symbol for the classes
            IFillSymbol pFSymbol = new SimpleFillSymbolClass();

            double LabelValue = Convert.ToDouble((dMaxValue - dMinValue) / 9);
            for (int i = 0; i <= pClassRen.ClassCount - 1; i++)
            {
                pFSymbol.Color = pRamp.get_Color(i);
                pClassRen.set_Symbol(i, pFSymbol as ISymbol);
                double h1 = (LabelValue * i) + dMinValue;
                double h2 = (LabelValue * (i + 1)) + dMinValue;
                pClassRen.set_Label(i, h1.ToString() + "��" + h2.ToString());
            }
            //Update the renderer and plug into layer
            pRasRen.Update();
            IRasterLayer pRLayer = new RasterLayerClass();
            pRLayer.CreateFromRaster(pRaster);
            pRLayer.Renderer = pClassRen as IRasterRenderer;
            return pRLayer;
        }
Esempio n. 23
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm = txtOutNm.Text;
            string rstIn = cmbInRaster1.Text;

            if (rstNm == null || rstNm == "" || rstIn == null || rstIn == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (dgvRanges.Rows.Count < 1)
            {
                MessageBox.Show("You must have at least on range of values selected", "No Ranges", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRemapFilter rfilt = new RemapFilterClass();

            for (int i = 0; i < dgvRanges.Rows.Count; i++)
            {
                object obj1 = dgvRanges[0, i].Value;
                object obj2 = dgvRanges[1, i].Value;
                object obj3 = dgvRanges[2, i].Value;
                if (Convert.IsDBNull(obj1))
                {
                    obj1 = 0;
                }
                if (Convert.IsDBNull(obj2))
                {
                    obj2 = 0;
                }
                if (Convert.IsDBNull(obj3))
                {
                    obj3 = 0;
                }
                double min = System.Convert.ToDouble(obj1);
                double max = System.Convert.ToDouble(obj2);
                double vl  = System.Convert.ToDouble(obj3);
                rfilt.AddClass(min, max, vl);
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Remapping Rasters. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                outraster = rsUtil.returnRaster(rsUtil.calcRemapFunction(rstDic[rstIn], rfilt));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Remapping Rasters" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 24
0
        //Ϊդ��ͼ�����ݽ���Ψһֵ��ɫ
        public static IRasterLayer GetRLayerUniqueColor(IRaster pRaster, double dMaxDis)
        {
            try
            {
                IRasterBandCollection pBandCol = pRaster as IRasterBandCollection;
                IRasterBand pBand = pBandCol.Item(0) as IRasterBand;
                bool ExistTable;
                ITable pTable = null;
                pBand.HasTable(out ExistTable);
                if (ExistTable == false)
                {
                    pTable = pBand.AttributeTable as ITable;
                }

                int iNumOfValues = pTable.RowCount(null);
                string sFieldName = "Value";
                int iFieldIndex = pTable.FindField(sFieldName);
                IRandomColorRamp pRamp = new RandomColorRampClass();
                pRamp.Size = iNumOfValues;
                pRamp.Seed = 100;
                bool a = true;
                pRamp.CreateRamp(out a);
                IFillSymbol pFSymbol = new SimpleFillSymbolClass();
                IRasterUniqueValueRenderer pUVRen = new RasterUniqueValueRendererClass();
                IRasterRenderer pRasRen = pUVRen as IRasterRenderer;
                pRasRen.Raster = pRaster;
                pRasRen.Update();
                pUVRen.HeadingCount = 1;
                pUVRen.set_Heading(0, "�ȼ�");
                pUVRen.set_ClassCount(0, iNumOfValues);
                pUVRen.Field = sFieldName;
                //��ʼѭ��������ɫ
                double LabelValue;
                double s = Convert.ToDouble(dMaxDis / 5);
                IRgbColor pRGBColor = new RgbColorClass();

                for (int i = 0; i < iNumOfValues - 1; i++)
                {
                    IColor pColor = pRamp.get_Color(i);
                    IRow pRow = pTable.GetRow(i);
                    string sLabel = "";
                    LabelValue = Convert.ToDouble(pRow.get_Value(iFieldIndex));
                    if (LabelValue >= 0 || LabelValue <= s)
                    {
                        sLabel = "0" + "��" + s.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    double h1 = s * 2;
                    if (LabelValue >= s || LabelValue <= s * 2)
                    {
                        sLabel = s.ToString() + "��" + h1.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    double h2 = s * 3;
                    if (LabelValue >= s * 2 || LabelValue <= s * 3)
                    {
                        sLabel = h1.ToString() + "��" + h2.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    double h3 = s * 4;
                    if (LabelValue >= s * 3 || LabelValue <= s * 4)
                    {
                        sLabel = h2.ToString() + "��" + h3.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    double h4 = s * 5;
                    if (LabelValue >= s * 4 || LabelValue <= s * 5)
                    {
                        sLabel = h3.ToString() + "��" + h4.ToString();
                        pRGBColor.Red = 0;
                        pRGBColor.Green = 112;
                        pRGBColor.Blue = 255;
                        pColor = pRGBColor as IColor;
                    }
                    pUVRen.AddValue(0, i, LabelValue);
                    pUVRen.set_Label(0, i, sLabel);

                    pFSymbol.Color = pColor;
                    pUVRen.set_Symbol(0, i, pFSymbol as ISymbol);

                }
                pRasRen.Update();
                IRasterLayer pRLayer = new RasterLayerClass();
                pRLayer.CreateFromRaster(pRaster);
                pRLayer.Renderer = pUVRen as IRasterRenderer;
                return pRLayer;
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
Esempio n. 25
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm = txtOutNm.Text;

            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (clbBands.CheckedItems.Count < 1)
            {
                MessageBox.Show("You must check at least on Raster Band", "No Bands", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            ILongArray lArr = new LongArrayClass();

            for (int i = 0; i < clbBands.CheckedItems.Count; i++)
            {
                string bandVl   = clbBands.CheckedItems[i].ToString();
                int    bndIndex = System.Convert.ToInt32(bandVl.Split(new char[] { '_' })[1]) - 1;
                lArr.Add(bndIndex);
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Extracting Bands From  Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                outraster = rsUtil.returnRaster(rsUtil.getBands(rstDic[cmbInRaster1.Text], lArr));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");

                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Extacting Bands" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private void btnClip_Click(object sender, EventArgs e)
 {
     string rstNm = cmbInRaster1.Text;
     string outNm = txtOutName.Text;
     string visStr = cmbVis.Text;
     string irStr = cmbIr.Text;
     if (visStr == "" || visStr == null || rstNm == "" || rstNm == null||irStr==""||irStr==null)
     {
         MessageBox.Show("You must have a raster layer selected and a valid visual and ir band index value", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (outNm == "" || outNm == null)
     {
         MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     this.Visible = false;
     int visVl = System.Convert.ToInt32(visStr)-1;
     int irVl = System.Convert.ToInt32(irStr)-1;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Making Raster. This may take a while...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     try
     {
         IRaster rst = rstDic[rstNm];
         outraster = rsUtil.returnRaster(rsUtil.calcNDVIFunction(rst, visVl, irVl));
         if (mp != null && addToMap)
         {
             rp.addMessage("Calculating Statistics...");
             rp.Show();
             rp.Refresh();
             IRasterLayer rstLyr = new RasterLayerClass();
             //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
             rstLyr.CreateFromRaster(outraster);
             rstLyr.Name = outNm;
             rstLyr.Visible = false;
             mp.AddLayer(rstLyr);
         }
         outrastername = outNm;
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         rp.addMessage(ex.ToString());
     }
     finally
     {
         DateTime dt2 = DateTime.Now;
         TimeSpan ts = dt2.Subtract(dt);
         string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
         rp.stepPGBar(100);
         rp.addMessage("Finished Making Raster" + t);
         rp.enableClose();
         this.Close();
     }
 }
        public void addFunctionRasterToMap(IMap map)
        {
            try
            {
                ofd.Title = "Add Function Model to map";
                ofd.Filter = "Function Dataset|*.fds|Batch Datasets|*.bch|NetCdf|*.nc";
                ofd.Multiselect = false;
                ofd.FilterIndex = 2;
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    FunctionDatasetPath = ofd.FileName;
                    int fIndex = ofd.FilterIndex;
                    string outName = "";
                    object outobj = null;
                    string outDesc = "";
                    if (fIndex == 1)
                    {
                        IRaster outRs;
                        createFunctionRaster(out outName, out outRs, out outDesc);
                        outobj = outRs;
                    }
                    else if (fIndex == 2)
                    {
                        createBatchRaster(out outName, out outobj, out outDesc);
                    }
                    else
                    {
                        createNetCdf(out outName, out outobj, out outDesc);
                    }
                    if (outobj is IFunctionRasterDataset)
                    {
                        IRasterLayer rsLyr = new RasterLayerClass();
                        rsLyr.CreateFromDataset((IRasterDataset)outobj);
                        rsLyr.Name = outName;
                        rsLyr.Visible = false;
                        map.AddLayer((ILayer)rsLyr);
                    }
                    else if (outobj is IRaster)
                    {
                        IRasterLayer rsLyr = new RasterLayerClass();
                        rsLyr.CreateFromRaster((IRaster)outobj);
                        rsLyr.Name = outName;
                        rsLyr.Visible = false;
                        map.AddLayer((ILayer)rsLyr);
                    }
                    else if (outobj is FeatureClass)
                    {
                        IFeatureLayer ftrLyr = new FeatureLayerClass();
                        ftrLyr.Name = outName;
                        ftrLyr.Visible = false;
                        ftrLyr.FeatureClass = (IFeatureClass)outobj;
                        map.AddLayer((ILayer)ftrLyr);
                    }
                    else if (outobj is Table)
                    {
                        IStandaloneTableCollection stCol = (IStandaloneTableCollection)map;
                        IStandaloneTable stTbl = new StandaloneTableClass();
                        stTbl.Table = (ITable)outobj;
                        stTbl.Name = outName;
                        stCol.AddStandaloneTable(stTbl);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("There was a problem parsing the model. Please check your model file");
                    }

                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Could not add output to the map:" + e.ToString(), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
 private void btnExecute_Click(object sender, EventArgs e)
 {
     string inRst1Nm = cmbInRaster1.Text;
     string txtNoDataVl = txtNodata.Text;
     int noVl = 0;
     if(!Int32.TryParse(txtNoDataVl,out noVl))noVl=0;
     string outNmRst = txtOutName.Text;
     if (inRst1Nm == "" || inRst1Nm == null)
     {
         MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
         return;
     }
     if (outNmRst == "" || outNmRst == null)
     {
         MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     IRaster rs1 = rstDic[inRst1Nm];
     this.Visible = false;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Creating Raster. This may take a while...");
     rp.addMessage("Calculating Statistics...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     rp.Show();
     rp.Refresh();
     try
     {
         outraster = rsUtil.returnRaster(rsUtil.setNullValue(rs1,noVl));
         outrastername = outNmRst;
         int bCnt = ((IRasterBandCollection)outraster).Count;
         if (mp != null && aM)
         {
             //rsUtil.calcStatsAndHist(((IRaster2)outRs).RasterDataset);
             IRasterLayer rsLyr = new RasterLayerClass();
             rsLyr.CreateFromRaster(outraster);
             rsLyr.Name = outrastername;
             rsLyr.Visible = false;
             mp.AddLayer((ILayer)rsLyr);
         }
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         rp.addMessage(ex.ToString());
         Console.WriteLine(ex.ToString());
     }
     finally
     {
         DateTime dt2 = DateTime.Now;
         TimeSpan ts = dt2.Subtract(dt);
         string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
         rp.stepPGBar(100);
         rp.addMessage("Finished setting null" + t);
         rp.enableClose();
         this.Close();
     }
 }
Esempio n. 29
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm = txtOutNm.Text;
            string rstIn = cmbInRaster1.Text;

            if (rstNm == null || rstNm == "" || rstIn == null || rstIn == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (dgvRanges.Rows.Count < 1)
            {
                MessageBox.Show("You must have at least on range of values selected", "No Ranges", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IStringArray strArr = new StrArrayClass();

            for (int i = 0; i < dgvRanges.Rows.Count; i++)
            {
                object obj1 = dgvRanges[1, i].Value;
                object obj2 = dgvRanges[2, i].Value;
                if (Convert.IsDBNull(obj1) || obj1 == null)
                {
                    obj1 = 0;
                }
                if (Convert.IsDBNull(obj2) || obj1 == null)
                {
                    obj2 = 0;
                }
                int           min  = System.Convert.ToInt32(obj1);
                int           max  = System.Convert.ToInt32(obj2);
                List <string> sLst = new List <string>();
                for (int j = min; j < max; j++)
                {
                    sLst.Add(j.ToString());
                }
                string ln = String.Join(" ", sLst.ToArray());
                strArr.Add(ln);
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Setting values to null. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                outraster = rsUtil.returnRaster(rsUtil.setValueRangeToNodata(rstDic[rstIn], strArr));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Setting values to null " + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 30
0
        private void iDW内插ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDW pIDW = new IDW();

            IGeoDataset pGeoDataset = pIDW.GetIDW((axMapControl1.Map.get_Layer(0) as IFeatureLayer).FeatureClass, "H", .013866668, 0.5, 2);

            IRaster pRaster = pGeoDataset as IRaster;

            // ILayerFile pLayerFile = new LayerFileClass();

            // pLayerFile.Open(@"..\\..\\..\\..\\..\\Idw_shp.lyr");

            IRasterLayer pRsterLayer = new RasterLayerClass();

            pRsterLayer.CreateFromRaster(pRaster);

            //  pRsterLayer.Renderer = (pLayerFile.Layer as IRasterLayer).Renderer;

            axMapControl1.AddLayer(pRsterLayer);
        }
Esempio n. 31
0
        private void btnClip_Click(object sender, EventArgs e)
        {
            string rstNm     = cmbInRaster1.Text;
            string outNm     = txtOutName.Text;
            string newXValue = txtValueX.Text;
            string newYValue = txtValueY.Text;

            if (newXValue == "" || newXValue == null || newYValue == "" || newYValue == null || rstNm == "" || rstNm == null)
            {
                MessageBox.Show("You must have a raster layer selected and valid x and y values", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNm == "" || outNm == null)
            {
                MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Transforming Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                IRaster rst = rstDic[rstNm];
                IFunctionRasterDataset fRst = rsUtil.createIdentityRaster(rst);
                double vlX = System.Convert.ToDouble(newXValue) * fRst.RasterInfo.CellSize.X;
                double vlY = System.Convert.ToDouble(newYValue) * fRst.RasterInfo.CellSize.Y;
                outraster = rsUtil.createRaster(rsUtil.shiftRasterFunction(rst, vlX, vlY));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");

                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = outNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = outNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Transforming Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm = cmbInRaster1.Text;
            string inRst2Nm = cmbInRaster2.Text;
            string inRst3Nm = cmbInRaster3.Text;
            string outNmRst = txtOutName.Text;
            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 1","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            if (inRst2Nm == "" || inRst2Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (inRst3Nm == "" || inRst3Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 3 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNmRst == "" || outNmRst == null)
            {
                MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            object rs1,rs2,rs3;
            if(rstDic.ContainsKey(inRst1Nm))
            {
                rs1 = rstDic[inRst1Nm];
            }
            else
            {
                MessageBox.Show("You must specify an input raster for In Raster 1", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if(rstDic.ContainsKey(inRst2Nm))
            {
                rs2 = rstDic[inRst2Nm];
            }
            else if(rsUtil.isNumeric(inRst2Nm))
            {
                rs2 = inRst2Nm;

            }
            else
            {
                MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rstDic.ContainsKey(inRst3Nm))
            {
                rs3 = rstDic[inRst3Nm];
            }
            else if (rsUtil.isNumeric(inRst3Nm))
            {
                rs3 = inRst3Nm;

            }
            else
            {
                MessageBox.Show("You must specify an input raster for In Raster 3 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;
            rp.addMessage("Creating Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                outraster = rsUtil.createRaster(rsUtil.conditionalRasterFunction(rs1, rs2, rs3));
                outrastername = outNmRst;
                if (mp != null && aM)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    //rsUtil.calcStatsAndHist(outraster);
                    IRasterLayer rsLyr = new RasterLayerClass();
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name = outrastername;
                    rsLyr.Visible = false;
                    mp.AddLayer((ILayer)rsLyr);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts = dt2.Subtract(dt);
                string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Conditional Analysis" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 33
0
        private void iDW空间差值ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //用反距离IDW插值生成的栅格图像
            IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass();

            // 输入点图层
            IFeatureClass pFeatureClass;
            IFeatureLayer pFeaturelayer;
            int           indexLayer = Convert.ToInt32(Interaction.InputBox("请输入IDW空间插值点图层下标", "字符串", "", 500, 250));

            pFeaturelayer = this.axMapControl1.Map.get_Layer(indexLayer) as IFeatureLayer;
            pFeatureClass = pFeaturelayer.FeatureClass;

            // Define the search radius
            IRasterRadius pRadius     = new RasterRadiusClass();
            object        maxDistance = Type.Missing;

            pRadius.SetVariable(12, ref maxDistance);

            //Create FeatureClassDescriptor using a value field
            IFeatureClassDescriptor pFCDescriptor = new FeatureClassDescriptorClass();
            string zValue = Interaction.InputBox("请输入特征字段(yelvsuA/FYyelvsuA)", "字符串", "", 500, 250);

            pFCDescriptor.Create(pFeatureClass, null, zValue);

            //set { cellsize for output raster in the environment
            object dCellSize = 113.039027413432;
            IRasterAnalysisEnvironment pEnv = new RasterAnalysis();

            pEnv = pInterpolationOp as IRasterAnalysisEnvironment;
            pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCellSize);
            object objectbarrier = Type.Missing;

            //Perform the interpolation
            IGeoDataset rasDataset = pInterpolationOp.IDW((IGeoDataset)pFCDescriptor, 2, pRadius, ref objectbarrier);
            IRaster     pOutRaster = rasDataset as IRaster;

            //Add output into ArcMap as a raster layer
            IRasterLayer pOutRasLayer = new RasterLayerClass();

            pOutRasLayer.CreateFromRaster(pOutRaster);
            this.axMapControl1.AddLayer(pOutRasLayer, 0);
            axMapControl1.ActiveView.Refresh();

            DialogResult dr = MessageBox.Show("插值成功,请选择是否进行分级渲染", "分级渲染选择",
                                              MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (dr == DialogResult.OK)
            {
                //用户选择确认的操作(分级渲染)
                IRasterLayer pRasterLayer = null;
                for (int i = 0; i < axMapControl1.LayerCount; i++)
                {
                    if (axMapControl1.get_Layer(i) is IRasterLayer)
                    {
                        pRasterLayer = axMapControl1.get_Layer(i) as IRasterLayer;
                    }
                }
                if (pRasterLayer == null)
                {
                    MessageBox.Show("当前图层不存在栅格图层");
                    return;
                }
                int number = Convert.ToInt32(Interaction.InputBox("请输入栅格影像分类数量(默认为10)", "字符串", "", 500, 250));
                if (number == 0)
                {
                    number = 10;
                }
                funColorForRaster_Classify(pRasterLayer, number);
                axMapControl1.ActiveView.Refresh();
            }
            else if (dr == DialogResult.Cancel)
            {
                //用户选择取消的操作
                return;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string ftrNm = cmbSampleFeatureClass.Text;
            string sasDir = cmbModelDir.Text;
            if (ftrNm == "" || ftrNm == null)
            {
                MessageBox.Show("You must have a Workspace selected");
                return;
            }
            if (sasDir == "" || sasDir == null)
            {
                MessageBox.Show("You must have a SAS modeled directory selected");
                return;
            }
            if (!System.IO.File.Exists(rR.SasOutputFile))
            {
                MessageBox.Show("Could not find the sas estimate file. You either needed to first create the classificaiton model or select a feature dataset that has been used to create the model!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int paramLength = rR.OutParameters.Length;
            int rsBndsCnt = lstRasterBands.Items.Count;
            int bCnt = 0;
            for (int i = 0; i < rsBndsCnt; i++)
            {
                bCnt = bCnt + ((IRasterBandCollection)rstDic[lstRasterBands.Items[i].ToString()]).Count;
            }
            if (bCnt < 1 || (paramLength - 1) != bCnt)
            {
                MessageBox.Show("Param = " + (paramLength - 1).ToString() + " BandCount = " + bCnt.ToString() + "\nYou must have the same number of rasters selected in the same order as parameter estimates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnViewOrder.PerformClick();
                return;

            }
            IRasterBandCollection rsBc = new RasterClass();
            for (int i = 0; i < rsBndsCnt; i++)
            {
                IRaster rs = rstDic[lstRasterBands.Items[i].ToString()];
                rsBc.AppendBands((IRasterBandCollection)rs);
            }
            this.Visible = false;
            rR.InRaster = (IRaster)rsBc;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new esriUtil.Forms.RunningProcess.frmRunningProcessDialog(false);
            System.DateTime dt1 = System.DateTime.Now;
            rp.addMessage("Creating Regression Raster.");
            rp.addMessage("Name of the out raster = " + sasDir + ". Bands are in the order of dependent variables");
            int bcnt = 1;
            foreach (string s in rR.Categories)
            {
                rp.addMessage("\tBand_" + bcnt.ToString() + " = " + s);
                bcnt++;
            }
            rp.addMessage("This may take some time...");
            rp.Show();
            rp.TopMost = true;
            rp.stepPGBar(20);
            rp.Refresh();
            try
            {
                outraster = rR.createModelRaster();
                outrastername = sasDir;
                if (mp != null && addToMap)
                {
                    rp.addMessage("Adding Rasters to map");
                    rp.Refresh();
                    IRasterLayer rsLyr1 = new RasterLayerClass();
                    rsLyr1.Name = outrastername;
                    rsLyr1.CreateFromRaster(outraster);
                    rsLyr1.Visible = false;
                    mp.AddLayer(rsLyr1);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception exc)
            {
                rp.addMessage(exc.ToString());
            }
            finally
            {
                rp.stepPGBar(50);
                rp.addMessage("Finished creating raster");
                rp.Refresh();
                System.DateTime dt2 = System.DateTime.Now;
                System.TimeSpan ts = dt2.Subtract(dt1);
                string prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
                rp.addMessage(prcTime);
                rp.stepPGBar(100);
                rp.Refresh();
                rp.enableClose();
                this.Close();
            }
            return;
        }
Esempio n. 35
0
        //添加数据工具;
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            index._tool_lable = HmMap.PublicMark.ButtonFunction.roam;

            openFileDialog1.Title       = "打开文件";
            openFileDialog1.Filter      = "矢量文件(*.shp)|*.shp|ArcMap工程文件(*.mxd)|*.mxd|栅格影像文件|*.bmp;*.tif;*.img;*.jpg";
            openFileDialog1.Multiselect = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string [] filename = openFileDialog1.FileNames;
                //添加矢量文件;

                if (System.IO.Path.GetExtension(openFileDialog1.FileName) == ".shp")
                {
                    for (int i = 0; i < filename.Length; i++)
                    {
                        string path       = System.IO.Path.GetDirectoryName(filename[i]);
                        string filename_1 = System.IO.Path.GetFileName(filename[i]);
                        axMapControl1.AddShapeFile(path, filename_1);
                    }
                }
                //添加ArcMaP工程文件;
                else if (System.IO.Path.GetExtension(openFileDialog1.FileName) == ".mxd")
                {
                    axMapControl1.LoadMxFile(openFileDialog1.FileName);
                }
                //加载栅格数据文件;
                else if (System.IO.Path.GetExtension(openFileDialog1.FileName) == ".tif" || System.IO.Path.GetExtension(openFileDialog1.FileName) == ".img" || System.IO.Path.GetExtension(openFileDialog1.FileName) == ".bmp" || System.IO.Path.GetExtension(openFileDialog1.FileName) == ".jpg")
                {
                    for (int i = 0; i < filename.Length; i++)
                    {
                        string path       = System.IO.Path.GetDirectoryName(filename[i]);
                        string filename_1 = System.IO.Path.GetFileName(filename[i]);

                        IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();
                        IWorkspace        pworkspace        = pWorkspaceFactory.OpenFromFile(path, 0);

                        IRasterWorkspace pRasterWorkspace = pworkspace as IRasterWorkspace;
                        IRasterDataset   prasterdataset   = pRasterWorkspace.OpenRasterDataset(filename_1);

                        IRasterPyramid3 jzt;
                        jzt = prasterdataset as IRasterPyramid3;
                        if (jzt != null)
                        {
                            if (!(jzt.Present))
                            {
                                jzt.Create();
                            }
                        }

                        IRaster raster;
                        raster = prasterdataset.CreateDefaultRaster();
                        IRasterLayer rasterLayer;
                        rasterLayer = new RasterLayerClass();
                        rasterLayer.CreateFromRaster(raster);
                        ILayer layer = rasterLayer as ILayer;
                        axMapControl1.AddLayer(layer);
                        axMapControl1.ActiveView.Refresh();
                    }
                }
            }
            else
            {
                MessageBox.Show("文件打开失败!");
                return;
            }
            axMapControl1.Refresh();
        }
Esempio n. 36
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)
            {

            }
        }
Esempio n. 37
0
        private void button_IDW_TIME_Click(object sender, EventArgs e)
        {
            object                  obj          = null;
            ILayer                  pLayer       = new FeatureLayerClass();
            IFeatureClass           featureClass = GetFeatureClass(@"D:\a_gis工程设计实践课\china\墓穴地shp\grave.shp");
            IGeoDataset             geo          = featureClass as IGeoDataset;
            object                  extend       = geo.Extent;
            object                  o            = null;
            IFeatureClassDescriptor feades       = new FeatureClassDescriptorClass();

            feades.Create(featureClass, null, "time_inter");
            IRasterRadius rasterrad = new RasterRadiusClass();

            rasterrad.SetVariable(12, ref obj);
            object                     dCell     = 0.014800000;//可以根据不同的点图层进行设置
            IInterpolationOp           interpla  = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment rasanaenv = interpla as IRasterAnalysisEnvironment;

            rasanaenv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCell);
            rasanaenv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extend, ref o);
            IGeoDataset g_GeoDS_Raster = interpla.IDW((IGeoDataset)feades, 2, rasterrad, ref obj);
            IRaster     pOutRsater     = (IRaster)g_GeoDS_Raster;

            IRasterLayer pOutRasterlayer = new RasterLayerClass();

            pOutRasterlayer.CreateFromRaster(pOutRsater);
            pOutRasterlayer.Name = "时间久远程度";
            PixelValue2          = Class_GetPixelValue(pOutRasterlayer);

            IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRendererClass();
            IRasterRenderer pRRend = pRClassRend as IRasterRenderer;

            IRaster pRaster = pOutRasterlayer.Raster;
            IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection;
            IRasterBand           pRBand    = pRBandCol.Item(0);

            if (pRBand.Histogram == null)
            {
                pRBand.ComputeStatsAndHist();
            }
            pRRend.Raster          = pRaster;
            pRClassRend.ClassCount = 10;
            pRRend.Update();

            IRgbColor pFromColor = new RgbColorClass();

            pFromColor.Red   = 135;//天蓝色
            pFromColor.Green = 206;
            pFromColor.Blue  = 235;
            IRgbColor pToColor = new RgbColorClass();

            pToColor.Red   = 124;//草坪绿
            pToColor.Green = 252;
            pToColor.Blue  = 0;

            IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();

            colorRamp.Size      = 10;
            colorRamp.FromColor = pFromColor;
            colorRamp.ToColor   = pToColor;
            bool createColorRamp;

            colorRamp.CreateRamp(out createColorRamp);

            IFillSymbol fillSymbol = new SimpleFillSymbolClass();

            for (int i = 0; i < pRClassRend.ClassCount; i++)
            {
                fillSymbol.Color = colorRamp.get_Color(i);
                pRClassRend.set_Symbol(i, fillSymbol as ISymbol);
                pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00"));
            }
            pOutRasterlayer.Renderer = pRRend;



            this.axMapControl1.AddLayer(pOutRasterlayer);

            //两种方法的结合后
        }
 private void btnExecute_Click(object sender, EventArgs e)
 {
     string inRst1Nm = cmbInRaster1.Text;
     string inRst2Nm = cmbInRaster2.Text;
     string outNmRst = txtOutName.Text;
     int pChange = trbPercent.Value;
     if (inRst1Nm == "" || inRst1Nm == null)
     {
         MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
         return;
     }
     if (inRst2Nm == "" || inRst2Nm == null)
     {
         MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (outNmRst == "" || outNmRst == null)
     {
         MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     IRaster rs1 = rstDic[inRst1Nm];
     IRaster rs2 = rstDic[inRst2Nm];
     this.Visible = false;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Creating Raster. This may take a while...");
     rp.addMessage("Calculating Statistics...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     rp.Show();
     rp.Refresh();
     normalization nm = new normalization(rsUtil.createIdentityRaster(rs1), rsUtil.createIdentityRaster(rs2), pChange, rsUtil);
     try
     {
         double[][] coef = nm.Coefficients;
         outraster = rsUtil.createRaster(nm.OutRaster);
         outrastername = outNmRst;
         int bCnt = ((IRasterBandCollection)outraster).Count;
         for (int i = 0; i < bCnt; i++)
         {
             double[] intSlp  = coef[i];
             double intercept = intSlp[0];
             double slope = intSlp[1];
             double r2 = intSlp[2];
             rp.addMessage("R2, Intercept, Slope (" + (i+1).ToString() + ") = " + r2.ToString() + ", " + intercept.ToString() + ", " + slope.ToString());
         }
         if (mp != null && aM)
         {
             //rsUtil.calcStatsAndHist(((IRaster2)outRs).RasterDataset);
             IRasterLayer rsLyr = new RasterLayerClass();
             rsLyr.CreateFromRaster(outraster);
             rsLyr.Name = outrastername;
             rsLyr.Visible = false;
             mp.AddLayer((ILayer)rsLyr);
         }
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         rp.addMessage(ex.ToString());
         Console.WriteLine(ex.ToString());
     }
     finally
     {
         DateTime dt2 = DateTime.Now;
         TimeSpan ts = dt2.Subtract(dt);
         string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
         rp.stepPGBar(100);
         rp.addMessage("Finished Normalizing Image" + t);
         rp.enableClose();
         this.Close();
     }
 }
Esempio n. 39
0
        private void btn_2e_Click(object sender, EventArgs e)
        {
            ILayer        pLayer       = new FeatureLayerClass();
            IFeatureClass featureClass = GetFeatureClass(@"D:\a_gis工程设计实践课\china\墓穴地shp\grave.shp");
            IGeoDataset   geo          = featureClass as IGeoDataset;

            object extend = geo.Extent;
            object o      = null;
            IFeatureClassDescriptor feades = new FeatureClassDescriptorClass();

            feades.Create(featureClass, null, "area");
            IRasterRadius rasterrad = new RasterRadiusClass();

            rasterrad.SetVariable(12, ref o);
            object                     dCell     = 0.014800000;//可以根据不同的点图层进行设置
            IInterpolationOp           interpla  = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment rasanaenv = interpla as IRasterAnalysisEnvironment;

            rasanaenv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCell);
            rasanaenv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extend, ref o);
            IGeoDataset  g_GeoDS_Raster  = interpla.IDW((IGeoDataset)feades, 2, rasterrad, ref o);
            IRaster      pOutRsater      = (IRaster)g_GeoDS_Raster;
            IRasterLayer pOutRasterlayer = new RasterLayerClass();

            pOutRasterlayer.CreateFromRaster(pOutRsater);
            pOutRasterlayer.Name = "两个因素都考虑";

            //IRaster raster = pOutRasterlayer.Raster;
            IRaster2 raster2 = (IRaster2)pOutRsater;
            // 指定像素块大小
            IPnt pntBlock = new PntClass();

            pntBlock.X = 1280;
            pntBlock.Y = 1280;
            //创建一个光标以给定像素块大小
            //定义RasterCursor初始化,参数设为null,内部自动设置PixelBlock大小
            //IRasterCursor pRasterCursor = pRaster2.CreateCursorEx(null);
            IRasterCursor rasterCursor = raster2.CreateCursorEx(null);
            //控制像素块级别的编辑操作
            IRasterEdit rasterEdit = raster2 as IRasterEdit;

            if (rasterEdit.CanEdit())
            {
                //得到一段光栅带
                IRasterBandCollection bandCollection = (IRasterBandCollection)pOutRsater;
                System.Array          pixels;
                IPnt   pnt = null;
                object value;
                int    bandCount = bandCollection.Count;
                //创建像素块
                IPixelBlock3 pixelBlock3 = null;
                int          blockWidth  = 0;
                int          blockHeight = 0;
                double       temp        = 0;
                do
                {
                    pixelBlock3 = rasterCursor.PixelBlock as IPixelBlock3;
                    blockWidth  = pixelBlock3.Width;
                    blockHeight = pixelBlock3.Height;
                    for (int k = 0; k < bandCount; k++)
                    {
                        //指定平面的像素的数组
                        pixels = (System.Array)pixelBlock3.get_PixelData(k);

                        for (int i = 0; i < blockWidth; i++)
                        {
                            for (int j = 0; j < blockHeight; j++)
                            {
                                //value = pixels.GetValue(i, j);

                                ////if (Convert.ToInt32(value) == 0)
                                //{
                                //设置像素的颜色值
                                temp = PixelValue1[i, j] + PixelValue2[i, j];
                                pixels.SetValue((int)temp, i, j);
                                //}
                            }
                        }
                        pixelBlock3.set_PixelData(k, pixels);
                    }
                    pnt = rasterCursor.TopLeft;
                    rasterEdit.Write(pnt, (IPixelBlock)pixelBlock3);
                }while (rasterCursor.Next());
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);



                //渲染
                IRasterClassifyColorRampRenderer pRClassRend = new RasterClassifyColorRampRendererClass();
                IRasterRenderer pRRend = pRClassRend as IRasterRenderer;

                IRaster pRaster = pOutRasterlayer.Raster;
                IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection;
                IRasterBand           pRBand    = pRBandCol.Item(0);
                if (pRBand.Histogram == null)
                {
                    pRBand.ComputeStatsAndHist();
                }
                pRRend.Raster          = pRaster;
                pRClassRend.ClassCount = 10;
                pRRend.Update();

                IRgbColor pFromColor = new RgbColorClass();
                pFromColor.Red   = 135;//天蓝色
                pFromColor.Green = 206;
                pFromColor.Blue  = 235;
                IRgbColor pToColor = new RgbColorClass();
                pToColor.Red   = 124;//草坪绿
                pToColor.Green = 252;
                pToColor.Blue  = 0;

                IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
                colorRamp.Size      = 10;
                colorRamp.FromColor = pFromColor;
                colorRamp.ToColor   = pToColor;
                bool createColorRamp;
                colorRamp.CreateRamp(out createColorRamp);

                IFillSymbol fillSymbol = new SimpleFillSymbolClass();

                for (int i = 0; i < pRClassRend.ClassCount; i++)
                {
                    fillSymbol.Color = colorRamp.get_Color(i);
                    pRClassRend.set_Symbol(i, fillSymbol as ISymbol);
                    pRClassRend.set_Label(i, pRClassRend.get_Break(i).ToString("0.00"));
                }
                pOutRasterlayer.Renderer = pRRend;
                this.axMapControl1.AddLayer(pOutRasterlayer);
            }
        }
Esempio n. 40
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                 pMapAlgebraOp= new RasterMapAlgebraOpClass();

                string strExpression = "";
                string dP = "",dCN="";
                dP = "[" + this.cmbPcp.Text + "]";
                dCN = "[" + this.cmbCN.Text + "]";

                ILayer pLayer = null;
                IRaster pRater = null;
                IGeoDataset pGeoDataset = null;
                pLayer = this.pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap,this.cmbPcp.Text));
                pRater=(pLayer as IRasterLayer).Raster;
                pGeoDataset = pRater as IGeoDataset;
                pMapAlgebraOp.BindRaster(pGeoDataset, pLayer.Name);

                pLayer = this.pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbCN.Text));
                pRater = (pLayer as IRasterLayer).Raster;
                pGeoDataset = pRater as IGeoDataset;
                pMapAlgebraOp.BindRaster(pGeoDataset, pLayer.Name);
                pLayer = null;
                pRater = null;
                pGeoDataset = null;
                // S=25400/CN-254
                // Q=(P-0.2S)^2/(P+0.8S)  P>0.2S
                // Q=0  P>0.2S

                //Con(P>0.2S,(P-0.2S)^2/(P+0.8S),0)
                //Con(P>0.2*(25400/CN-254),(P-0.2*(25400/CN-254))^2/(P+0.8*(25400/CN-254)),0)

                strExpression = "25400.0 / ("+dCN+" * 1.0) - 254";
                IGeoDataset pGeoDsS = pMapAlgebraOp.Execute(strExpression);
                pMapAlgebraOp.BindRaster(pGeoDsS, "S");

                string dS="[S]";
                string saveFileName = this.txtSavePath.Text.Trim();
                if (saveFileName == "")
                {
                    strExpression = "Con(" + dP + " > 0.2 * " + dS + ",(" + dP + " - 0.2 * " + dS + ") * (" + dP + " - 0.2 * " + dS + ") / (" + dP + " + 0.8 * " + dS + "),0)";

                }
                else
                {
                    strExpression =saveFileName+" = " +strExpression;
                }
                IGeoDataset pGeoDsQ = pMapAlgebraOp.Execute(strExpression);

                IRaster pOutRaster = pGeoDsQ as IRaster;
                IRasterLayer pOutRasterLayer = new RasterLayerClass();
                //pOutRasterLayer = SetStretchRenderer(pOutRaster);
                pOutRasterLayer.CreateFromRaster(pOutRaster);
                pMap.AddLayer(pOutRasterLayer);
                pGeoDsQ = null;
                pGeoDsS = null;
                pMapAlgebraOp = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
Esempio n. 41
0
        private void btnClip_Click(object sender, EventArgs e)
        {
            string rstNm  = cmbInRaster1.Text;
            string outNm  = txtOutName.Text;
            string visStr = cmbVis.Text;
            string irStr  = cmbIr.Text;

            if (visStr == "" || visStr == null || rstNm == "" || rstNm == null || irStr == "" || irStr == null)
            {
                MessageBox.Show("You must have a raster layer selected and a valid visual and ir band index value", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNm == "" || outNm == null)
            {
                MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Visible = false;
            int visVl = System.Convert.ToInt32(visStr) - 1;
            int irVl  = System.Convert.ToInt32(irStr) - 1;

            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Making Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                IRaster rst = rstDic[rstNm];
                outraster = rsUtil.returnRaster(rsUtil.calcNDVIFunction(rst, visVl, irVl));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = outNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = outNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Making Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm = cmbRaster.Text;
            string inFocalStat = cmbFocalStat.Text;

            string outNmRst = txtOutName.Text;
            int clms = System.Convert.ToInt32(nudColumns.Value);

            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            if (inFocalStat == "" || inFocalStat == null)
            {
                MessageBox.Show("You must specify an Aggregation Statistic", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (outNmRst == "" || outNmRst == null)
            {
                MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            IRaster rs1 = rstDic[inRst1Nm];
            IRaster outRs = null;
            rasterUtil.focalType fcType = (rasterUtil.focalType)Enum.Parse(typeof(rasterUtil.focalType), inFocalStat);
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;
            rp.addMessage("Creating Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {

                outRs = rsUtil.createRaster(rsUtil.calcAggregationFunction(rs1,clms,fcType));

                outraster = outRs;
                outrastername = outNmRst;
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rsLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name = OutRasterName;
                    rsLyr.Visible = false;
                    mp.AddLayer(rsLyr);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts = dt2.Subtract(dt);
                string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Aggregation Analysis" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 43
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            int i = 0; int j = 0;

            if (string.IsNullOrEmpty(this.ComboBoxInLayer.Text))
            {
                MessageBox.Show("请选择需要二值化的图层!", "栅格二值化", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            int intLyrCount = frm.mainMapControl.LayerCount;

            for (i = 0; i <= intLyrCount - 1; i++)
            {
                if ((frm.mainMapControl.Map.get_Layer(i).Name == this.ComboBoxInLayer.Text.Trim()))
                {
                    IRasterLayer   pRasterLayer  = frm.mainMapControl.get_Layer(i) as IRasterLayer;
                    IRaster2       raster        = pRasterLayer.Raster as IRaster2;
                    IRasterDataset rasterDataset = raster.RasterDataset;

                    IRasterBandCollection dirBandCollection = (IRasterBandCollection)rasterDataset;
                    IRasterBand           dirRasterBand     = dirBandCollection.Item(0);
                    IRawPixels            dirRawPixels      = (IRawPixels)dirRasterBand;

                    IPnt         pixelBlockOrigin = null;
                    IPnt         dirBlockSize     = new DblPntClass();
                    IRasterProps dirProps         = (IRasterProps)dirRawPixels;
                    int          dirColumns       = dirProps.Width;       //列数
                    int          dirRows          = dirProps.Height;      //行数

                    IPixelBlock3 dirPixelBlock = (IPixelBlock3)dirRawPixels.CreatePixelBlock(dirBlockSize);
                    dirRawPixels.Read(pixelBlockOrigin, (IPixelBlock)dirPixelBlock);

                    System.Array array;
                    array = (System.Array)dirPixelBlock.get_PixelDataByRef(0);//获取栅格数组

                    int min;
                    if (textBox1.Text == "")
                    {
                        min = 20;
                    }
                    else
                    {
                        min = Convert.ToInt32(textBox1.Text);
                    }
                    /////获得栅格数据像元值
                    double[,] b = new double[dirRows, dirColumns];
                    double value;
                    string strExcute = null;
                    for (int row = 0; row < dirRows; row++)
                    {
                        for (int col = 0; col < dirColumns; col++)
                        {
                            b[row, col] = Convert.ToSingle(array.GetValue(col, row));
                            /////阈值判断
                            if (b[row, col] > min)
                            {
                                value = 1;
                            }
                            else
                            {
                                value = 0;
                            }
                            strExcute = Convert.ToString(value);
                        }
                    }
                    IGeoDataset   tempGeodata1  = (IGeoDataset)pRster;
                    IMapAlgebraOp pMapAlgebraOp = new RasterMapAlgebraOpClass();

                    //设置栅格运算空间
                    IRasterAnalysisEnvironment pRasterAnalysisEnvironment = (IRasterAnalysisEnvironment)pMapAlgebraOp;
                    IWorkspaceFactory          pWorkspaceFactory          = new RasterWorkspaceFactoryClass();

                    string outPath      = null;
                    string outLayerName = null;
                    outPath = this.TxtBox.Text.Trim();
                    j       = this.TxtBox.Text.Trim().LastIndexOf("\\");

                    outPath      = this.TxtBox.Text.Substring(0, j);
                    outLayerName = this.TxtBox.Text.Substring(j + 1);
                    string DataSetName = this.TxtBox.Text.Substring(j + 1);

                    //设置输出空间
                    IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(outPath, 0);
                    pRasterAnalysisEnvironment.OutWorkspace = pWorkspace;
                    IGeoDataset  outGetDataset = pMapAlgebraOp.Execute(strExcute);
                    IRasterLayer pCreatRalyr   = new RasterLayerClass();
                    pCreatRalyr.CreateFromRaster((IRaster)outGetDataset);

                    pCreatRalyr.Name = outLayerName;
                    frm.mainMapControl.AddLayer(pCreatRalyr);
                    break;
                }
            }
        }
 private void frmFunctionalModeling_FormClosing(object sender, FormClosingEventArgs e)
 {
     for (int i = 0; i < dgvOutputs.RowCount; i++)
     {
         DataGridViewCellCollection cl = dgvOutputs.Rows[i].Cells;
         string rsNm = cl[0].Value.ToString();
         bool tst = System.Convert.ToBoolean(cl[1].Value);
         if (tst == true)
         {
             IRaster rs = rsultDic[rsNm];
             IRasterLayer rsLyr = new RasterLayerClass();
             rsLyr.CreateFromRaster(rs);
             rsLyr.Name = rsNm;
             rsLyr.Visible = false;
             mp.AddLayer((ILayer)rsLyr);
         }
     }
 }
Esempio n. 45
0
        private void button1_Click(object sender, EventArgs e)
        {
            string ftrNm  = cmbSampleFeatureClass.Text;
            string sasDir = cmbModelDir.Text;

            if (ftrNm == "" || ftrNm == null)
            {
                MessageBox.Show("You must have a Workspace selected");
                return;
            }
            if (sasDir == "" || sasDir == null)
            {
                MessageBox.Show("You must have a SAS modeled directory selected");
                return;
            }
            if (!System.IO.File.Exists(rR.SasOutputFile))
            {
                MessageBox.Show("Could not find the sas estimate file. You either needed to first create the classificaiton model or select a feature dataset that has been used to create the model!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int paramLength = rR.OutParameters.Length;
            int rsBndsCnt   = lstRasterBands.Items.Count;
            int bCnt        = 0;

            for (int i = 0; i < rsBndsCnt; i++)
            {
                bCnt = bCnt + ((IRasterBandCollection)rstDic[lstRasterBands.Items[i].ToString()]).Count;
            }
            if (bCnt < 1 || (paramLength - 1) != bCnt)
            {
                MessageBox.Show("Param = " + (paramLength - 1).ToString() + " BandCount = " + bCnt.ToString() + "\nYou must have the same number of rasters selected in the same order as parameter estimates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnViewOrder.PerformClick();
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();

            for (int i = 0; i < rsBndsCnt; i++)
            {
                IRaster rs = rstDic[lstRasterBands.Items[i].ToString()];
                rsBc.AppendBands((IRasterBandCollection)rs);
            }
            this.Visible = false;
            rR.InRaster  = (IRaster)rsBc;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new esriUtil.Forms.RunningProcess.frmRunningProcessDialog(false);
            System.DateTime dt1 = System.DateTime.Now;
            rp.addMessage("Creating Regression Raster.");
            rp.addMessage("Name of the out raster = " + sasDir + ". Bands are in the order of dependent variables");
            int bcnt = 1;

            foreach (string s in rR.Categories)
            {
                rp.addMessage("\tBand_" + bcnt.ToString() + " = " + s);
                bcnt++;
            }
            rp.addMessage("This may take some time...");
            rp.Show();
            rp.TopMost = true;
            rp.stepPGBar(20);
            rp.Refresh();
            try
            {
                outraster     = rR.createModelRaster();
                outrastername = sasDir;
                if (mp != null && addToMap)
                {
                    rp.addMessage("Adding Rasters to map");
                    rp.Refresh();
                    IRasterLayer rsLyr1 = new RasterLayerClass();
                    rsLyr1.Name = outrastername;
                    rsLyr1.CreateFromRaster(outraster);
                    rsLyr1.Visible = false;
                    mp.AddLayer(rsLyr1);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception exc)
            {
                rp.addMessage(exc.ToString());
            }
            finally
            {
                rp.stepPGBar(50);
                rp.addMessage("Finished creating raster");
                rp.Refresh();
                System.DateTime dt2     = System.DateTime.Now;
                System.TimeSpan ts      = dt2.Subtract(dt1);
                string          prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
                rp.addMessage(prcTime);
                rp.stepPGBar(100);
                rp.Refresh();
                rp.enableClose();
                this.Close();
            }
            return;
        }
Esempio n. 46
0
        //Ϊդ��ͼ�����ݽ���������ɫ
        public static IRasterLayer SetStretchRenderer(IRaster pRaster)
        {
            try
            {
                //������ɫ���QIդ����ɫ
                IRasterStretchColorRampRenderer pStretchRen = new RasterStretchColorRampRendererClass();
                IRasterRenderer pRasRen = pStretchRen as IRasterRenderer;
                //Ϊ��ɫ�͸�������դ������
                pRasRen.Raster = pRaster;
                pRasRen.Update();
                //���������յ���ɫ
                IColor pFromColor = new RgbColorClass();
                IRgbColor pRgbColor = pFromColor as IRgbColor;
                pRgbColor.Red = 255;
                pRgbColor.Green = 0;
                pRgbColor.Blue = 0;
                IColor pToColor = new RgbColorClass();
                pRgbColor = pToColor as IRgbColor;
                pRgbColor.Red = 0;
                pRgbColor.Green = 255;
                pRgbColor.Blue = 0;
                //������ɫ�ּ�
                IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();
                pRamp.Size = 255;
                pRamp.FromColor = pFromColor;
                pRamp.ToColor = pToColor;
                bool ok = true;
                pRamp.CreateRamp(out ok);
                //����ɫ�ּ�������ɫ�в�ѡ��һ������
                pStretchRen.BandIndex = 0;
                pStretchRen.ColorRamp = pRamp;
                pRasRen.Update();
                IRasterLayer pRLayer = new RasterLayerClass();
                pRLayer.CreateFromRaster(pRaster);
                pRLayer.Renderer = pStretchRen as IRasterRenderer;
                return pRLayer;

            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
                return null;
            }
        }
Esempio n. 47
0
        public void btnClip_Click(object sender, EventArgs e)
        {
            string rstNm = cmbInRaster1.Text;
            string outNm = txtOutName.Text;

            if (rstNm == "" || rstNm == null)
            {
                MessageBox.Show("You must have a raster layer selected and a valid value", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNm == "" || outNm == null)
            {
                MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Transforming Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                IRaster rst = rstDic[rstNm];
                switch (sType)
                {
                case rasterUtil.surfaceType.SLOPE:
                    outraster = rsUtil.returnRaster(rsUtil.calcSlopeFunction(rst));
                    break;

                case rasterUtil.surfaceType.ASPECT:
                    outraster = rsUtil.createRaster(rsUtil.calcAspectFunction(rst));
                    break;

                case rasterUtil.surfaceType.EASTING:
                    outraster = rsUtil.createRaster(rsUtil.calcEastWestFunction(rst));
                    break;

                case rasterUtil.surfaceType.NORTHING:
                    outraster = rsUtil.createRaster(rsUtil.calcNorthSouthFunction(rst));
                    break;

                default:
                    outraster = rsUtil.createRaster(rsUtil.flipRasterFunction(rst));
                    break;
                }

                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = outNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = outNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Setting Values Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 48
0
        //Ϊդ��ͼ�����ݽ��з�����ɫ
        public static IRasterLayer GetRLayerClassifyColor(IRaster pRaster, double dMaxDis)
        {
            IRasterClassifyColorRampRenderer pClassRen = new RasterClassifyColorRampRendererClass();
            IRasterRenderer pRasRen = pClassRen as RasterClassifyColorRampRendererClass;
            //Set raster for the render and update
            pRasRen.Raster = pRaster;
            pClassRen.ClassCount = 10;
            pRasRen.Update();
            //Create a color ramp to use
            //���������յ���ɫ
            IColor pFromColor = new RgbColorClass();
            IRgbColor pRgbColor = pFromColor as IRgbColor;
            pRgbColor.Red = 255;
            pRgbColor.Green = 0;
            pRgbColor.Blue = 0;
            IColor pToColor = new RgbColorClass();
            pRgbColor = pToColor as IRgbColor;
            pRgbColor.Red = 0;
            pRgbColor.Green = 255;
            pRgbColor.Blue = 0;
            //������ɫ�ּ�
            IAlgorithmicColorRamp pRamp = new AlgorithmicColorRampClass();
            pRamp.Size = 10;
            pRamp.FromColor = pFromColor;
            pRamp.ToColor = pToColor;
            bool ok = true;
            pRamp.CreateRamp(out ok);
            //Create symbol for the classes
            IFillSymbol pFSymbol = new SimpleFillSymbolClass();

            double LabelValue = Convert.ToDouble(dMaxDis / 6);
            for (int i = 0; i <= pClassRen.ClassCount - 1; i++)
            {
                pFSymbol.Color = pRamp.get_Color(i);
                pClassRen.set_Symbol(i, pFSymbol as ISymbol);
                double h1 = LabelValue * i;
                double h2 = LabelValue * (i + 1);
                pClassRen.set_Label(i, h1.ToString() + "��" + h2.ToString());
            }
            //Update the renderer and plug into layer
            pRasRen.Update();
            IRasterLayer pRLayer = new RasterLayerClass();
            pRLayer.CreateFromRaster(pRaster);
            pRLayer.Renderer = pClassRen as IRasterRenderer;
            return pRLayer;
        }
Esempio n. 49
0
        public void underInit()
        {
            IRaster2              raster2     = m_raster as IRaster2;
            IRasterDataset        rstDataset  = raster2.RasterDataset;
            IRasterBandCollection rstBandColl = rstDataset as IRasterBandCollection;

            if (rstBandColl.Count > 1)
            {
                MessageBox.Show("暂不支持多波段的滤波计算", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRasterProps pRasterProps = raster2 as IRasterProps;
            int          Height       = pRasterProps.Height;
            int          Width        = pRasterProps.Width;
            double       cellsizex    = pRasterProps.MeanCellSize().X;

            double            cellsizey        = pRasterProps.MeanCellSize().Y;
            rstPixelType      pixelType        = pRasterProps.PixelType;
            ISpatialReference spatialReference = pRasterProps.SpatialReference;
            //MessageBox.Show(spatialReference.Name.ToString());
            IWorkspaceFactory pRasterWsFac = new RasterWorkspaceFactoryClass();
            IWorkspace        pWs          = pRasterWsFac.OpenFromFile(@"D://RDB", 0);
            IRasterWorkspace2 pRasterWs;

            pRasterWs = pWs as IRasterWorkspace2;
            IPoint origin = new PointClass();

            origin.PutCoords(pRasterProps.Extent.XMin, pRasterProps.Extent.YMin);
            //RasterWorkspace rasterWorkspace = (RasterWorkspace)workspace;
            ISpatialReference sr                 = new UnknownCoordinateSystemClass();
            IRasterDataset2   resultDataset      = pRasterWs.CreateRasterDataset("raster" + "_" + cmb_FliterMethod.SelectedItem.ToString() + ".tif", "TIFF", origin, Width, Height, cellsizex, cellsizey, 1, rstPixelType.PT_DOUBLE, sr) as IRasterDataset2;
            IRaster           resultRaster       = resultDataset.CreateFullRaster();
            IRasterCursor     resultRasterCursor = ((IRaster2)resultRaster).CreateCursorEx(null);

            IRasterDataset2 rasterDataset = raster2.RasterDataset as IRasterDataset2;
            IRaster2        raster        = rasterDataset.CreateFullRaster() as IRaster2;
            IRasterCursor   rasterCursor  = raster.CreateCursorEx(null);

            IPixelBlock3 resultPixelBlock = null;
            IPixelBlock3 tempPixelBlock   = null;
            IRasterEdit  resultRasterEdit = resultRaster as IRasterEdit;

            long blockWidth  = 0;
            long blockHeight = 0;

            // System.Array pixels;
            double[,] kernal = new double[3, 3] {
                { 0, 0, 0 },
                { 0, 1, 0 },
                { 0, 0, 0 }
            };
            switch (cmb_FliterMethod.SelectedItem.ToString())
            {
            case "LineDetectionHorizontal":
                kernal = new double[3, 3] {
                    { -1, -1, -1 },
                    { 2, 2, 2 },
                    { -1, -1, -1 }
                };
                break;

            case "LineDetectionVertical":
                kernal = new double[3, 3] {
                    { -1, 2, -1 },
                    { -1, 2, -1 },
                    { -1, 2, -1 }
                };
                break;

            case "Laplacian3x3":
                kernal = new double[3, 3] {
                    { 0, -1, 0 },
                    { -1, 4, -1 },
                    { 0, -1, 0 }
                };
                break;

            case "Smoothing3x3":
                kernal = new double[3, 3] {
                    { 1, 2, 1 },
                    { 2, 4, 2 },
                    { 1, 2, 1 }
                };
                break;

            case "Sharpening3x3":
                kernal = new double[3, 3] {
                    { -1, -1, -1 },
                    { -1, 9, -1 },
                    { -1, -1, -1 }
                };
                break;
            }
            do
            {
                resultPixelBlock = resultRasterCursor.PixelBlock as IPixelBlock3;
                tempPixelBlock   = rasterCursor.PixelBlock as IPixelBlock3;

                System.Array pixels = (System.Array)tempPixelBlock.get_PixelData(0);
                //MessageBox.Show(pixels3.GetValue(0, 0).GetType().ToString());
                blockHeight = resultPixelBlock.Height;
                blockWidth  = resultPixelBlock.Width;
                System.Array resultPixels = (System.Array)resultPixelBlock.get_PixelData(0);
                //MessageBox.Show(resultPixels.GetValue(0, 0).GetType().ToString());
                for (int i = 0; i < blockHeight; i++)
                {
                    for (int j = 0; j < blockWidth; j++)
                    {
                        double sum = 0;
                        for (int ki = -1; ki <= 1; ki++)
                        {
                            for (int kj = -1; kj <= 1; kj++)
                            {
                                long   idxi = (i + ki) < 0 ? 0 : i + ki >= blockHeight ? blockHeight - 1 : (i + ki);
                                long   idxj = (j + kj) < 0 ? 0 : j + kj >= blockWidth ? blockWidth - 1 : (j + kj);
                                double raw  = double.Parse(pixels.GetValue(idxj, idxi).ToString());
                                sum += raw * kernal[ki + 1, kj + 1];
                            }
                        }
                        resultPixels.SetValue(sum, j, i);
                    }
                }
                resultPixelBlock.set_PixelData(0, (System.Array)resultPixels);
                resultRasterEdit.Write(resultRasterCursor.TopLeft, (IPixelBlock)resultPixelBlock);
                resultRasterEdit.Refresh();
            } while (resultRasterCursor.Next() == true && rasterCursor.Next() == true);
            IRasterDataset pRasterDs = pRasterWs.OpenRasterDataset("raster" + "_" + cmb_FliterMethod.SelectedItem.ToString() + ".tif");
            IRaster        praster   = pRasterDs.CreateDefaultRaster();

            IRasterLayer resLayer = new RasterLayerClass();

            resLayer.CreateFromRaster(praster);
            m_raster = resLayer.Raster;
        }
        public void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm = txtOutNm.Text;
            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();
            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);

            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;
            rp.addMessage("Building " + mStr + " Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                if (this.Text == "Create Composite Raster")
                {
                    outraster = rsUtil.createRaster(rsUtil.compositeBandFunction(rsBc));
                }
                else
                {

                    outraster = rsUtil.createRaster(rsUtil.calcCombineRasterFunction(rsBc));
                }
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts = dt2.Subtract(dt);
                string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished " + mStr + " Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 51
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm    = cmbRaster.Text;
            string inFocalStat = cmbFocalStat.Text;
            string windowType  = cmbWindowType.Text;
            string outNmRst    = txtOutName.Text;
            int    clms        = System.Convert.ToInt32(nudColumns.Value);
            int    rws         = System.Convert.ToInt32(nudRows.Value);

            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (inFocalStat == "" || inFocalStat == null)
            {
                MessageBox.Show("You must specify an Focal Statistic", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (windowType == "" || windowType == null)
            {
                MessageBox.Show("You must select a widow type from dropdown menu", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNmRst == "" || outNmRst == null)
            {
                MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            IRaster rs1   = rstDic[inRst1Nm];
            IRaster outRs = null;

            rasterUtil.windowType wdType = (rasterUtil.windowType)Enum.Parse(typeof(rasterUtil.windowType), windowType);
            rasterUtil.focalType  fcType = (rasterUtil.focalType)Enum.Parse(typeof(rasterUtil.focalType), inFocalStat);
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Creating Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                if (wdType == rasterUtil.windowType.CIRCLE)
                {
                    outRs = rsUtil.returnRaster(rsUtil.calcFocalStatisticsFunction(rs1, clms, fcType));
                }
                else
                {
                    outRs = rsUtil.returnRaster(rsUtil.calcFocalStatisticsFunction(rs1, clms, rws, fcType));
                }
                outraster     = outRs;
                outrastername = outNmRst;
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rsLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name    = OutRasterName;
                    rsLyr.Visible = false;
                    mp.AddLayer(rsLyr);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Focal Analysis" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private void btnClip_Click(object sender, EventArgs e)
 {
     string rstNm = cmbInRaster1.Text;
     string outNm = txtOutName.Text;
     string pixelNm = cmbPixel.Text;
     if (pixelNm == "" || pixelNm == null || rstNm == "" || rstNm == null)
     {
         MessageBox.Show("You must have a raster layer selected and a pixel type selected", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if(outNm==""||outNm==null)
     {
         MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     this.Visible = false;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Transforming Raster. This may take a while...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     rp.Show();
     try
     {
         IRaster rst = rstDic[rstNm];
         rasterUtil.transType pType = (rasterUtil.transType)Enum.Parse(typeof(rasterUtil.transType),pixelNm);
         outraster = rsUtil.returnRaster(rsUtil.calcMathRasterFunction(rst,pType));
         if (mp != null&&addToMap)
         {
             rp.addMessage("Calculating Statistics...");
             rp.Show();
             rp.Refresh();
             IRasterLayer rstLyr = new RasterLayerClass();
             //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
             rstLyr.CreateFromRaster(outraster);
             rstLyr.Name = outNm;
             rstLyr.Visible = false;
             mp.AddLayer(rstLyr);
         }
         outrastername = outNm;
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         rp.addMessage(ex.ToString());
     }
     finally
     {
         DateTime dt2 = DateTime.Now;
         TimeSpan ts = dt2.Subtract(dt);
         string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
         rp.stepPGBar(100);
         rp.addMessage("Finished Transforming Raster" + t);
         rp.enableClose();
         this.Close();
     }
 }
Esempio n. 53
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm = cmbRaster.Text;

            double newCellSize = 0;
            string outNmRst    = txtOutName.Text;

            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNmRst == "" || outNmRst == null)
            {
                MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (rsUtil.isNumeric(txtCellSize.Text))
            {
                newCellSize = System.Convert.ToDouble(txtCellSize.Text);
            }
            else
            {
                MessageBox.Show("You must specify a numeric cell size", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            IRaster rs1   = rstDic[inRst1Nm];
            IRaster outRs = null;

            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Creating Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                outRs         = rsUtil.createRaster(rsUtil.reSampleRasterFunction(rs1, newCellSize));
                outraster     = outRs;
                outrastername = outNmRst;
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rsLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name    = OutRasterName;
                    rsLyr.Visible = false;
                    mp.AddLayer(rsLyr);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Resample Analysis" + t);
                rp.enableClose();
                this.Close();
            }
        }
Esempio n. 54
0
 private IRasterLayer IntersectRaster(IRasterLayer rsterLayer, IPolygon polygon2)
 {
     //  获得与组合成的面相叠加的栅格
     if (radioBtnKJ.Checked && polygon2 != null)
     {
         IExtractionOp op = new RasterExtractionOpClass();
         IGeoDataset dataset = op.Polygon((IGeoDataset)rsterLayer.Raster, polygon2, true);
         IRasterLayer layer = new RasterLayerClass();
         layer.CreateFromRaster((IRaster)dataset);
         rsterLayer = layer;
     }
     return rsterLayer;
 }
Esempio n. 55
0
        private void btnClip_Click(object sender, EventArgs e)
        {
            string rstNm = cmbInRaster1.Text;
            string outNm = txtOutName.Text;
            int    rws   = System.Convert.ToInt32(nudRows.Value);
            int    clms  = System.Convert.ToInt32(nudColumns.Value);

            if (rstNm == "" || rstNm == null)
            {
                MessageBox.Show("You must have a raster layer selected and a pixel type selected", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNm == "" || outNm == null)
            {
                MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <double> kernalLst = new List <double>();

            for (int i = 0; i < dgvKernal.ColumnCount; i++)
            {
                for (int j = 0; j < dgvKernal.RowCount; j++)
                {
                    object vlo = dgvKernal[i, j].Value;
                    double vl  = 0;
                    if (DBNull.Value.Equals(vlo))
                    {
                        vl = 0;
                    }
                    else
                    {
                        vl = System.Convert.ToDouble(dgvKernal[i, j].Value);
                    }
                    kernalLst.Add(vl);
                    //Console.WriteLine(vl.ToString());
                }
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Creating Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                IRaster rst = rstDic[rstNm];
                outraster = rsUtil.returnRaster(rsUtil.convolutionRasterFunction(rst, clms, rws, kernalLst.ToArray()));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = outNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = outNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Convolution Analysis" + t);
                rp.enableClose();
                this.Close();
            }
        }