Example #1
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);
        }
Example #2
0
 public IFeatureLayer CreateRasterContour(IRaster raster)
 {
     try
     {
         ISurfaceOp  pSurface    = new RasterSurfaceOpClass();
         object      BaseHeight  = Type.Missing;
         IGeoDataset pGeoDataset = raster as IGeoDataset;
         double      interval    = Convert.ToDouble(txtContour.Text);
         if (interval <= 0)
         {
             MessageBox.Show("请指定大于0的正数!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return(null);
         }
         IGeoDataset   pContour       = pSurface.Contour(pGeoDataset, interval, ref BaseHeight);
         IFeatureLayer pFContourLayer = new FeatureLayerClass();
         pFContourLayer.FeatureClass = pContour as IFeatureClass;
         // IFeatureDataConverter pFeatureDataConvert = new FeatureDataConverter();
         OperateConvertToShape(m_ResultPath, pFContourLayer.FeatureClass);
         return(pFContourLayer);
     }
     catch (SystemException e)
     {
         MessageBox.Show(e.Message);
         return(null);
     }
 }
Example #3
0
 public IRaster CreateRasterHillShade(IRaster raster)
 {
     try
     {
         RasterSurfaceOpClass class2     = new RasterSurfaceOpClass();
         IGeoDataset          geoDataset = raster as IGeoDataset;
         double zFactor = Convert.ToDouble(textBoxX3.Text);
         if (zFactor <= 0)
         {
             MessageBox.Show("请指定大于0的正数!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return(null);
         }
         object o              = zFactor;
         double azimuth        = slider2.Value;
         double altitude       = slider1.Value;
         bool   inModelShadows = false;
         if (cmbRenderType.SelectedIndex == 1)
         {
             inModelShadows = true;
         }
         IGeoDataset pGeoDataset = class2.HillShade(geoDataset, azimuth, altitude, inModelShadows, ref o);
         IRaster     pRaster     = (IRaster)pGeoDataset;
         ISaveAs2    pSaveAs     = pRaster as ISaveAs2;
         IDataset    pDataset    = pSaveAs.SaveAs(m_ResultPath + ".tif", null, "TIFF");
         System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataset);
         MessageBox.Show("山体阴影计算完毕!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(pRaster);
     }
     catch (SystemException e)
     {
         MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return(null);
     }
 }
Example #4
0
        /// <summary>
        /// 计算DEM坡度
        /// </summary>
        /// <param name="rasterLayer">输入DEM图层</param>
        /// <param name="outputFullPath">输出坡度图路径,类型为IMAGE,文件名为img</param>
        public void CreateRasterSlope(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();
            object o = 1;
            IGeoDataset geoDataset = raster as IGeoDataset;
            esriGeoAnalysisSlopeEnum geoType = esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees;
            IGeoDataset outGeodataset = rasterOpCls.Slope(geoDataset, geoType, ref o);
            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);
        }
Example #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            IGeoDataset inGeoDataSet;
            IGeoDataset outGeoDataSet;
            ISurfaceOp  SurfaceOp = new RasterSurfaceOpClass();

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

            inGeoDataSet = raster as IGeoDataset;

            outGeoDataSet = SurfaceOp.Aspect(inGeoDataSet);

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

            IRasterLayer pRlayer = new RasterLayer();

            pRlayer.CreateFromRaster((IRaster)outGeoDataSet);
            pRlayer.Name = System.IO.Path.GetFileName(textBox1.Text);
            mainForm.axMapControl1.AddLayer(pRlayer, 0);
        }
