Ejemplo n.º 1
0
        private void IDWInterpolation(IFeatureClass pointFeature, IRaster refRaster, string name)
        {
            IFeatureClassDescriptor pointDescript = new FeatureClassDescriptorClass();

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

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

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

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

            System.Runtime.InteropServices.Marshal.ReleaseComObject(outDataset);
        }
Ejemplo n.º 2
0
        public IGeoDataset GetIDW(IFeatureClass _pFeatureClass, string _pFieldName, double _pDistance, double _pCell, int _pPower)
        {
            IGeoDataset             Geo              = _pFeatureClass as IGeoDataset;
            object                  pExtent          = Geo.Extent;
            object                  o                = Type.Missing;
            IFeatureClassDescriptor pFeatureClassDes = new FeatureClassDescriptorClass();

            pFeatureClassDes.Create(_pFeatureClass, null, _pFieldName);
            IInterpolationOp           pInterOp    = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment pRasterAEnv = pInterOp as IRasterAnalysisEnvironment;

            // pRasterAEnv.Mask = Geo;
            pRasterAEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref pExtent, ref o);

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

            pRasterAEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref pCellSize);

            IRasterRadius pRasterrad = new RasterRadiusClass();
            object        obj        = Type.Missing;

            // pRasterrad.SetFixed(_pDistance, ref obj);
            pRasterrad.SetVariable(12);

            object pBar = Type.Missing;

            IGeoDataset pGeoIDW = pInterOp.IDW(pFeatureClassDes as IGeoDataset, _pPower, pRasterrad, ref pBar);

            return(pGeoIDW);
        }
Ejemplo n.º 3
0
        private IGeoDataset GetBeforeGeo(IFeatureClass fc)
        {
            IInterpolationOp3 pInterpolationOp = new RasterInterpolationOpClass();

            IFields fields = fc.Fields;
            int     index  = fields.FindFieldByAliasName("高程");
            IField  field  = fields.get_Field(index);

            ISpatialFilter filter = new SpatialFilter();

            filter.Geometry   = geo;
            filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;

            IFeatureClassDescriptor pFcd = new FeatureClassDescriptorClass();

            pFcd.Create(fc, filter, field.Name);

            //定义搜索半径
            IRasterRadius pRadius = new RasterRadiusClass();
            object        Missing = Type.Missing;

            pRadius.SetVariable(12, ref Missing);

            //设置栅格图像的单位大小
            object cellSizeProvider         = 5;
            IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;

            pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            IGeoDataset outGeoDataset = pInterpolationOp.IDW(pFcd as IGeoDataset, 2, pRadius, ref Missing);

            return(outGeoDataset);
        }