Example #6
0
        public IRaster CreateRasterSlope(IRaster raster)
        {
            try
            {
                RasterSurfaceOpClass class2     = new RasterSurfaceOpClass();
                IGeoDataset          geoDataset = raster as IGeoDataset;

                double zFactor = Convert.ToDouble(textBoxX3.Text);
                if (zFactor <= 0)
                {
                    MessageBox.Show("请指定大于0的正数!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(null);
                }

                //float zFactor = 1;
                object o = zFactor;
                esriGeoAnalysisSlopeEnum geoType = esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees;
                IGeoDataset pGeoDataset          = class2.Slope(geoDataset, geoType, ref o);
                IRaster     pRaster  = (IRaster)pGeoDataset;
                ISaveAs2    pSaveAs  = pRaster as ISaveAs2;
                IDataset    pDataset = pSaveAs.SaveAs(m_ResultPath + ".tif", null, "TIFF");
                //System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataset);
                MessageBox.Show("坡度计算完毕!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(pRaster);
            }
            catch (SystemException e)
            {
                MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(null);
            }
        }
Example #7
0
        public static void Mlayer_IDW_Click()
        {
            // 用反距离IDW插值生成的栅格图像。如下:
            IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass();

            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
            string            pPath             = Application.StartupPath + @"\MakeContours\Cont.shp";
            string            pFolder           = System.IO.Path.GetDirectoryName(pPath);
            string            pFileName         = System.IO.Path.GetFileName(pPath);

            IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFolder, 0);

            IFeatureWorkspace       pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureClass           oFeatureClass     = pFeatureWorkspace.OpenFeatureClass(pFileName);
            IFeatureClassDescriptor pFCDescriptor     = new FeatureClassDescriptorClass();

            pFCDescriptor.Create(oFeatureClass, null, "shape.z");
            IRasterRadius pRadius = new RasterRadiusClass();

            object objectMaxDistance = null;
            object objectbarrier     = null;
            object missing           = Type.Missing;

            pRadius.SetVariable(12, ref objectMaxDistance);

            object    dCellSize      = 1;
            object    snapRasterData = Type.Missing;
            IEnvelope pExtent;

            pExtent = new EnvelopeClass();
            Double xmin = 27202;
            Double xmax = 31550;

            Double ymin = 19104;
            Double ymax = 22947;

            pExtent.PutCoords(xmin, ymin, xmax, ymax);
            object extentProvider           = pExtent;
            IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;

            pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCellSize);
            pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
            IGeoDataset poutGeoDataset = pInterpolationOp.IDW((IGeoDataset)pFCDescriptor, 2, pRadius, ref objectbarrier);
            ISurfaceOp  surOp          = new RasterSurfaceOpClass();


            IRaster pOutRaster = poutGeoDataset as IRaster;

            IRasterLayer pOutRasLayer = new RasterLayer();

            pOutRasLayer.CreateFromRaster(pOutRaster);

            IMap pMap = Common.DataEditCommon.g_pMap;

            pMap.AddLayer(pOutRasLayer);
            Common.DataEditCommon.g_axTocControl.Refresh();
            Common.DataEditCommon.g_pAxMapControl.ActiveView.Refresh();
        }
Example #8
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int    startX, endX;
            string shpDir;

            try
            {
                if (bDataPath == true)
                {
                    fileName = txtOutputData.Text;
                    shpDir   = fileName.Substring(0, fileName.LastIndexOf("\\"));
                    startX   = fileName.LastIndexOf("\\");
                    endX     = fileName.Length;
                    shpFile  = fileName.Substring(startX + 1, endX - startX - 1);
                }
                else
                {
                    shpDir  = txtOutputData.Text;
                    shpFile = "х╚ох¤▀";
                }
                if (m_pRasterLyr != null)
                {
                    double        dInterval        = Convert.ToDouble(txtConInterval.Text);
                    double        dBaseLine        = Convert.ToDouble(txtBaseLine.Text);
                    object        objBaseLine      = dBaseLine;
                    ISurfaceOp    pRasterSurfaceOp = new RasterSurfaceOpClass();
                    IRaster       pInRaster        = m_pRasterLyr.Raster;
                    IFeatureClass pOutFClass       = pRasterSurfaceOp.Contour(pInRaster as IGeoDataset, dInterval, ref objBaseLine) as IFeatureClass;
                    //2. QI to IDataset
                    IDataset pFDS = pOutFClass as IDataset;
                    //3. Get a shapefile workspace
                    IWorkspaceFactory pSWF = new  ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace pFWS = pSWF.OpenFromFile(shpDir, 0) as IFeatureWorkspace;
                    //4. Copy contour output to a new shapefile
                    IWorkspace pWS = pFWS as IWorkspace;
                    if (pWS.Exists() == true)
                    {
                        Utility.DelFeatureFile(shpDir, shpFile + ".shp");
                    }
                    pFDS.Copy(shpFile, pFWS as IWorkspace);
                    IFeatureLayer pFeatLyr = new FeatureLayerClass();
                    pFeatLyr.FeatureClass = pOutFClass;
                    pFeatLyr.Name         = pOutFClass.AliasName;
                    pFeatLyr.Visible      = true;
                    pMainFrm.getMapControl().AddLayer(pFeatLyr, 0);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #9
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);

            }
        }
Example #10
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);
            }
        }
Example #11
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int startX, endX;
            string shpDir;
            try
            {
                if (bDataPath == true)
                {
                    fileName=txtOutputData.Text;
                    shpDir =fileName.Substring(0, fileName.LastIndexOf("\\"));
                    startX=fileName.LastIndexOf("\\");
                    endX=fileName.Length;
                    shpFile=fileName.Substring(startX+1,endX-startX-1);
                }
                else
                {
                    shpDir=txtOutputData.Text;
                    shpFile="��ֵ��";
                }
                if (m_pRasterLyr != null)
                {
                    double dInterval=Convert.ToDouble(txtConInterval.Text);
                    double dBaseLine=Convert.ToDouble(txtBaseLine.Text);
                    object objBaseLine=dBaseLine;
                    ISurfaceOp pRasterSurfaceOp = new RasterSurfaceOpClass();
                    IRaster pInRaster = m_pRasterLyr.Raster;
                    IFeatureClass  pOutFClass= pRasterSurfaceOp.Contour(pInRaster as IGeoDataset , dInterval, ref objBaseLine) as IFeatureClass ;
                    //2. QI to IDataset
                    IDataset pFDS=pOutFClass as IDataset ;
                    //3. Get a shapefile workspace
                    IWorkspaceFactory pSWF=new  ShapefileWorkspaceFactoryClass();
                    IFeatureWorkspace pFWS=pSWF.OpenFromFile(shpDir,0) as IFeatureWorkspace ;
                    //4. Copy contour output to a new shapefile
                    IWorkspace pWS = pFWS as IWorkspace;
                    if (pWS.Exists() == true)
                        Utility.DelFeatureFile(shpDir, shpFile + ".shp");
                    pFDS.Copy(shpFile,pFWS as IWorkspace );
                    IFeatureLayer pFeatLyr = new FeatureLayerClass();
                    pFeatLyr.FeatureClass = pOutFClass;
                    pFeatLyr.Name = pOutFClass.AliasName;
                    pFeatLyr.Visible = true;
                    pMainFrm.getMapControl().AddLayer(pFeatLyr, 0);
                }
            }

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

            }
        }
        private void SurfaceProcess(IGeoDataset beforeGeo, IGeoDataset afterGeo)
        {
            try
            {
                IRasterSurface rasterSurface = new RasterSurfaceClass();
                rasterSurface.PutRaster((IRaster)beforeGeo, 0);
                ISurface pSurface = rasterSurface as ISurface;

                surfaceArea = pSurface.GetSurfaceArea(h, esriPlaneReferenceType.esriPlaneReferenceAbove).ToString(".###") + "㎡";
                projectArea = pSurface.GetProjectedArea(h, esriPlaneReferenceType.esriPlaneReferenceAbove).ToString(".###") + "㎡";

                ISurfaceOp            SurfaceOp     = new RasterSurfaceOpClass();
                IGeoDataset           outGeoDataset = SurfaceOp.CutFill(beforeGeo, afterGeo, Type.Missing);
                IRasterBandCollection pRsBandCol    = outGeoDataset as IRasterBandCollection;

                double area       = 0.0; //涉及面积
                double volume     = 0.0; //挖方方量
                double volume1    = 0.0; //填方方量
                double sumVolume  = 0;   //挖方总量
                double sumVolume1 = 0;   //填方总量
                for (int i = 0; i < pRsBandCol.Count; i++)
                {
                    IRasterBand pBand   = pRsBandCol.Item(0);
                    ITable      pRTable = pBand.AttributeTable;
                    ICursor     pCursor = pRTable.Search(null, true);

                    IRow pRrow = pCursor.NextRow();
                    while (pRrow != null)
                    {
                        area  += Convert.ToDouble(pRrow.get_Value(pRrow.Fields.FindField("AREA")).ToString());
                        volume = Convert.ToDouble(pRrow.get_Value(pRrow.Fields.FindField("VOLUME")).ToString());
                        if (volume > 0)
                        {
                            sumVolume += volume;
                        }
                        else
                        {
                            sumVolume1 += volume;
                        }
                        pRrow = pCursor.NextRow();
                    }
                }
                dig  = Math.Round(sumVolume, 3).ToString() + "m³";
                fill = Math.Round(Math.Abs(sumVolume1), 3).ToString() + "m³";
            }
            catch (System.Exception ex)
            {
                WaitForm.Stop();
            }
        }