Ejemplo n.º 4
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();
        }
        private IGeoDataset GetAfterGeo(IFeatureClass fc)
        {
            try
            {
                ISpatialFilter pSpatialFilter = new SpatialFilter();
                pSpatialFilter.Geometry   = geo;
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                int count = fc.FeatureCount(pSpatialFilter);
                if (count == 0)
                {
                    return(null);
                }
                IFeatureCursor cursor = fc.Search(pSpatialFilter, true);
                IFeature       feature;
                while ((feature = cursor.NextFeature()) != null)
                {
                    int index = feature.Fields.FindField("HEIGHT");
                    if (index == -1)
                    {
                        continue;
                    }
                    feature.set_Value(index, h);
                    feature.Store();
                }

                IInterpolationOp3 pInterpolationOp = new RasterInterpolationOpClass();

                IFields fields = fc.Fields;
                int     index1 = fields.FindField("HEIGHT");
                if (index1 == -1)
                {
                    return(null);
                }
                IField field = fields.get_Field(index1);

                IFeatureClassDescriptor pFcd = new FeatureClassDescriptorClass();
                pFcd.Create(fc, pSpatialFilter, field.Name);

                //定义搜索半径
                IRasterRadius pRadius = new RasterRadiusClass();
                object        Missing = Type.Missing;
                pRadius.SetVariable(12, ref Missing);

                //设置栅格图像的单位大小
                object cellSizeProvider         = 5;
                IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;
                pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
                IGeoDataset outGeoDataset = pInterpolationOp.IDW(pFcd as IGeoDataset, 2, pRadius, ref Missing);
                return(outGeoDataset);
            }
            catch (System.Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        private IGeoDataset GetBeforeGeo(IFeatureClass fc, IGeometry geo)
        {
            try
            {
                WaitForm.SetCaption("正在生成栅格表面...");
                IInterpolationOp3 pInterpolationOp = new RasterInterpolationOpClass();

                IFields       fields            = fc.Fields;
                FacilityClass fac               = FacilityClassManager.Instance.GetFacilityClassByName("GCD");
                DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("Altitude");
                if (fi == null)
                {
                    return(null);
                }

                int index = fields.FindField(fi.Name);
                if (index == -1)
                {
                    return(null);
                }
                IField field = fields.get_Field(index);

                ISpatialFilter filter = new SpatialFilter();
                filter.Geometry   = geo;
                filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                int count = fc.FeatureCount(filter);
                if (count == 0)
                {
                    return(null);
                }
                IFeatureClassDescriptor pFcd = new FeatureClassDescriptorClass();
                pFcd.Create(fc, filter, field.Name);

                //定义搜索半径
                IRasterRadius pRadius = new RasterRadiusClass();
                object        Missing = Type.Missing;
                pRadius.SetVariable(12, ref Missing);

                //设置栅格图像的单位大小
                object cellSizeProvider         = 5;
                IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;
                pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
                IGeoDataset outGeoDataset = pInterpolationOp.IDW(pFcd as IGeoDataset, 2, pRadius, ref Missing);
                return(outGeoDataset);
            }
            catch (System.Exception ex)
            {
                return(null);

                WaitForm.Stop();
            }
        }
Ejemplo n.º 7
0
        }//Open Feature Class

        private void IDWOperate(IFeatureClass inFC)
        {
            IFeatureClassDescriptor iFCDesc = new FeatureClassDescriptorClass();
            //获取选中的字符串
            string sFieldName = comboBox1.SelectedText;

            iFCDesc.Create(inFC, null, sFieldName);
            //创建RasterInterpolationOp对象
            IInterpolationOp iIo = new RasterInterpolationOpClass();

            //设置输出Raster网格大小,默认的Raster输出空间范围和输入数据相同
            IRasterAnalysisEnvironment iRae = (IRasterAnalysisEnvironment)iIo;
            object oCellSize = (object)Convert.ToDouble(textBox2.Text);

            iRae.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref oCellSize);

            //搜索范围设置
            IRasterRadius iRadius = new RasterRadiusClass();
            //switch (comboBox2.SelectedIndex)
            //{
            //    case 0:
            object dis = (object)Convert.ToDouble(textBox3.Text);

            iRadius.SetVariable(Convert.ToInt32(textBox1.Text), ref dis);
            //        break;
            //    case 1:
            //        object cou = (object)Convert.ToDouble(textBox3.Text);
            //        iRadius.SetFixed(Convert.ToDouble(textBox1.Text), ref cou);
            //        break;
            //    default:
            //        break;
            //}

            IGeoDataset iInputGeo  = (IGeoDataset)iFCDesc;
            object      barrier    = Type.Missing;
            IGeoDataset iOutputGeo = iIo.IDW(iInputGeo, Convert.ToDouble(textBox2.Text), iRadius, ref barrier);

            IRaster iOutRaster = (IRaster)iOutputGeo;
            IRasterBandCollection iRasBnadC = (IRasterBandCollection)iOutRaster;
            IWorkspaceFactory     iWSF      = new RasterWorkspaceFactoryClass();
            IWorkspace            iWS       = iWSF.OpenFromFile(textBox5.Text, 0);

            IDataset iDs = iRasBnadC.SaveAs("Raster_test", iWS, "GRID");
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            IFeatureClass pInPointFClass;     //获得输入点特征数据类
            IFeatureClass pLineBarrierFClass; //获得输入的线障碍类

            String fileName;
            String rasterPath;
            String shpFile;
            int    startX, endX;

            //选择要进行分析的字段
            if (bDataPath == true)
            {
                fileName = comboBoxInPoint.Text;
                String shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX  = fileName.LastIndexOf("\\");
                endX    = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
                IWorkspaceFactory pWorkspaceFactory;
                pWorkspaceFactory = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFWS;
                pFWS = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(shpDir, 0);

                pInPointFClass = pFWS.OpenFeatureClass(shpFile);
            }
            else
            {
                pInPointFClass = GetFeatureFromMapLyr(comboBoxInPoint.Text);
            }

            if (bDataLinePath == true && chkBarrier.Checked)
            {
                fileName = comboBoxBarrier.Text;
                String shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX  = fileName.LastIndexOf("\\");
                endX    = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
                IWorkspaceFactory pWorkspaceFactory;
                pWorkspaceFactory = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFWS;
                pFWS = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(shpDir, 0);
                pLineBarrierFClass = pFWS.OpenFeatureClass(shpFile);
            }
            else if (chkBarrier.Checked)
            {
                pLineBarrierFClass = GetFeatureFromMapLyr(comboBoxBarrier.Text);
            }
            IFeatureLayer pFeatLayer = new FeatureLayerClass();

            pFeatLayer.FeatureClass = pInPointFClass;
            rasterPath = txtOutputRasterPath.Text;
            //查询过滤器

            //'FeatureClassDescriptor
            //这个对象主要用于提供访问控制FeatureClass descriptor的成员;例如,定义FeatureClass的那个属性作为分析操作。
            IFeatureClassDescriptor pFeatClsDes = new FeatureClassDescriptorClass();

            if (comboBoxZValueField.Text != "无")
            {
                pFeatClsDes.Create(pInPointFClass, null, comboBoxZValueField.Text);
            }
            else
            {
                pFeatClsDes.Create(pInPointFClass, null, "");
            }

            try
            {
                IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass();
                String           sCellSize        = txtCellSize.Text;
                String           sPower           = txtWeightValue.Text;
                if (Convert.ToDouble(sCellSize) <= 0 || sPower == "")
                {
                    MessageBox.Show("还没输入权重值或栅格单元!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                double dCellSize = Convert.ToDouble(sCellSize);
                double dPower    = Convert.ToDouble(sPower);

                IRasterRadius pRsRadius = new RasterRadiusClass();
                if (comboBoxSearchRadius.Text == "变化")
                {
                    String sPointNums = txtPointNumbers.Text;
                    if (sPointNums != "")
                    {
                        int iPointNums = Convert.ToInt32(sPointNums);
                        if (txtDisMaxValue.Text != "")
                        {
                            double maxDis    = Convert.ToDouble(txtDisMaxValue.Text);
                            object objMaxDis = maxDis as object;
                            pRsRadius.SetVariable(iPointNums, ref objMaxDis);
                        }
                        else
                        {
                            object objMaxDis = null;
                            pRsRadius.SetVariable(iPointNums, ref objMaxDis);
                        }
                    }
                    else
                    {
                        MessageBox.Show("还没输入点的数目!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                else
                {
                    String sDistance = txtDisValue.Text;
                    if (sDistance != "")
                    {
                        double dDistance = Convert.ToDouble(sDistance);
                        if (txtMaxPointNums.Text != "")
                        {
                            double maxPointNums    = Convert.ToDouble(txtMaxPointNums.Text);
                            object objMinPointNums = maxPointNums as object;
                            pRsRadius.SetFixed(dDistance, ref objMinPointNums);
                        }
                        else
                        {
                            object objMinPointNums = null;
                            pRsRadius.SetFixed(dDistance, ref objMinPointNums);
                        }
                    }
                    else
                    {
                        MessageBox.Show("还没输入距离的值!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                pInterpolationOp = SetRasterInterpolationAnalysisEnv(rasterPath, dCellSize, pFeatLayer);
                object objLineBarrier = null;
                if (chkBarrier.Checked == true)
                {
                    objLineBarrier = comboBoxBarrier;
                }
                else
                {
                    objLineBarrier = Type.Missing;
                }


                IRaster pOutRaster;
                pOutRaster = (IRaster)pInterpolationOp.IDW((IGeoDataset)pFeatClsDes, dPower, pRsRadius, ref objLineBarrier);
                //着色
                IRasterLayer pRasterLayer = new RasterLayerClass();
                pRasterLayer.Name = "反距离栅格";
                ConvertRasterToRsDataset(rasterPath, ref pOutRaster, "反距离栅格");
                pRasterLayer = SetRsLayerClassifiedColor(pOutRaster);
                frm.mainMapControl.AddLayer(pRasterLayer, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 11
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            IFeatureClass pInPointFClass = null;//������������������
            IFeatureClass pLineBarrierFClass = null;//�����������ϰ���
            IWorkspace pWorkspace;

            string fileName;
            string rasterPath;
            string shpFile;
            int startX, endX;
            string sFieldName;//ѡ��Ҫ���з������ֶ�
            if (bDataPath == true)
            {
                fileName = comboBoxInPoint.Text;
                string shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX = fileName.LastIndexOf("\\");
                endX = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
                pInPointFClass = Utility.OpenFeatureClassFromShapefile(shpDir, shpFile);
            }
            else
            {
                pInPointFClass = GetFeatureFromMapLyr(comboBoxInPoint.Text);
            }
            if (bDataLinePath == true)
            {
                fileName = comboBoxBarrier.Text;
                string shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX = fileName.LastIndexOf("\\");
                endX = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
                pLineBarrierFClass = Utility.OpenFeatureClassFromShapefile(shpDir, shpFile);
            }
            else
            {
                pLineBarrierFClass = GetFeatureFromMapLyr(comboBoxBarrier.Text);
            }
            IFeatureLayer pFeatLayer = new FeatureLayerClass();
            pFeatLayer.FeatureClass = pInPointFClass;
            rasterPath = txtOutputRasterPath.Text;
            IFeatureClassDescriptor pFeatClsDes = new FeatureClassDescriptorClass();
            if (comboBoxZValueField.Text != "��")
                pFeatClsDes.Create(pInPointFClass, null, comboBoxZValueField.Text);
            else
                pFeatClsDes.Create(pInPointFClass, null, "");
            try
            {
                IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass();
                string sCellSize = txtCellSize.Text;
                double dCellSize = Convert.ToDouble(sCellSize);
                IRasterRadius pRsRadius = new RasterRadiusClass();
                string sPower=txtWeightValue.Text;
                double dPower=Convert.ToDouble(sPower);
                if(comboBoxSearchRadius.Text == "�仯")
                {
                    string sPointNums=txtPointNumbers.Text;
                    int iPointNums=Convert.ToInt32(sPointNums);
                    double maxDis=Convert.ToDouble(txtDisMaxValue.Text);
                    object objMaxDis=maxDis;
                    pRsRadius.SetVariable(iPointNums,ref objMaxDis);
                }
                else
                {
                    string sDistance=txtDisValue.Text;
                    double dDistance=Convert.ToDouble(sDistance);
                    double maxPointNums=Convert.ToDouble(txtMaxPointNums.Text);
                    object objMinPointNums=maxPointNums;
                    pRsRadius.SetFixed(dDistance,ref objMinPointNums);
                }

                pInterpolationOp = Utility.SetRasterInterpolationAnalysisEnv(rasterPath, dCellSize, pFeatLayer);
                object objLineBarrier=null;
                if (chkBarrier.Checked == true)
                {
                    objLineBarrier=comboBoxBarrier;
                }
                else
                {
                    objLineBarrier = Type.Missing;
                }
                IRaster pOutRaster = null;
                pOutRaster = pInterpolationOp.IDW(pFeatClsDes as IGeoDataset, dPower, pRsRadius, ref objLineBarrier) as IRaster;

                //��ɫ
                IRasterLayer pRasterLayer = new RasterLayerClass();
                pRasterLayer.Name = "������դ��";
                Utility.ConvertRasterToRsDataset(rasterPath, pOutRaster, "������դ��");
                pRasterLayer = Utility.SetRsLayerClassifiedColor(pOutRaster);
                pMainFrm.getMapControl().AddLayer(pRasterLayer, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
Ejemplo n.º 12
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            IFeatureClass pInPointFClass     = null; //获得输入点特征数据类
            IFeatureClass pLineBarrierFClass = null; //获得输入的线障碍类
            IWorkspace    pWorkspace;

            string fileName;
            string rasterPath;
            string shpFile;
            int    startX, endX;
            string sFieldName;//选择要进行分析的字段

            if (bDataPath == true)
            {
                fileName = comboBoxInPoint.Text;
                string shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX         = fileName.LastIndexOf("\\");
                endX           = fileName.Length;
                shpFile        = fileName.Substring(startX + 1, endX - startX - 1);
                pInPointFClass = Utility.OpenFeatureClassFromShapefile(shpDir, shpFile);
            }
            else
            {
                pInPointFClass = GetFeatureFromMapLyr(comboBoxInPoint.Text);
            }
            if (bDataLinePath == true)
            {
                fileName = comboBoxBarrier.Text;
                string shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX             = fileName.LastIndexOf("\\");
                endX               = fileName.Length;
                shpFile            = fileName.Substring(startX + 1, endX - startX - 1);
                pLineBarrierFClass = Utility.OpenFeatureClassFromShapefile(shpDir, shpFile);
            }
            else
            {
                pLineBarrierFClass = GetFeatureFromMapLyr(comboBoxBarrier.Text);
            }
            IFeatureLayer pFeatLayer = new FeatureLayerClass();

            pFeatLayer.FeatureClass = pInPointFClass;
            rasterPath = txtOutputRasterPath.Text;
            IFeatureClassDescriptor pFeatClsDes = new FeatureClassDescriptorClass();

            if (comboBoxZValueField.Text != "无")
            {
                pFeatClsDes.Create(pInPointFClass, null, comboBoxZValueField.Text);
            }
            else
            {
                pFeatClsDes.Create(pInPointFClass, null, "");
            }
            try
            {
                IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass();
                string           sCellSize        = txtCellSize.Text;
                double           dCellSize        = Convert.ToDouble(sCellSize);
                IRasterRadius    pRsRadius        = new RasterRadiusClass();
                string           sPower           = txtWeightValue.Text;
                double           dPower           = Convert.ToDouble(sPower);
                if (comboBoxSearchRadius.Text == "变化")
                {
                    string sPointNums = txtPointNumbers.Text;
                    int    iPointNums = Convert.ToInt32(sPointNums);
                    double maxDis     = Convert.ToDouble(txtDisMaxValue.Text);
                    object objMaxDis  = maxDis;
                    pRsRadius.SetVariable(iPointNums, ref objMaxDis);
                }
                else
                {
                    string sDistance       = txtDisValue.Text;
                    double dDistance       = Convert.ToDouble(sDistance);
                    double maxPointNums    = Convert.ToDouble(txtMaxPointNums.Text);
                    object objMinPointNums = maxPointNums;
                    pRsRadius.SetFixed(dDistance, ref objMinPointNums);
                }

                pInterpolationOp = Utility.SetRasterInterpolationAnalysisEnv(rasterPath, dCellSize, pFeatLayer);
                object objLineBarrier = null;
                if (chkBarrier.Checked == true)
                {
                    objLineBarrier = comboBoxBarrier;
                }
                else
                {
                    objLineBarrier = Type.Missing;
                }
                IRaster pOutRaster = null;
                pOutRaster = pInterpolationOp.IDW(pFeatClsDes as IGeoDataset, dPower, pRsRadius, ref objLineBarrier) as IRaster;

                //着色
                IRasterLayer pRasterLayer = new RasterLayerClass();
                pRasterLayer.Name = "反距离栅格";
                Utility.ConvertRasterToRsDataset(rasterPath, pOutRaster, "反距离栅格");
                pRasterLayer = Utility.SetRsLayerClassifiedColor(pOutRaster);
                pMainFrm.getMapControl().AddLayer(pRasterLayer, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 13
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;
            }
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        private IGeoDataset GetAfterGeo(IFeatureClass fc, IGeometry geo)
        {
            try
            {
                WaitForm.SetCaption("正在计算填挖表面...");
                ISpatialFilter pSpatialFilter = new SpatialFilter();
                pSpatialFilter.Geometry   = geo;
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                int count = fc.FeatureCount(pSpatialFilter);
                if (count == 0)
                {
                    return(null);
                }
                IFeatureCursor cursor = fc.Search(pSpatialFilter, true);
                IFeature       feature;
                FacilityClass  fac = FacilityClassManager.Instance.GetFacilityClassByName("GCD");
                DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("Height");
                if (fi == null)
                {
                    return(null);
                }
                while ((feature = cursor.NextFeature()) != null)
                {
                    int index = feature.Fields.FindField(fi.Name);
                    if (index == -1)
                    {
                        continue;
                    }
                    feature.set_Value(index, h);
                    feature.Store();
                }

                IInterpolationOp3 pInterpolationOp = new RasterInterpolationOpClass();

                //IFields fields = fc.Fields;
                //int index1 = fields.FindField("HEIGHT");
                //if (index1 == -1) return null;
                //IField field = fields.get_Field(index1);

                IFeatureClassDescriptor pFcd = new FeatureClassDescriptorClass();
                pFcd.Create(fc, pSpatialFilter, fi.Name);

                //定义搜索半径
                IRasterRadius pRadius = new RasterRadiusClass();
                object        Missing = Type.Missing;
                pRadius.SetVariable(12, ref Missing);

                //设置栅格图像的单位大小
                object cellSizeProvider         = 5;
                IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;
                pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
                IGeoDataset outGeoDataset = pInterpolationOp.IDW(pFcd as IGeoDataset, 2, pRadius, ref Missing);
                return(outGeoDataset);
            }
            catch (System.Exception ex)
            {
                return(null);

                WaitForm.Stop();
            }
        }
Ejemplo n.º 16
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);

            //两种方法的结合后
        }
Ejemplo n.º 17
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);
            }
        }
        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
        }
Ejemplo n.º 19
0
        public IGeoDataset GetIDW(IFeatureClass _pFeatureClass, string _pFieldName, double _pDistance, double _pCell, int _pPower)
        {
            IGeoDataset Geo = _pFeatureClass as IGeoDataset;
               object pExtent = Geo.Extent;
               object o = Type.Missing;
               IFeatureClassDescriptor pFeatureClassDes = new FeatureClassDescriptorClass();
               pFeatureClassDes.Create(_pFeatureClass, null, _pFieldName);
               IInterpolationOp pInterOp = new RasterInterpolationOpClass();
               IRasterAnalysisEnvironment pRasterAEnv = pInterOp as IRasterAnalysisEnvironment;

              // pRasterAEnv.Mask = Geo;
               pRasterAEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref pExtent, ref o);

               object pCellSize = _pCell;//���Ը��ݲ�ͬ�ĵ�ͼ���������

               pRasterAEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref pCellSize);

               IRasterRadius pRasterrad = new RasterRadiusClass();
               object obj = Type.Missing;
              // pRasterrad.SetFixed(_pDistance, ref obj);
               pRasterrad.SetVariable(12);

               object pBar = Type.Missing;

               IGeoDataset pGeoIDW = pInterOp.IDW(pFeatureClassDes as IGeoDataset, _pPower, pRasterrad, ref pBar);

               return pGeoIDW;
        }