Example #13
0
        private void Btn_Slope_Click(object sender, EventArgs e)
        {
            IRasterLayer pFromRasterLayer = m_selectedLayer as IRasterLayer;

            if (pFromRasterLayer == null)
            {
                MessageBox.Show("非栅格图层");
                return;
            }

            IRaster pFromRaster = pFromRasterLayer.Raster;
            IRasterBandCollection pFromRasterBandCollection = pFromRaster as IRasterBandCollection;
            IRasterBand           pFromRasterBand           = pFromRasterBandCollection.Item(0);
            IRasterDataset        pFromRasterDataset        = pFromRasterBand as IRasterDataset;

            IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace  pRasterWorkspace  = pWorkspaceFactory.OpenFromFile(@"DB", 0) as IRasterWorkspace;

            ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass();
            IRasterAnalysisEnvironment pRasterAnalysisEnvironment;

            pRasterAnalysisEnvironment = pSurfaceOp as IRasterAnalysisEnvironment;
            pRasterAnalysisEnvironment.OutWorkspace = pWorkspaceFactory as IWorkspace;
            object      zFactor = new object();
            IGeoDataset pGeoDataset, pRasterGetDataset;

            pRasterGetDataset = pFromRasterDataset as IGeoDataset;
            pGeoDataset       = pSurfaceOp.Slope(pRasterGetDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopePercentrise, ref zFactor);
            IRasterBandCollection pOutRasterBandCollection = pGeoDataset as IRasterBandCollection;
            string strOutRasterName = pFromRasterLayer.Name.Split('.')[0] + "_slope.tif";

            pOutRasterBandCollection.SaveAs(strOutRasterName, pRasterWorkspace as IWorkspace, "TIFF");

            IRasterDataset pNewRasterDataset = pRasterWorkspace.OpenRasterDataset(strOutRasterName);

            IRasterLayer pNewRasterLayer = new RasterLayerClass();

            pNewRasterLayer.CreateFromDataset(pNewRasterDataset);
            ILayer pNewLayer = pNewRasterLayer as ILayer;

            Ctrl_Map.AddLayer(pNewLayer);
        }
Example #14
0
 public IRaster CreateRasterAspect(IRaster raster)
 {
     try
     {
         RasterSurfaceOpClass class2      = new RasterSurfaceOpClass();
         IGeoDataset          geoDataset  = raster as IGeoDataset;
         IGeoDataset          pGeoDataset = class2.Aspect(geoDataset);
         IRaster  pRaster  = (IRaster)pGeoDataset;
         ISaveAs2 pSaveAs  = pRaster as ISaveAs2;
         IDataset pDataset = pSaveAs.SaveAs(m_ResultPath + ".tif", null, "TIFF");
         System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataset);
         MessageBox.Show("坡向计算完毕!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(pRaster);
     }
     catch (SystemException e)
     {
         MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return(null);
     }
 }
Example #15
0
 //
 //����դ���¶ȷ�������
 //
 public static ISurfaceOp SetRasterSurfaceAnalysisEnv(string rasterpath, double cellsize)
 {
     object Missing = Type.Missing;
     IWorkspace pWorkspace;
     pWorkspace = UtilityFunction.setRasterWorkspace(rasterpath);
     ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass();
     IRasterAnalysisEnvironment pEnv = pSurfaceOp as IRasterAnalysisEnvironment;
     pEnv.OutWorkspace = pWorkspace;
     //װ�����
     object objCellSize = cellsize;
     pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objCellSize);
     pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvMaxOf, ref Missing, ref Missing);
     return pSurfaceOp;
 }
Example #16
0
        public void CreateRasterFromPoints(IMap pMap, IFeatureLayer pp,String Path, String Name, String Field)
        {
            //1.��Shape�ļ���ȡ��FeatureClass
            //2.����FeatureClass����IFeatureClassDescriptor
            //3.����IRasterRaduis ����
            //����Cell
            //4.��ֵ�����ɱ���
            object obj = null;

            IWorkspaceFactory pShapSpace;

            pShapSpace = new ShapefileWorkspaceFactory();

            IWorkspace pW;

            pW = pShapSpace.OpenFromFile(Path, 0);

            IFeatureWorkspace pFeatureWork;

            pFeatureWork = pW as IFeatureWorkspace;

            IFeatureClass pFeatureClass = pFeatureWork.OpenFeatureClass("Name");

            IGeoDataset Geo = pFeatureClass as IGeoDataset;

            object extend = Geo.Extent;

            object o = null;

            IFeatureClassDescriptor pFeatureClassDes = new FeatureClassDescriptorClass();

            pFeatureClassDes.Create(pFeatureClass, null, Field);

            IRasterRadius pRasterrad = new RasterRadiusClass();

            pRasterrad.SetVariable(10, ref obj);

            object dCell = 0.5;//���Ը��ݲ�ͬ�ĵ�ͼ���������

            IInterpolationOp Pinterpla = new RasterInterpolationOpClass();

            IRasterAnalysisEnvironment pRasterAnaEn = Pinterpla as IRasterAnalysisEnvironment;

            pRasterAnaEn.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCell);

            pRasterAnaEn.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extend, ref o);

            IGeoDataset pGRaster;

            object hh = 3;

            pGRaster = Pinterpla.IDW((IGeoDataset)pFeatureClassDes , 2, pRasterrad, ref hh);

            ISurfaceOp pSurF;

            pSurF = new RasterSurfaceOpClass();

            IGeoDataset pCour;

            object  o1 = 0;

            pCour = pSurF.Contour(pGRaster, 5, ref o1);

            IFeatureLayer pLa;

            pLa = new FeatureLayerClass();

            IFeatureClass pClass = pCour as IFeatureClass;

            pLa.FeatureClass = pClass;

            pLa.Name = pClass.AliasName;

            pMap.AddLayer(pLa as ILayer);
        }
Example #17
0
        public void CreateRasterFromPoints(IMap pMap, IFeatureLayer pp, String Path, String Name, String Field)
        {
            //1.将Shape文件读取成FeatureClass
            //2.根据FeatureClass生成IFeatureClassDescriptor
            //3.创建IRasterRaduis 对象
            //设置Cell
            //4.插值并生成表面
            object obj = null;

            IWorkspaceFactory pShapSpace;

            pShapSpace = new ShapefileWorkspaceFactory();

            IWorkspace pW;

            pW = pShapSpace.OpenFromFile(Path, 0);

            IFeatureWorkspace pFeatureWork;

            pFeatureWork = pW as IFeatureWorkspace;


            IFeatureClass pFeatureClass = pFeatureWork.OpenFeatureClass("Name");


            IGeoDataset Geo = pFeatureClass as IGeoDataset;

            object extend = Geo.Extent;

            object o = null;

            IFeatureClassDescriptor pFeatureClassDes = new FeatureClassDescriptorClass();

            pFeatureClassDes.Create(pFeatureClass, null, Field);

            IRasterRadius pRasterrad = new RasterRadiusClass();

            pRasterrad.SetVariable(10, ref obj);

            object dCell = 0.5;//可以根据不同的点图层进行设置

            IInterpolationOp Pinterpla = new RasterInterpolationOpClass();

            IRasterAnalysisEnvironment pRasterAnaEn = Pinterpla as IRasterAnalysisEnvironment;

            pRasterAnaEn.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCell);

            pRasterAnaEn.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extend, ref o);

            IGeoDataset pGRaster;

            object hh = 3;

            pGRaster = Pinterpla.IDW((IGeoDataset)pFeatureClassDes, 2, pRasterrad, ref hh);


            ISurfaceOp pSurF;

            pSurF = new RasterSurfaceOpClass();

            IGeoDataset pCour;

            object o1 = 0;

            pCour = pSurF.Contour(pGRaster, 5, ref o1);

            IFeatureLayer pLa;

            pLa = new FeatureLayerClass();

            IFeatureClass pClass = pCour as IFeatureClass;

            pLa.FeatureClass = pClass;

            pLa.Name = pClass.AliasName;

            pMap.AddLayer(pLa as ILayer);
        }
Example #18
0
        private void button1_Click(object sender, EventArgs e)
        {
            //得到dem、分成多个区域



            //获取等高线
            ILayer tLayer = this.axMapControl1.get_Layer(0);

            IRasterLayer tRasterLayer = (IRasterLayer)tLayer;

            IFeatureClass tFeatureClass = null;

            IGeoDataset tGeodataset = null;

            //使用接口参数(Raster,等高线间距,基值)
            ISurfaceOp tSurfaceop = new RasterSurfaceOpClass();

            object obj = 0;

            tGeodataset = tSurfaceop.Contour((IGeoDataset)tRasterLayer.Raster, 5, ref obj);  //等高线间距为10米

            IFeatureLayer tFeatureLayer = new FeatureLayerClass();

            //判断是否生成等高线
            if (tGeodataset != null)
            {
                tFeatureClass = (IFeatureClass)tGeodataset;

                if (tFeatureClass != null)
                {
                    tFeatureLayer.FeatureClass = tFeatureClass;

                    //this.axMapControl1.AddLayer((ILayer)tFeatureLayer);

                    //this.axMapControl1.Refresh();
                }
            }

            tFeatureLayer = deleteLine(tFeatureLayer);

            this.axMapControl1.AddLayer((ILayer)tFeatureLayer);

            this.axMapControl1.Refresh();

            /*选取特定高程的等高线*/

            //得到Feature的指针
            IQueryFilter queryFilter = new SpatialFilterClass();

            int maxContour = getMax(tFeatureLayer);

            int queryContour = maxContour - 10; //选择具体某条等高线

            queryFilter.WhereClause = "Contour = " + queryContour;

            IFeatureCursor featureCursor = tFeatureClass.Search(queryFilter, false);
            IFeature       feature       = featureCursor.NextFeature();

            //获取表的长度
            //int attributeTableLength = tFeatureClass.Fields.FindField("id");
            //string lenStr = attributeTableLength.ToString();
            //MessageBox.Show(lenStr);
            ////
            //IGeometry geometry;
            //IPolyline polyline;
            /* 筛选符合要求的等高线*/
            //while (feature!=null)
            //{
            //    IFields ptFields  =  feature.Fields;
            //    geometry =  feature.Shape;
            //    polyline =  (IPolyline)geometry;
            //    IField field = ptFields.get_Field(0);
            //    feature.get_Value();
            //    feature = featureCursor.NextFeature(); //指针移动到下一行。
            //}



            //释放游标
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);


            //获取选中的等高线
            IGeometry geometry = feature.Shape;
            IPolyline polyline = (IPolyline)geometry;

            //定义列表存储构成等高线的点的坐标、高程
            List <IPoint> contourPoint = new List <IPoint>();

            contourPoint = getPointByContourLine(polyline);

            /*将线转成面,并获取面的面积*/

            ////初始化Geoprocessor工具
            //Geoprocessor processor = new Geoprocessor();

            //FeatureToPolygon fPolygon = new FeatureToPolygon();

            //fPolygon.in_features = feature;

            //fPolygon.out_feature_class = "D:\\testData\\conPolygon.shp";

            //processor.Execute(fPolygon,null);


            //构造面,并将构成等高线的点赋予面

            //IPoint pPoint = new PointClass();

            //IPointCollection pointCollection = new PolygonClass();

            //object missing = Type.Missing;

            //double x, y;

            //for (int i = 0; i < contourPoint.Count; i++)
            //{

            //    x = contourPoint[i].X;

            //    y = contourPoint[i].Y;

            //    pPoint = new PointClass();

            //    pPoint.PutCoords(x, y);

            //    pointCollection.AddPoint(pPoint, ref missing, ref missing);

            //}

            //IPolygon pPolygon = new PolygonClass();

            ////生成面
            //pPolygon = (IPolygon)pointCollection;



            //获取指定数据库的要素类

            string path = "D:\\testPolygon";

            IFeatureClass featureclass = getFeatureClass(path);

            IFeatureLayer polyFeatureLayer = new FeatureLayerClass();

            IFeatureClass polyFeatclas = IfeatureBuffer(contourPoint, featureclass, maxContour.ToString());


            /*给由等高线生成的面添加新字段Contour(表示等高线高程值是多少)*/
            //定义新字段
            IField pField = new FieldClass();

            //字段编辑
            IFieldEdit pFieldEdit = pField as IFieldEdit;

            //新建字段名
            pFieldEdit.Name_2 = "Contour";

            //获取属性表
            IClass pTable = polyFeatclas as IClass;

            pTable.AddField(pFieldEdit);

            IFeature pFea = polyFeatclas.GetFeature(0);

            pFea.set_Value(pFea.Fields.FindField("Contour"), maxContour.ToString());

            //保存
            pFea.Store();

            polyFeatureLayer.FeatureClass = polyFeatclas;

            //将生成的面加入到当前地图控件中
            this.axMapControl1.AddLayer(polyFeatureLayer);

            this.axMapControl1.Refresh();

            IFeature polyFeature, lineFeature;

            polyFeature = polyFeatclas.GetFeature(0);

            lineFeature = feature;

            double judResult = calculate(polyFeature, lineFeature);

            double radius = fitting(contourPoint);

            RadiTBox.Text = radius.ToString();

            MessageBox.Show(judResult.ToString(), "面积/周长");
        }
        public static void Mlayer_IDW_Click()
        {
            // 用反距离IDW插值生成的栅格图像。如下:
               IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass();

               IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
               string pPath = Application.StartupPath + @"\MakeContours\Cont.shp";
               string pFolder = System.IO.Path.GetDirectoryName(pPath);
               string pFileName = System.IO.Path.GetFileName(pPath);

               IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFolder, 0);

               IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
               IFeatureClass oFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName);
               IFeatureClassDescriptor pFCDescriptor = new FeatureClassDescriptorClass();
               pFCDescriptor.Create(oFeatureClass, null, "shape.z");
               IRasterRadius pRadius = new RasterRadiusClass();

               object objectMaxDistance = null;
               object objectbarrier = null;
               object missing = Type.Missing;
               pRadius.SetVariable(12, ref objectMaxDistance);

               object dCellSize =1;
               object snapRasterData = Type.Missing;
               IEnvelope pExtent;
               pExtent = new EnvelopeClass();
               Double xmin = 27202;
               Double xmax = 31550;

               Double ymin = 19104;
               Double ymax = 22947;
               pExtent.PutCoords(xmin, ymin, xmax, ymax);
               object extentProvider = pExtent;
               IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;
               pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref dCellSize);
               pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
               IGeoDataset poutGeoDataset = pInterpolationOp.IDW((IGeoDataset)pFCDescriptor, 2, pRadius, ref objectbarrier);
               ISurfaceOp surOp = new RasterSurfaceOpClass();

               IRaster pOutRaster = poutGeoDataset as IRaster;

               IRasterLayer pOutRasLayer = new RasterLayer();
               pOutRasLayer.CreateFromRaster(pOutRaster);

               IMap pMap = Common.DataEditCommon.g_pMap;
               pMap.AddLayer(pOutRasLayer);
               Common.DataEditCommon.g_axTocControl.Refresh();
               Common.DataEditCommon.g_pAxMapControl.ActiveView.Refresh();
        }
Example #20
0
        private IRasterLayer calWSCons(string  _outPath)
        {
            //��դ�� pMapAlgebraOp
            try
            {
                if (pMapAlgebraOp==null)
                {
                    pMapAlgebraOp = new RasterMapAlgebraOpClass();
                }
                string strExp = "";
                string sRainPath = "";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                IGeoDataset pGeoDsSr = pMapAlgebraOp.Execute(strExp);
                IRaster pOutRaster = pGeoDsSr as IRaster;
                IRasterLayer pOutRasterLayer = new RasterLayerClass();
                pOutRasterLayer.CreateFromRaster(pOutRaster);
                //��������
                //string strOutDir = _outPath.Substring(0, _outPath.LastIndexOf("\\"));
                int startX = _outPath.LastIndexOf("\\");
                int endX = _outPath.Length;
                string sRLyrName = _outPath.Substring(startX + 1, endX - startX - 1);
                pOutRasterLayer.Name = sRLyrName;
                pMapAlgebraOp = null;
                return pOutRasterLayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return null;
            }
        }
Example #21
0
        private IRasterLayer calTerrain(string _outPath)
        {
            //绑定栅格到 pMapAlgebraOp
            try
            {
                if (pMapAlgebraOp == null)
                {
                    pMapAlgebraOp = new RasterMapAlgebraOpClass();
                }
                string strExp = "";
                //dem
                IRaster pRasterDem = (pMap.get_Layer(LayerOprate.getLayerIndexByName(pMap, this.cmbDem.Text)) as IRasterLayer).Raster;
                IGeoDataset pGeoDsDem = pRasterDem as IGeoDataset;
                // bind raster data "Dem"
                pMapAlgebraOp.BindRaster(pGeoDsDem, "Dem");

                //cal Slope with Deg
                ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass();
                object objZFactor = System.Type.Missing;
                IGeoDataset pGeoDsSlope = pSurfaceOp.Slope(pRasterDem as IGeoDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, ref objZFactor);

                // bind raster data "Slope"
                pMapAlgebraOp.BindRaster(pGeoDsSlope, "Slope");

                //cal Slo dem
                string demStart = this.txtDemStart.Text;
                string demEnd = this.txtDemEnd.Text;

                string sloStart = this.txtSloStart.Text;
                string sloEnd = this.txtSloEnd.Text;

                //strExp = "Con([Dem] < " + demStart + ",0,[Dem] > " + demEnd + ",0,1)";
                //IGeoDataset pGeoDsDemC = pMapAlgebraOp.Execute(strExp);
                //pMapAlgebraOp.BindRaster(pGeoDsDemC, "DemC");

                ////限制区为1,非限制区为0
                //strExp = "Con([Slope] < " + sloStart + ",0,[Slope] > "+sloEnd+",0,1)";
                //IGeoDataset pGeoDsSloC = pMapAlgebraOp.Execute(strExp);
                //pMapAlgebraOp.BindRaster(pGeoDsSloC, "SloC");

                //cal in together
                strExp = "Con((([Slope] > " + sloStart + " & [Slope] < " + sloEnd + ") & ([Dem] > " + demStart + " & [Dem] < " + demEnd + ")),1,0)";
                IGeoDataset pGeoDsC = pMapAlgebraOp.Execute(strExp);
                pMapAlgebraOp.BindRaster(pGeoDsC, "TerrainRedL");

                pMapAlgebraOp.UnbindRaster("Dem");
                pMapAlgebraOp.UnbindRaster("Slope");

                IRaster pOutRaster = pGeoDsC as IRaster;
                IRasterLayer pOutRasterLayer = new RasterLayerClass();
                pOutRasterLayer.CreateFromRaster(pOutRaster);
                //数据名称
                //string strOutDir = _outPath.Substring(0, _outPath.LastIndexOf("\\"));
                int startX = _outPath.LastIndexOf("\\");
                int endX = _outPath.Length;
                string sRLyrName = _outPath.Substring(startX + 1, endX - startX - 1);
                pOutRasterLayer.Name = sRLyrName;
                pMapAlgebraOp = null;
                return pOutRasterLayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return null;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //通过IDW插值生成栅格图层
            #region
            label2.Text = "正在进行IDW插值";
            IFeatureLayer pFeatureLayer_point = axMapControl1.Map.Layer[0] as IFeatureLayer;//获取点图层
            IRasterRadius pRadius             = new RasterRadiusClass();
            object        missing             = Type.Missing;
            pRadius.SetVariable(12, ref missing);
            IFeatureClassDescriptor pFCDescriptor = new FeatureClassDescriptorClass();
            pFCDescriptor.Create(pFeatureLayer_point.FeatureClass, null, "高程");

            object                     cellSizeProvider = 185.244192;
            IInterpolationOp           pInterpolationOp = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment pEnv             = pInterpolationOp as IRasterAnalysisEnvironment;
            pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            IRaster pOutRaster;

            try
            {
                pOutRaster = pInterpolationOp.IDW(pFCDescriptor as IGeoDataset, 2, pRadius, ref missing) as IRaster;
            }
            catch
            {
                pOutRaster = pInterpolationOp.IDW(pFCDescriptor as IGeoDataset, 2, pRadius, ref missing) as IRaster;
            }

            //Add output into ArcMap as a raster layer
            RasterLayer pOutRasLayer = new RasterLayerClass();
            pOutRasLayer.CreateFromRaster(pOutRaster);
            pOutRasLayer.Name = "栅格";
            axMapControl1.Map.AddLayer(pOutRasLayer);
            #endregion
            //提取等值线
            #region
            label2.Text = "正在生成等值线...";
            IGeoDataset                pGeoDataSet                = pOutRaster as IGeoDataset;
            IWorkspaceFactory          pWorkspaceFactory1         = new ShapefileWorkspaceFactory();
            string                     file_path                  = System.IO.Path.GetDirectoryName(database_path);
            IWorkspace                 pShpWorkspace              = pWorkspaceFactory1.OpenFromFile(file_path, 0);
            ISurfaceOp2                pSurfaceOp2                = new RasterSurfaceOpClass();
            IRasterAnalysisEnvironment pRasterAnalysisEnvironment = pSurfaceOp2 as IRasterAnalysisEnvironment;

            pRasterAnalysisEnvironment.Reset();
            pRasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            pRasterAnalysisEnvironment.OutWorkspace = pShpWorkspace;
            double      dInterval      = 0.8; //间距
            IGeoDataset pOutputDataSet = pSurfaceOp2.Contour(pGeoDataSet, dInterval, ref missing, ref missing);

            IFeatureClass pFeatureClass1 = pOutputDataSet as IFeatureClass;
            IFeatureLayer pFeatureLayer  = new FeatureLayerClass();
            pFeatureLayer.FeatureClass = pFeatureClass1;

            IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
            pGeoFeatureLayer.DisplayAnnotation = true;
            pGeoFeatureLayer.DisplayField      = "Contour";
            pGeoFeatureLayer.Name = "高程等值线";
            axMapControl1.Map.AddLayer(pGeoFeatureLayer);
            label2.Text = "完毕";
            #endregion
        }
        private void iDW插值ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureClass pFeatureClass = GetFeatureClass(@".\data\IDW数据", "山东20100321");

             IGeoDataset pGeoDataset = IDW(pFeatureClass, "H", 0.005, 0.05, 2);

             IRasterLayer pRasterlayer = new RasterLayerClass();

             //IRasterDataset pRs = pGeoDataset as IRasterDataset;

             pRasterlayer.CreateFromRaster(pGeoDataset as IRaster);

             axMapControl1.Map.AddLayer(pRasterlayer as ILayer);

             ISurfaceOp pSurface = new RasterSurfaceOpClass();
             object BaseHeight = Type.Missing;

             IGeoDataset p = pSurface.Contour(pGeoDataset, 2, ref BaseHeight);

             IFeatureLayer pFContourLayer = new FeatureLayerClass();

             pFContourLayer.FeatureClass = p as IFeatureClass;

             axMapControl1.AddLayer(pFContourLayer as ILayer);

             axMapControl1.Refresh();

             IWorkspaceFactory WF = new RasterWorkspaceFactoryClass();

             IWorkspace pRasterWS = WF.OpenFromFile(@".\data\IDW数据", 0);

             ISaveAs pSaveAs = (ISaveAs)pGeoDataset;

             pSaveAs.SaveAs("RasterTest.tif", pRasterWS, "TIFF");

             axMapControl1.ActiveView.Refresh();
        }