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

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

            rasterAnalysisEnvironment.OutWorkspace = workspace;


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

            rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _extentEnvelope, ref objectMissing);
            //set output spatial reference
            rasterAnalysisEnvironment.OutSpatialReference = ((IGeoDataset)pFeatureClass).SpatialReference;
            //convertion
            conversionOp.ToRasterDataset(geoDataset, _rasterType, workspace, newRasterName);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private void CreateDEM()
        {
            IWorkspaceFactory pWsF    = new AccessWorkspaceFactory();
            IFeatureWorkspace pWs     = pWsF.OpenFromFile(textEdit1.Text, 0) as IFeatureWorkspace;
            IFeatureDataset   pFDs    = pWs.OpenFeatureDataset("GCD");
            IFeatureClass     pFc     = pFDs as IFeatureClass;
            double            power   = 1;
            object            Missing = Type.Missing;


            IFields pFields = pFc.Fields;
            int     index   = pFields.FindFieldByAliasName("高程");
            string  z       = pFields.get_Field(index).Name;


            IFeatureClassDescriptor feaDes = new FeatureClassDescriptorClass();

            feaDes.Create(pFc, null, z);
            IGeoDataset inGeoDs = feaDes as IGeoDataset;

            IRasterAnalysisEnvironment rasterEnv = new RasterInterpolationOpClass();
            double cellSize    = 20;
            object cellSizeObj = cellSize;

            rasterEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeObj);

            IRasterRadius radius = new RasterRadiusClass();

            radius.SetVariable(12, Missing);

            IInterpolationOp2 interOp  = rasterEnv as IInterpolationOp2;
            IGeoDataset       outGeoDs = interOp.IDW(inGeoDs, power, radius, ref Missing);

            pWs = pWsF.OpenFromFile(textEdit2.Text, 0) as IFeatureWorkspace;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 转换
        /// </summary>
        /// <param name="pFeatureClass">要素类</param>
        /// <param name="fieldName">栅格采用的字段</param>
        /// <param name="rasterWorkSpace">输出栅格的工作空间</param>
        /// <param name="newRasterName">新的栅格名称</param>
        public void Convert(IFeatureClass pFeatureClass,
            string fieldName,
            string rasterWorkSpace,
            string newRasterName)
        {
            FileHelper.DeleteFile(rasterWorkSpace, newRasterName, ".tif", ".tfw",".tif.aux");
            IFeatureClassDescriptor featureClassDescriptor = new FeatureClassDescriptorClass();
            featureClassDescriptor.Create(pFeatureClass, null, fieldName);
            IGeoDataset geoDataset = (IGeoDataset)featureClassDescriptor;
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();           
            IWorkspace workspace = workspaceFactory.OpenFromFile(rasterWorkSpace, 0);
            IConversionOp conversionOp = new RasterConversionOpClass();
            IRasterAnalysisEnvironment rasterAnalysisEnvironment = (IRasterAnalysisEnvironment)conversionOp;
            rasterAnalysisEnvironment.OutWorkspace = workspace;

       
            //set cell size
            rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _cellSize);
            //set output extent  
            object objectMissing = Type.Missing;
            rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref _extentEnvelope, ref objectMissing);
            //set output spatial reference 
            rasterAnalysisEnvironment.OutSpatialReference = ((IGeoDataset)pFeatureClass).SpatialReference;
            //convertion
            conversionOp.ToRasterDataset(geoDataset, _rasterType, workspace, newRasterName);              
        }    
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 矢量点转栅格
        /// </summary>
        /// <param name="xjFeatureLayer">矢量图层</param>
        /// <param name="RasterPath">栅格绝对路径</param>
        /// <param name="CellSize">栅格边长</param>
        /// <param name="SecletctedField">所选字段(高程等)</param>
        /// <returns>返回栅格图层</returns>
        private ILayer xjShpPointToRaster(IFeatureLayer xjFeatureLayer, string RasterPath, double CellSize, string SecletctedField)
        {
            IFeatureClass           xjFeatureClass           = xjFeatureLayer.FeatureClass;
            IFeatureClassDescriptor xjFeatureClassDescriptor = new FeatureClassDescriptorClass();//using ESRI.ArcGIS.GeoAnalyst;

            xjFeatureClassDescriptor.Create(xjFeatureClass, null, SecletctedField);
            IGeoDataset xjGeoDataset = xjFeatureClassDescriptor as IGeoDataset;

            IWorkspaceFactory          xjwsf          = new RasterWorkspaceFactoryClass(); //using ESRI.ArcGIS.DataSourcesRaster;
            string                     xjRasterFolder = System.IO.Path.GetDirectoryName(RasterPath);
            IWorkspace                 xjws           = xjwsf.OpenFromFile(xjRasterFolder, 0);
            IConversionOp              xjConversionOp = new RasterConversionOpClass();
            IRasterAnalysisEnvironment xjRasteren     = xjConversionOp as IRasterAnalysisEnvironment;

            object xjCellSize = CellSize as object;

            xjRasteren.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref xjCellSize);

            string         xjFileName = System.IO.Path.GetFileName(RasterPath);
            IRasterDataset xjdaset2   = xjConversionOp.ToRasterDataset(xjGeoDataset, "TIFF", xjws, xjFileName);

            IRasterLayer xjRasterLayer = new RasterLayerClass();

            xjRasterLayer.CreateFromDataset(xjdaset2);
            ILayer xjLayer = xjRasterLayer;

            xjRasterLayer.Name = xjFileName;

            return(xjLayer);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 执行矢量转栅格
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FtoR_backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

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


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

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

                    IConversionOp conversionOp = new RasterConversionOpClass();
                    //转换设置
                    IRasterAnalysisEnvironment rasterAnalysisEnvironment = conversionOp as IRasterAnalysisEnvironment;
                    //栅格的大小
                    double dCellSize = Convert.ToDouble(featuretoraster_cellsize.Text);
                    object oCellSize = dCellSize as object;
                    //设置栅格大小
                    rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref oCellSize);
                    string format = "";
                    if (outputinfo.Extension == ".tif")
                    {
                        format = "TIFF";
                    }
                    else if (outputinfo.Extension == ".img")
                    {
                        format = "IMAGINE Image";
                    }
                    else
                    {
                        format = "GRID";
                    }
                    //启动预处理计时
                    watch = new Stopwatch();
                    watch.Start();
                    //执行转换
                    conversionOp.ToRasterDataset(geodatasetop, format, outputworkspaceop, outputinfo.Name);
                }
                catch (Exception erro)
                {
                    MessageBox.Show(erro.Message, "错误");
                }
            }
        }
Exemplo n.º 9
0
        private IFunctionRasterDataset createBarrierRaster()
        {
            IFeatureClassDescriptor ftrDesc = new FeatureClassDescriptorClass();
            IQueryFilter            qf      = new QueryFilterClass();

            ftrDesc.Create(BarriersFeatureClass, qf, BarriersFeatureClass.OIDFieldName);
            IConversionOp convOp = new RasterConversionOpClass();
            IRasterAnalysisEnvironment       rasterAnalysisEnvironment       = (IRasterAnalysisEnvironment)convOp;
            IRasterAnalysisGlobalEnvironment rasterAnalysisGlobalEnvironment = (IRasterAnalysisGlobalEnvironment)convOp;

            rasterAnalysisGlobalEnvironment.AvoidDataConversion = true;
            rasterAnalysisEnvironment.OutSpatialReference       = sp;
            rasterAnalysisEnvironment.OutWorkspace = OutWorkspace;
            //object cells = Dem.RasterInfo.CellSize;
            object ext  = ((IGeoDataset)Dem).Extent;
            object snap = ((IGeoDataset)Dem);

            rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, Dem);
            rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ext, Dem);
            string                 outRdName = rsUtil.getSafeOutputName(OutWorkspace, "sBarrier");
            IRasterDataset         geoDset   = convOp.ToRasterDataset((IGeoDataset)ftrDesc, "GRID", OutWorkspace, outRdName);
            IGeoDatasetSchemaEdit2 geoSch    = (IGeoDatasetSchemaEdit2)geoDset;

            if (geoSch.CanAlterSpatialReference)
            {
                geoSch.AlterSpatialReference(rasterAnalysisEnvironment.OutSpatialReference);
            }
            return(rsUtil.createIdentityRaster(geoDset));
        }
Exemplo n.º 10
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();
        }
Exemplo n.º 11
0
        public static void Mlayer_Krige_Click()
        {
            // 用克里金Krige插值生成的栅格图像。如下:
            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");

            IInterpolationOp           pInterpolationOp = new RasterInterpolationOpClass();
            IRasterAnalysisEnvironment pEnv             = pInterpolationOp as IRasterAnalysisEnvironment;

            object Cellsize = 0.004;//Cell size for output raster;0.004

            pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref Cellsize);
            //设置输出范围
            //27202 19104;27202 22947;31550 22947;31550 19104
            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;

            pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
            Double        dSearchD     = 10;
            object        pSearchCount = 3;
            object        missing      = Type.Missing;
            IRasterRadius pRadius      = new RasterRadius();

            pRadius.SetFixed(dSearchD, ref pSearchCount);
            //pRadius.SetVariable((int)pSearchCount, ref dSearchD);

            IGeoDataset poutGeoDataset = pInterpolationOp.Krige((IGeoDataset)pFCDescriptor, esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisGaussianSemiVariogram, pRadius, false, ref missing);

            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);
            }
        }
Exemplo n.º 13
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();
            }
        }
        /// <summary>
        /// 矢量转栅格
        /// </summary>
        /// <param name="IFeatureClass">要转换的矢量数据</param>
        /// <param name="eleField">转换的字段名</param>
        /// <param name="cellsize">栅格大小,默认为null</param>
        ///<param name="rasterSavePath">保存路径</param>
        ///<param name="demName">dem名称</param>
        /// <returns>返回ILayer类型的图层</returns>
        public ILayer FeatureToRaster(IFeatureClass pFeatureClass, string eleField, object cellSize, string rasterSavePath, string demName)
        {
            IFeatureClassDescriptor pFeatureClassDescriptor = new FeatureClassDescriptorClass(); //获取转化的字段

            pFeatureClassDescriptor.Create(pFeatureClass, null, eleField);                       //转换字段
            IGeoDataset pGeoDataset = (IGeoDataset)pFeatureClassDescriptor;                      //获取第一个参数

            //默认栅格大小
            if (Convert.ToDouble(cellSize) <= 0)
            {
                IEnvelope envelope = pGeoDataset.Extent;
                if (envelope.Width > envelope.Height)
                {
                    cellSize = envelope.Height / 250;
                }
                else
                {
                    cellSize = envelope.Width / 250;
                }
            }
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace2 rasterWorkspace2 = workspaceFactory.OpenFromFile(rasterSavePath, 0) as IRasterWorkspace2;

            //in case that there is already an existing raster with the raster name, try to delete it
            if (System.IO.Directory.Exists(System.IO.Path.Combine(rasterSavePath, demName)))
            {
                IDataset dataset = rasterWorkspace2.OpenRasterDataset(demName) as IDataset;
                dataset.Delete();
            }
            IConversionOp conversionOp = new RasterConversionOpClass();
            IRasterAnalysisEnvironment rasterAnalysisEnvironment = conversionOp as IRasterAnalysisEnvironment;

            rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSize);
            IRasterDataset rasterDataset = null;

            try
            { rasterDataset = conversionOp.ToRasterDataset(pGeoDataset, "TIFF", (IWorkspace)rasterWorkspace2, demName); }
            catch (Exception ee)
            { MessageBox.Show(ee.Message); }
            ILayer layer = null;

            if (rasterDataset != null)
            {
                IRasterLayer pRlyr = new RasterLayerClass();
                pRlyr.CreateFromDataset(rasterDataset);
                layer = pRlyr as ILayer;
            }
            return(layer);
        }
Exemplo n.º 15
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");
        }
Exemplo n.º 16
0
        private void _PunchDEM()
        {
            OnProgress("Punching DEM with drainage points...");

            IConversionOp conversionOp   = new RasterConversionOpClass();
            ILogicalOp    logicalOp      = new RasterMathOpsClass();
            IGeoDataset   inletLocations = null;
            IWorkspace    tempWorkspace  = null;

            try
            {
                tempWorkspace = GetTempRasterWorkspace();

                SetAnalysisEnvironment((IRasterAnalysisEnvironment)conversionOp);
                SetAnalysisEnvironment((IRasterAnalysisEnvironment)logicalOp);

                IFeatureClassDescriptor sourceDescriptor = new FeatureClassDescriptorClass();
                sourceDescriptor.Create(_drainClass, null, _drainClass.OIDFieldName);
                string gridPath = SetupOp.CreateTempFileName(_GetTempDir(), "TmpInlets", null);
                string gridName = System.IO.Path.GetFileName(gridPath);

                IRasterDataset pRasterDataset = null;
                try
                {
                    pRasterDataset = conversionOp.ToRasterDataset((IGeoDataset)sourceDescriptor, "GRID", tempWorkspace, gridName);
                    inletLocations = logicalOp.BooleanNot(logicalOp.IsNull((IGeoDataset)pRasterDataset));
                    string outputPath = CreateTempFileName(_GetResultDir(), "punchdem", "");
                    _punchedDEM = GeoprocessingTools.SetNull((IRaster)inletLocations, _dem, outputPath);
                }
                finally
                {
                    _MarkForDisposal((IDataset)pRasterDataset);
                }
            }
            finally
            {
                UrbanDelineationExtension.ReleaseComObject(tempWorkspace);
                UrbanDelineationExtension.ReleaseComObject(conversionOp);
                UrbanDelineationExtension.ReleaseComObject(logicalOp);
            }

            OnProgress("DEM punched.");
        }
Exemplo n.º 17
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);

            }
        }
Exemplo n.º 18
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();
        }
Exemplo n.º 19
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);
            }
        }
        /// <summary>
        /// Where all of the work is done.  Override from TabBaseViewModel
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;

                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                {
                    return;
                }

                //base.CreateMapElement();

                var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                if (surface == null)
                {
                    return;
                }

                // Determine if selected surface is projected or geographic
                ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
                var    geoDataset   = surfaceLayer as IGeoDataset;
                SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

                if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
                {
                    MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSUserPrompt, VisibilityLibrary.Properties.Resources.RLOSUserPromptCaption);
                    return;
                }

                if (geoDataset != null && ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
                {
                    MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
                    return;
                }

                using (ComReleaser oComReleaser = new ComReleaser())
                {
                    // Create feature workspace
                    IFeatureWorkspace workspace = CreateFeatureWorkspace("tempWorkspace");

                    StartEditOperation((IWorkspace)workspace);

                    // Create feature class
                    IFeatureClass pointFc = CreateObserversFeatureClass(workspace, SelectedSurfaceSpatialRef, "Output" + RunCount.ToString());

                    double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                    double finalSurfaceOffset  = GetOffsetInZUnits(SurfaceOffset, surface.ZFactor, OffsetUnitType);

                    double conversionFactor     = GetConversionFactor(SelectedSurfaceSpatialRef);
                    double convertedMinDistance = MinDistance * conversionFactor;
                    double convertedMaxDistance = MaxDistance * conversionFactor;
                    double finalMinDistance     = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, OffsetUnitType);
                    double finalMaxDistance     = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, OffsetUnitType);

                    double finalLeftHorizontalFOV  = GetAngularDistance(ArcMap.Document.FocusMap, LeftHorizontalFOV, AngularUnitType);
                    double finalRightHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, RightHorizontalFOV, AngularUnitType);
                    double finalBottomVerticalFOV  = GetAngularDistance(ArcMap.Document.FocusMap, BottomVerticalFOV, AngularUnitType);
                    double finalTopVerticalFOV     = GetAngularDistance(ArcMap.Document.FocusMap, TopVerticalFOV, AngularUnitType);

                    // Out radius geometries
                    List <IGeometry> radius2GeomList   = new List <IGeometry>();
                    List <IGeometry> radius1_2GeomList = new List <IGeometry>();
                    List <IGeometry> donutGeomList     = new List <IGeometry>();

                    foreach (var observerPoint in ObserverAddInPoints)
                    {
                        // Create buffer geometries for final Min/Max distance
                        ITopologicalOperator topologicalOperator = observerPoint.Point as ITopologicalOperator;
                        IGeometry            geom = topologicalOperator.Buffer(finalMaxDistance);
                        radius2GeomList.Add(geom);
                        radius1_2GeomList.Add(geom);
                        if (finalMinDistance > 0)
                        {
                            IGeometry geom2 = topologicalOperator.Buffer(finalMinDistance);

                            ITopologicalOperator eraseTopo  = geom as ITopologicalOperator;
                            IGeometry            erasedGeom = eraseTopo.Difference(geom2);
                            donutGeomList.Add(erasedGeom);
                        }
                        else
                        {
                            radius1_2GeomList.Add(geom);
                        }

                        double z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                        //create a new point feature
                        IFeature ipFeature = pointFc.CreateFeature();

                        // Set the field values for the feature
                        SetFieldValues(finalObserverOffset, finalSurfaceOffset, finalMinDistance, finalMaxDistance, finalLeftHorizontalFOV,
                                       finalRightHorizontalFOV, finalBottomVerticalFOV, finalTopVerticalFOV, ipFeature);

                        if (double.IsNaN(z1))
                        {
                            System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                            return;
                        }

                        //Create shape
                        IPoint point = new PointClass()
                        {
                            Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true
                        };
                        ipFeature.Shape = point;
                        ipFeature.Store();
                    }

                    IFeatureClassDescriptor fd = new FeatureClassDescriptorClass();
                    fd.Create(pointFc, null, "OBJECTID");

                    StopEditOperation((IWorkspace)workspace);

                    try
                    {
                        ILayer layer     = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
                        string layerPath = GetLayerPath(layer);

                        IFeatureLayer ipFeatureLayer = new FeatureLayerClass();
                        ipFeatureLayer.FeatureClass = pointFc;

                        IDataset ipDataset    = (IDataset)pointFc;
                        string   outputFcName = ipDataset.BrowseName + "_output";
                        string   strPath      = ipDataset.Workspace.PathName + "\\" + ipDataset.BrowseName;
                        string   outPath      = ipDataset.Workspace.PathName + "\\" + outputFcName;

                        IVariantArray parameters = new VarArrayClass();
                        parameters.Add(layerPath);
                        parameters.Add(strPath);
                        parameters.Add(outPath);

                        esriLicenseStatus status = GetSpatialAnalystLicense();
                        if (status == esriLicenseStatus.esriLicenseUnavailable || status == esriLicenseStatus.esriLicenseFailure ||
                            status == esriLicenseStatus.esriLicenseNotInitialized || status == esriLicenseStatus.esriLicenseNotLicensed ||
                            status == esriLicenseStatus.esriLicenseUnavailable)
                        {
                            System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSSpatialAnalystLicenseInvalid, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                            return;
                        }

                        IGeoProcessor2 gp = new GeoProcessorClass();

                        gp.AddOutputsToMap = false;

                        // Add a mask to buffer the output to selected distance
                        SetGPMask(workspace, radius2GeomList, gp, "radiusMask");

                        object oResult = gp.Execute("Visibility_sa", parameters, null);
                        IGeoProcessorResult ipResult = (IGeoProcessorResult)oResult;

                        ComReleaser.ReleaseCOMObject(gp);
                        gp = null;
                        GC.Collect();

                        // Add buffer geometries to the map
                        foreach (IGeometry geom in radius1_2GeomList)
                        {
                            var color = new RgbColorClass()
                            {
                                Blue = 255
                            } as IColor;
                            AddGraphicToMap(geom, color, true);
                        }

                        IRasterLayer outputRasterLayer = new RasterLayerClass();
                        outputRasterLayer.CreateFromFilePath(outPath);

                        string fcName = IntersectOutput(outputRasterLayer, ipDataset, workspace, donutGeomList);

                        IFeatureClass finalFc = workspace.OpenFeatureClass(fcName);

                        IFeatureLayer outputFeatureLayer = new FeatureLayerClass();
                        outputFeatureLayer.FeatureClass = finalFc;

                        //Add it to a map if the layer is valid.
                        if (outputFeatureLayer != null)
                        {
                            // set the renderer
                            IFeatureRenderer featRend = UniqueValueRenderer(workspace, finalFc);
                            IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer;
                            geoLayer.Renderer = featRend;
                            geoLayer.Name     = "RLOS_Visibility_" + RunCount.ToString();

                            // Set the layer transparency
                            IDisplayFilterManager      filterManager = (IDisplayFilterManager)outputFeatureLayer;
                            ITransparencyDisplayFilter filter        = new TransparencyDisplayFilter();
                            filter.Transparency         = 80;
                            filterManager.DisplayFilter = filter;

                            ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap;
                            map.AddLayer((ILayer)outputFeatureLayer);

                            IEnvelope envelope = outputFeatureLayer.AreaOfInterest.Envelope;
                            ZoomToExtent(envelope);
                        }

                        RunCount += 1;
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                    }

                    //Reset(true);
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
            }
            finally
            {
                IsRunning = false;
            }
        }
        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
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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();
            }
        }
Exemplo n.º 24
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;
            }
        }
Exemplo n.º 25
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            IFeatureClass pInPointFClass;//   '获得输入点特征数据类

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


            if (bDataPath == true)
            {
                fileName = comboBoxInputData.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(comboBoxInputData.Text);
            }

            IFeatureLayer pFeatLayer = new FeatureLayerClass();

            pFeatLayer.FeatureClass = pInPointFClass;
            rasterPath = txtOutputPath.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;
                String           sWeight          = txtWeightValue.Text;
                if (Convert.ToDouble(sCellSize) <= 0 || sWeight == "")
                {
                    MessageBox.Show("还没输入权重值或栅格单元!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                double dCellSize  = Convert.ToDouble(sCellSize);
                double dWeight    = Convert.ToDouble(sWeight);
                String sPointNums = txtPointNum.Text;
                int    iPointNums;
                if (sPointNums != "")
                {
                    iPointNums = Convert.ToInt32(sPointNums);
                }
                else
                {
                    MessageBox.Show("还没输入点的数目!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                pInterpolationOp = SetRasterInterpolationAnalysisEnv(rasterPath, dCellSize, pFeatLayer);
                IRaster pOutRaster;
                object  w = dWeight;    //权重必须为object类型
                object  n = iPointNums; //插值点大小必须为object类型且要大于5,样条插值的基本条件
                if (comboBoxSplineType.Text == "规则样条")
                {
                    pOutRaster = (IRaster)pInterpolationOp.Spline((IGeoDataset)pFeatClsDes, esriGeoAnalysisSplineEnum.esriGeoAnalysisRegularizedSpline, ref w, ref n);
                }
                else
                {
                    pOutRaster = (IRaster)pInterpolationOp.Spline((IGeoDataset)pFeatClsDes, esriGeoAnalysisSplineEnum.esriGeoAnalysisTensionSpline, ref w, ref n);
                }

                //着色
                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);
            }
        }
Exemplo n.º 26
0
        public IRaster DensityAnalyst(IFeatureClass pFeatureClass,string pFieldName, double pCellSize, double pRadius)
        {
            //辅助对象,设置密度分析时候的参数

               IFeatureClassDescriptor pFDescr = new FeatureClassDescriptorClass();
               pFDescr.Create(pFeatureClass, null, pFieldName);

               IDensityOp pDensityOp = new RasterDensityOpClass();

               //设置环境
               IRasterAnalysisEnvironment pEnv = pDensityOp as IRasterAnalysisEnvironment;

               object object_cellSize = (System.Object)pCellSize;

               pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref object_cellSize);

               System.Double double_radio_dis = pRadius;
               object object_radio_dis = (System.Object)double_radio_dis;
               object Missing = Type.Missing;
               //核函数密度制图方法生成栅格数据
               IRaster pRaster = pDensityOp.KernelDensity(pFDescr as IGeoDataset, ref object_radio_dis, ref Missing) as IRaster;

               return pRaster;
        }
Exemplo n.º 27
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);

            //两种方法的结合后
        }
Exemplo n.º 28
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                ILayer        selectedLayer        = global.p2DMap.get_Layer(comboBox1.SelectedIndex);
                IFeatureLayer selectedFeatureLayer = selectedLayer as IFeatureLayer;
                IFeatureClass selectedFeatureClass = selectedFeatureLayer.FeatureClass;

                IRasterAnalysisEnvironment rasterEnv = new RasterDensityOp();

                double r        = Convert.ToDouble(textBox2.Text);
                object dSearchD = r;  //搜索半径

                //设置输出栅格大小
                double cellSize = Convert.ToDouble(textBox3.Text);
                // object cellSizeObj = cellSize;
                // rasterEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeObj);

                //获得图层
                ILayer layer = null;
                IMap   map   = global.p2DMap;
                for (int i = 0; i < map.LayerCount; i++)
                {
                    ILayer temp = map.Layer[i];
                    if (temp.Name == comboBox1.SelectedItem.ToString())
                    {
                        layer = temp;
                    }
                }
                IFeatureLayer fLayer = layer as IFeatureLayer;
                IFeatureClass fClass = fLayer.FeatureClass;

                //设置空间处理范围
                object extentProObj = layer;
                rasterEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProObj);
                rasterEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, 1);
                // IRasterRadius pRadius = new RasterRadiusClass();??
                // pRadius.SetVariable(pSearchCount, ref dSearchD);


                //设置要素数据
                IFeatureClassDescriptor feaDes;
                feaDes = new FeatureClassDescriptorClass();
                feaDes.Create(fClass, null, comboBox2.SelectedItem.ToString());
                IGeoDataset inGeodataset;
                inGeodataset = feaDes as IGeoDataset;


                //设置输出栅格
                //IRaster outraster;
                IGeoDataset outGeoDataset;

                IDensityOp densityOp = rasterEnv as IDensityOp;
                outGeoDataset = densityOp.KernelDensity(inGeodataset, r);//., 1);

                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);
                global.p2DMap.AddLayer(pRlayer);
                global.p3DMap.Scene.AddLayer(pRlayer);
            }

            catch { }
            this.Close();
        }
Exemplo n.º 29
0
        private void btnGO_Click(object sender, System.EventArgs e)
        {
            IFeatureClass pFClass = null;          //获得输入特征数据类

            IWorkspace pWorkspace;
            object     Missing = Type.Missing;
            string     fileName;
            string     rasterPath;
            string     shpFile;
            int        startX, endX;
            string     sFieldName;        //选择要进行分析的字段

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

            pFeatLayer.FeatureClass = pFClass;
            rasterPath = txtRasterPath.Text;
            IFeatureClassDescriptor pFeatClsDes = new FeatureClassDescriptorClass();

            if (comboBoxField.Text != "无")
            {
                pFeatClsDes.Create(pFClass, null, comboBoxField.Text);
            }
            else
            {
                pFeatClsDes.Create(pFClass, null, "");
            }
            try
            {
                IDensityOp pDensityOp = new RasterDensityOpClass();
                string     sCellSize  = txtCellSize.Text;
                double     dCellSize  = Convert.ToDouble(sCellSize);
                string     sRadius    = txtSearchRadius.Text;
                double     dRadius    = Convert.ToDouble(sRadius);
                object     objRadius  = dRadius;
                pDensityOp = Utility.SetRasterDensityAnalysisEnv(rasterPath, dCellSize, pFeatLayer);
                IRasterNeighborhood pRasNeighborhood = new RasterNeighborhoodClass();
                if (comboBoxAreaUnit.Text == "按地图单位")
                {
                    pRasNeighborhood.SetCircle(dRadius, esriGeoAnalysisUnitsEnum.esriUnitsMap);
                }
                else
                {
                    pRasNeighborhood.SetCircle(dRadius, esriGeoAnalysisUnitsEnum.esriUnitsCells);
                }
                IRaster pOutRaster = null;
                switch (pFClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    if (rdoKernel.Checked == false)
                    {
                        pOutRaster = pDensityOp.PointDensity(pFeatClsDes as IGeoDataset, pRasNeighborhood, ref Missing) as IRaster;
                    }
                    else
                    {
                        pOutRaster = pDensityOp.KernelDensity(pFeatClsDes as IGeoDataset, ref objRadius, ref Missing) as IRaster;
                    }
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (rdoKernel.Checked == false)
                    {
                        pOutRaster = pDensityOp.LineDensity(pFeatClsDes as IGeoDataset, ref objRadius, ref Missing) as IRaster;
                    }
                    else
                    {
                        pOutRaster = pDensityOp.KernelDensity(pFeatClsDes as IGeoDataset, ref objRadius, ref Missing) as IRaster;
                    }
                    break;
                }
                //着色
                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);
            }
        }
Exemplo n.º 30
0
        public static void Mlayer_Krige_Click()
        {
            // 用克里金Krige插值生成的栅格图像。如下:
               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");

               IInterpolationOp pInterpolationOp = new RasterInterpolationOpClass();
               IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;

               object Cellsize = 0.004;//Cell size for output raster;0.004
               pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref Cellsize);
               //设置输出范围
               //27202 19104;27202 22947;31550 22947;31550 19104
               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;
               pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
               Double dSearchD = 10;
               object pSearchCount = 3;
               object missing = Type.Missing;
               IRasterRadius pRadius = new RasterRadius();
               pRadius.SetFixed(dSearchD, ref pSearchCount);
               //pRadius.SetVariable((int)pSearchCount, ref dSearchD);

               IGeoDataset poutGeoDataset = pInterpolationOp.Krige((IGeoDataset)pFCDescriptor, esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisGaussianSemiVariogram, pRadius, false, ref missing);

               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();
        }
Exemplo n.º 31
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int startX, endX;
            string shpDir;
            IFeatureClass pFClass = null;
            if (bFeatDataPath == true)
            {
                fileName = comboBoxInData.Text;
                shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX = fileName.LastIndexOf("\\");
                endX = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
                pFClass = UtilityFunction.OpenFeatureClassFromShapefile(shpDir, shpFile);
            }
            else
            {
                pFClass = GetFeatureFromMapLyr(comboBoxInData.Text);
            }
            if (bRasterDataPath == true)
            {
                fileName = txtOutPath.Text;
                shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX = fileName.LastIndexOf("\\");
                endX = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);
            }
            else
            {
                shpDir = txtOutPath.Text;
                shpFile = "����תդ��";
            }
            IGeoDataset pTempDS = pFClass as IGeoDataset;
            IFeatureLayer pFeatLayer = new FeatureLayerClass();
            pFeatLayer.FeatureClass = pFClass;

            IFeatureClassDescriptor pFeatClsDes = new FeatureClassDescriptorClass();
            if (comboBoxField.Text != "��")
                pFeatClsDes.Create(pFClass, null, comboBoxField.Text);
            else
                pFeatClsDes.Create(pFClass, null, "");
            pTempDS = pFeatClsDes as IGeoDataset;
            try
            {
                IConversionOp pConversionOp = new RasterConversionOpClass();
                string sCellSize = txtCellSize.Text;
                double dCellSize = Convert.ToDouble(sCellSize);
                pConversionOp = UtilityFunction.SetFeatToRasterAnalysisEnv(shpDir, dCellSize, pFeatLayer);
                if (File.Exists(shpDir + "\\" + shpFile + ".img") == true)
                    File.Delete(shpDir + "\\" + shpFile + ".img");
                IWorkspace pWS = UtilityFunction.setRasterWorkspace(shpDir);
                IRasterDataset pRasterDs = pConversionOp.ToRasterDataset(pTempDS, "IMAGINE Image", pWS, shpFile);
                ITemporaryDataset pTempRaster = pRasterDs as ITemporaryDataset;
                if (pTempRaster.IsTemporary() == true)
                    pTempRaster.MakePermanent();
                IRaster pOutRaster = pRasterDs.CreateDefaultRaster();
                IRasterLayer pRasterLayer = UtilityFunction.SetStretchRenderer(pOutRaster);
                pMap.AddLayer(pRasterLayer);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 32
0
		private void btnGO_Click(object sender, System.EventArgs e)
		{
			IFeatureClass pFClass=null;//获得输入特征数据类
			 
			IWorkspace pWorkspace;
			object Missing = Type.Missing;	
			string fileName;
			string rasterPath;
			string shpFile;
			int startX,endX;
			string sFieldName;//选择要进行分析的字段
			if(bDataPath==true)
			{
				fileName=comboBoxInData.Text;
				string shpDir =fileName.Substring(0, fileName.LastIndexOf("\\")); 
				startX=fileName.LastIndexOf("\\");
				endX=fileName.Length;
				shpFile=fileName.Substring(startX+1,endX-startX-1);
				pFClass=Utility.OpenFeatureClassFromShapefile(shpDir,shpFile);
			}
			else
			{
				pFClass=GetFeatureFromMapLyr(comboBoxInData.Text);
			}
			IFeatureLayer pFeatLayer =new FeatureLayerClass();
			pFeatLayer.FeatureClass=pFClass;
			rasterPath=txtRasterPath.Text;
			IFeatureClassDescriptor pFeatClsDes=new FeatureClassDescriptorClass();
			if(comboBoxField.Text!="无")
				pFeatClsDes.Create(pFClass,null,comboBoxField.Text);
			else
				pFeatClsDes.Create(pFClass,null,"");
			try
			{
				 IDensityOp pDensityOp=new RasterDensityOpClass();
				string sCellSize=txtCellSize.Text ;
				double dCellSize=Convert.ToDouble(sCellSize);
				string sRadius=txtSearchRadius.Text;
				double dRadius=Convert.ToDouble(sRadius);
				object objRadius=dRadius;
				pDensityOp=Utility.SetRasterDensityAnalysisEnv(rasterPath,dCellSize,pFeatLayer);
				IRasterNeighborhood pRasNeighborhood=new RasterNeighborhoodClass();
				if(comboBoxAreaUnit.Text=="按地图单位")
					pRasNeighborhood.SetCircle(dRadius,esriGeoAnalysisUnitsEnum.esriUnitsMap);
				else
					pRasNeighborhood.SetCircle(dRadius,esriGeoAnalysisUnitsEnum.esriUnitsCells);
				IRaster pOutRaster=null;
				switch(pFClass.ShapeType)
				{
					case esriGeometryType.esriGeometryPoint:
						if(rdoKernel.Checked==false)
							pOutRaster= pDensityOp.PointDensity(pFeatClsDes as IGeoDataset,pRasNeighborhood,ref Missing) as IRaster;
						else
							pOutRaster= pDensityOp.KernelDensity(pFeatClsDes as IGeoDataset,ref objRadius,ref Missing) as IRaster;
						break;
					case esriGeometryType.esriGeometryPolyline:
						if(rdoKernel.Checked==false)
							pOutRaster= pDensityOp.LineDensity(pFeatClsDes as IGeoDataset,ref objRadius,ref Missing) as IRaster;
						else
							pOutRaster=pDensityOp.KernelDensity(pFeatClsDes as IGeoDataset,ref objRadius,ref Missing) as IRaster;
						break;
				}
				//着色                
				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);
			
			}
		
		}
Exemplo n.º 33
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;
        }
Exemplo n.º 34
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);
            }
        }
Exemplo n.º 35
0
        /// <summary>
        /// Where all of the work is done.  Override from TabBaseViewModel
        /// </summary>
        internal override void CreateMapElement()
        {
            if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                return;

            //base.CreateMapElement();

            var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

            if (surface == null)
                return;

            using (ComReleaser oComReleaser = new ComReleaser())
            {

                // Create feature workspace
                IFeatureWorkspace workspace = CreateFeatureWorkspace("tempWorkspace");

                StartEditOperation((IWorkspace)workspace);

                // Create feature class
                IFeatureClass pointFc = CreateObserversFeatureClass(workspace, "Output" + RunCount.ToString());

                double finalObserverOffset = GetOffsetInZUnits(ArcMap.Document.FocusMap, ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                double finalSurfaceOffset = GetOffsetInZUnits(ArcMap.Document.FocusMap, SurfaceOffset, surface.ZFactor, OffsetUnitType);

                double conversionFactor = GetConversionFactor(ArcMap.Document.FocusMap.SpatialReference);
                double convertedMinDistance = MinDistance * conversionFactor;
                double convertedMaxDistance = MaxDistance * conversionFactor;
                double finalMinDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, OffsetUnitType);
                double finalMaxDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, OffsetUnitType);

                double finalLeftHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, LeftHorizontalFOV, AngularUnitType);
                double finalRightHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, RightHorizontalFOV, AngularUnitType);
                double finalBottomVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, BottomVerticalFOV, AngularUnitType);
                double finalTopVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, TopVerticalFOV, AngularUnitType);

                // Out radius geometries
                List<IGeometry> radius2GeomList = new List<IGeometry>();
                List<IGeometry> radius1_2GeomList = new List<IGeometry>();
                List<IGeometry> donutGeomList = new List<IGeometry>();

                foreach (var observerPoint in ObserverAddInPoints)
                {
                    // Create buffer geometries for final Min/Max distance
                    ITopologicalOperator topologicalOperator = observerPoint.Point as ITopologicalOperator;
                    IGeometry geom = topologicalOperator.Buffer(finalMaxDistance);
                    radius2GeomList.Add(geom);
                    radius1_2GeomList.Add(geom);
                    if (finalMinDistance > 0)
                    {
                        IGeometry geom2 = topologicalOperator.Buffer(finalMinDistance);

                        ITopologicalOperator eraseTopo = geom as ITopologicalOperator;
                        IGeometry erasedGeom = eraseTopo.Difference(geom2);
                        donutGeomList.Add(erasedGeom);
                    }
                    else
                    {
                        radius1_2GeomList.Add(geom);
                    }

                    double z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                    //create a new point feature
                    IFeature ipFeature = pointFc.CreateFeature();

                    // Set the field values for the feature
                    SetFieldValues(finalObserverOffset, finalSurfaceOffset, finalMinDistance, finalMaxDistance, finalLeftHorizontalFOV,
                        finalRightHorizontalFOV, finalBottomVerticalFOV, finalTopVerticalFOV, ipFeature);

                    //Create shape
                    IPoint point = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true };
                    ipFeature.Shape = point;
                    ipFeature.Store();
                }

                IFeatureClassDescriptor fd = new FeatureClassDescriptorClass();
                fd.Create(pointFc, null, "OBJECTID");

                StopEditOperation((IWorkspace)workspace);

                try
                {
                    ILayer layer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
                    string layerPath = GetLayerPath(layer);

                IFeatureLayer ipFeatureLayer = new FeatureLayerClass();
                ipFeatureLayer.FeatureClass = pointFc;

                IDataset ipDataset = (IDataset)pointFc;
                string outputFcName = ipDataset.BrowseName + "_output";
                string strPath = ipDataset.Workspace.PathName + "\\" + ipDataset.BrowseName;
                string outPath = ipDataset.Workspace.PathName + "\\" + outputFcName;

                IVariantArray parameters = new VarArrayClass();
                    parameters.Add(layerPath);
                parameters.Add(strPath);
                parameters.Add(outPath);

                    esriLicenseStatus status = GetSpatialAnalystLicense();

                    IGeoProcessor2 gp = new GeoProcessorClass();

                    gp.AddOutputsToMap = false;

                    // Add a mask to buffer the output to selected distance
                    SetGPMask(workspace, radius2GeomList, gp, "radiusMask");

                    object oResult = gp.Execute("Visibility_sa", parameters, null);
                    IGeoProcessorResult ipResult = (IGeoProcessorResult)oResult;

                    ComReleaser.ReleaseCOMObject(gp);
                    gp = null;
                    GC.Collect();

                    // Add buffer geometries to the map
                    foreach (IGeometry geom in radius1_2GeomList)
                    {
                        var color = new RgbColorClass() { Blue = 255 } as IColor;
                        AddGraphicToMap(geom, color, true);
                    }

                    IRasterLayer outputRasterLayer = new RasterLayerClass();
                    outputRasterLayer.CreateFromFilePath(outPath);

                    string fcName = IntersectOutput(outputRasterLayer, ipDataset, workspace, donutGeomList);

                    IFeatureClass finalFc = workspace.OpenFeatureClass(fcName);

                    IFeatureLayer outputFeatureLayer = new FeatureLayerClass();
                    outputFeatureLayer.FeatureClass = finalFc;

                    //Add it to a map if the layer is valid.
                    if (outputFeatureLayer != null)
                    {
                        // set the renderer
                        IFeatureRenderer featRend = UnqueValueRenderer(workspace, finalFc);
                        IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer;
                        geoLayer.Renderer = featRend;
                        geoLayer.Name = "VisibilityLayer_" + RunCount.ToString();

                        // Set the layer transparency
                        IDisplayFilterManager filterManager = (IDisplayFilterManager)outputFeatureLayer;
                        ITransparencyDisplayFilter filter = new TransparencyDisplayFilter();
             			            filter.Transparency = 80;
             			            filterManager.DisplayFilter = filter;

                        ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap;
                        map.AddLayer((ILayer)outputFeatureLayer);
                    }

                    RunCount += 1;
                }
                catch (Exception ex)
                {
                    string exception = ex.ToString();
                    System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                }

                //Reset(true);
            }
        }
Exemplo n.º 36
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);
        }
        /// <summary>
        /// return operation watershed handler
        /// </summary>
        /// <param name="boundVariables">>bound Variables</param>
        /// <param name="operationInput">operation Input</param>
        /// <param name="outputFormat">output Format</param>
        /// <param name="requestProperties">request Properties</param>
        /// <param name="responseProperties">response Properties</param>
        /// <returns>operation watershed handler</returns>
        private byte[] OperationWatershedHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            long?idWatershed;

            if (operationInput.Exists("idWatershed"))
            {
                if (!operationInput.TryGetAsLong("idWatershed", out idWatershed))
                {
                    throw new ArgumentNullException("idWatershed");
                }
            }
            else
            {
                idWatershed = 0;
            }

            JsonObject jsonObjectPoint;

            if (!operationInput.TryGetJsonObject("location", out jsonObjectPoint))
            {
                throw new ArgumentNullException("location");
            }

            IPoint location = Conversion.ToGeometry(jsonObjectPoint, esriGeometryType.esriGeometryPoint) as IPoint;

            if (location == null)
            {
                throw new ArgumentException("Invalid location", "location");
            }

            double?snapDistance;

            if (!operationInput.TryGetAsDouble("snapDistance", out snapDistance))
            {
                throw new ArgumentNullException("snapDistance");
            }

            snapDistance = snapDistance ?? 0.0;

            long?idAccumulation;

            if (!operationInput.TryGetAsLong("idAccumulation", out idAccumulation) || !idAccumulation.HasValue)
            {
                throw new ArgumentNullException("idAccumulation");
            }

            long?idDirection;

            if (!operationInput.TryGetAsLong("idDirection", out idDirection) || !idDirection.HasValue)
            {
                throw new ArgumentNullException("idDirection");
            }

            string methodName = MethodBase.GetCurrentMethod().Name;

            try
            {
                IFeatureWorkspace featureWorkspace = Helper.CreateInMemoryWorkspace() as IFeatureWorkspace;
                IFeatureClass     featureClass     = this.CreateFeatureClass(location, featureWorkspace);

                IFeature feature = featureClass.CreateFeature();
                feature.Shape = location;
                feature.set_Value(featureClass.FindField(SAUtility.FieldNameIdWatershed), (int)idWatershed.Value);
                feature.Store();

                IHydrologyOp hydrologyOp = new RasterHydrologyOp() as IHydrologyOp;

                IGeoDataset accumulation = this.GetGeodataset((int)idAccumulation.Value);
                IGeoDataset direction    = this.GetGeodataset((int)idDirection.Value);

                IFeatureClassDescriptor featureClassDescriptor = new FeatureClassDescriptorClass();
                featureClassDescriptor.Create(featureClass, null, SAUtility.FieldNameIdWatershed);
                IGeoDataset pourPoint = featureClassDescriptor as IGeoDataset;

                IRasterAnalysisEnvironment rasterAnalysisEnvironment = new RasterAnalysisClass();
                object extentProvider = Type.Missing;
                object snapRasterData = Type.Missing;
                rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvMaxOf, ref extentProvider, ref snapRasterData);

                IGeoDataset snapRaster = hydrologyOp.SnapPourPoint(pourPoint, accumulation, snapDistance.Value);

                IGeoDataset watershed = hydrologyOp.Watershed(direction, snapRaster);

                IConversionOp conversionOp          = new RasterConversionOpClass() as IConversionOp;
                IGeoDataset   featureClassWatershed = conversionOp.RasterDataToPolygonFeatureData(watershed, featureWorkspace as IWorkspace, "WatershedPolygon", true);

                IRecordSetInit recordset = new RecordSetClass();
                recordset.SetSourceTable(featureClassWatershed as ITable, null);

                byte[] recorset = Conversion.ToJson(recordset as IRecordSet);
                this.logger.LogMessage(ServerLogger.msgType.infoDetailed, methodName, SAUtility.MessageCodeSOE, string.Format("Watershed created with succcess. IdWatershed {0}", (int)idWatershed.Value));
                return(recorset);
            }
            catch (Exception ex)
            {
                this.logger.LogMessage(ServerLogger.msgType.error, methodName, SAUtility.MessageCodeSOE, ex.Message);
                return(new ObjectError("error create watershed").ToJsonObject().JsonByte());
            }
        }
Exemplo n.º 38
0
        static void CreateGrid(TileInfo tiles, int level, IFeatureWorkspace destination, String name)
        {
            ISpatialReferenceFactory2 sEnv = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2;
            ISpatialReference sr = sEnv.CreateSpatialReference((int)tiles.spatialReference);
            sr.SetMDomain(-137434824702, 0);
            IFeatureClass fc = CreateFeatureClass(destination, name, sr);
            LOD lod = tiles.lods[level];
            double width = tiles.width * lod.resolution;
            double height = tiles.height * lod.resolution;
            double y = tiles.originY;
            long row = 0;
            double maxX = -(tiles.originX + width);
            double minY = -(tiles.originY - height);
            while (y > minY)
            {
                double x = tiles.originX;
                long col = 0;
                while (x < maxX)
                {
                    RingClass ring = new RingClass();
                    IPoint tl = new PointClass();
                    tl.PutCoords(x, y);
                    tl.M = -(((col & 0xFFFF) << 16) + (row & 0xFFFF));
                    ring.AddPoint(tl);
                    IPoint tr = new PointClass();
                    tr.PutCoords(x + width, y);
                    tr.M = -((((col + 1) & 0xFFFF) << 16) + (row & 0xFFFF));
                    ring.AddPoint(tr);
                    IPoint br = new PointClass();
                    br.PutCoords(x + width, y - width);
                    br.M = -((((col + 1) & 0xFFFF) << 16) + ((row + 1) & 0xFFFF));
                    ring.AddPoint(br);
                    IPoint bl = new PointClass();
                    bl.PutCoords(x, y - width);
                    bl.M = -(((col & 0xFFFF) << 16) + ((row + 1) & 0xFFFF));
                    ring.AddPoint(bl);

                    ring.AddPoint(tl);

                    ring.Close();
                    PolygonClass polygon = new PolygonClass();
                    polygon.AddGeometry(ring);
                    IFeature polyFeature = fc.CreateFeature();
                    polyFeature.Shape = polygon;
                    polyFeature.Store();
                    x += width;
                    col += 1;
                }
                row += 1;
                y -= height;
            }
            IFeatureClassDescriptor fd = new FeatureClassDescriptorClass();
            fd.Create(fc, null, "OBJECTID");
        }
Exemplo n.º 39
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            IFeatureClass pInPointFClass;//   '获得输入点特征数据类

            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);
            }

            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;

                if (Convert.ToDouble(sCellSize) <= 0)
                {
                    MessageBox.Show("还没输入栅格单元!请输入后在进行插值。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                double dCellSize = Convert.ToDouble(sCellSize);

                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;
                            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;
                            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);

                esriGeoAnalysisSemiVariogramEnum semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisNoneVariogram;
                if (RadioOrdinary.Checked)
                {
                    switch (ComboBoxMethod.SelectedIndex)
                    {
                    case 0:
                        semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisSphericalSemiVariogram;
                        break;

                    case 1:
                        semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisCircularSemiVariogram;
                        break;

                    case 2:
                        semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisExponentialSemiVariogram;
                        break;

                    case 3:
                        semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisGaussianSemiVariogram;
                        break;
                    }
                }
                else
                {
                    switch (ComboBoxMethod.SelectedIndex)
                    {
                    case 0:
                        semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisUniversal1SemiVariogram;
                        break;

                    case 1:
                        semi = esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisUniversal2SemiVariogram;
                        break;
                    }
                }
                IRaster pOutRaster;
                object  barrier = null;

                pOutRaster = (IRaster)pInterpolationOp.Krige((IGeoDataset)pFeatClsDes, semi, pRsRadius, true, ref barrier);
                //着色
                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);
            }
        }
Exemplo n.º 40
0
        /// <summary>
        /// Runs the selected density operations on the input feature class.
        /// </summary>
        /// <param name="pFC"></param>
        /// <returns></returns>
        private IRaster Density(IFeatureClass pFC)
        {
            IRaster pRaster = null;

            try
            {
                IDensityOp pDensityOp = new RasterDensityOpClass();

                //create a feature class descriptor to specify a field
                IFeatureClassDescriptor pFCD = new FeatureClassDescriptorClass();
                if (m_sField != "None")
                {
                    pFCD.Create(pFC, null, m_sField);
                }
                else
                {
                    pFCD.Create(pFC, null, null);
                }


                //run the density op
                //set the output resolution

                //make sure this scale factor is always in right units.
                object oScaleFactor = 1;
                switch (m_sDensityUnits + m_sMapUnits)
                {
                case "per square km" + "Meter":
                    oScaleFactor = 1000;
                    break;

                case "per square mile" + "Meter":
                    oScaleFactor = 1609.344;
                    break;

                case "per square mile" + "Foot_US":
                case "per square mile" + "Foot":
                    oScaleFactor = 5280;
                    break;

                case "per square km" + "Foot_US":
                case "per square km" + "Foot":
                    oScaleFactor = 3280.84;
                    break;

                case "per square nm" + "Meter":
                    oScaleFactor = 1852;
                    break;

                case "per square nm" + "Foot_US":
                case "per square nm" + "Foot":
                    oScaleFactor = 6076.12;
                    break;
                }

                object oRadius = m_dRadius;

                IGeoDataset pOutRaster = null;

                if (m_sDensityType == "Kernel")
                {
                    pOutRaster = pDensityOp.KernelDensity((IGeoDataset)pFCD, ref oRadius, ref oScaleFactor);
                }
                else
                {
                    esriGeometryType thisType = pFC.ShapeType;
                    if (thisType == esriGeometryType.esriGeometryPolyline)
                    {
                        pOutRaster = pDensityOp.LineDensity((IGeoDataset)pFCD, ref oRadius, ref oScaleFactor);
                    }
                    else if (thisType == esriGeometryType.esriGeometryPoint)
                    {
                        IRasterNeighborhood pNbr = new RasterNeighborhoodClass();

                        if (m_sRadiusType == "Cells")
                        {
                            pNbr.SetCircle(m_dRadius, esriGeoAnalysisUnitsEnum.esriUnitsCells);
                        }
                        else
                        {
                            pNbr.SetCircle(m_dRadius, esriGeoAnalysisUnitsEnum.esriUnitsMap);
                        }

                        pOutRaster = pDensityOp.PointDensity((IGeoDataset)pFCD, pNbr, ref oScaleFactor); //ref oCellSize);
                    }
                }
                pRaster = (IRaster)pOutRaster;

                //check output spatial reference
                IRasterProps pRProps = (IRasterProps)pRaster;
                pRProps.SpatialReference = m_pLayerSR;


                //save the raster to disk
                IWorkspace pOutWS  = clsStatic.OpenWorkspace(m_sOutPath);
                ISaveAs    pSaveAs = (ISaveAs)pRaster;
                if (pSaveAs.CanSaveAs("GRID") == true)
                {
                    pSaveAs.SaveAs(pFC.AliasName + "_" + m_sOutName, pOutWS, "GRID");
                }

                IMap pMap = ArcMap.Document.FocusMap;

                //calculate raster stats
                IRasterDataset pRDS = clsStatic.OpenRasterDataset(m_sOutPath, pFC.AliasName + "_" + m_sOutName);
                CalcStats(pRDS);

                //add the layer to the map
                IRasterLayer pRL   = clsStatic.RasterDataset2RasterLayer(m_sOutPath, pFC.AliasName + "_" + m_sOutName, false, pMap);
                IRgbColor    pRGB1 = new RgbColorClass();
                IRgbColor    pRGB2 = new RgbColorClass();
                pRGB2.Blue  = 0;
                pRGB2.Green = 0;
                pRGB2.Red   = 255;
                pRGB1.Blue  = 255;
                pRGB1.Green = 0;
                pRGB1.Red   = 0;
                //pRL.CreateFromRaster(pRaster);
                CreateRasterStretchRenderer(pRL, pRGB1, pRGB2);

                pMap.AddLayer(pRL);

                return(pRaster);
            }
            catch (Exception ex)
            {
                clsStatic.ShowErrorMessage(ex.ToString());
            }
            return(pRaster);
        }
Exemplo n.º 41
0
        public void kriging(IFeatureClass pFeatureClass)
        {
            //  FeatureClassDescriptor 对象用于控制和描述插值的参数

             IFeatureClassDescriptor pFDescr = new FeatureClassDescriptorClass();
             pFDescr.Create(pFeatureClass, null, "Ozone");

             // 栅格半径辅助对象用于控制插值的参数
             IRasterRadius pRasRadius = new RasterRadiusClass();
             object object_Missing = System.Type.Missing;

             pRasRadius.SetVariable(12, ref object_Missing);

             IInterpolationOp pInterpOp = new RasterInterpolationOpClass();

             IRaster pRasterOut = (IRaster)pInterpOp.Krige((IGeoDataset)pFDescr,
                 esriGeoAnalysisSemiVariogramEnum.esriGeoAnalysisExponentialSemiVariogram,
                 pRasRadius, false, ref object_Missing);
        }
Exemplo n.º 42
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);
            }
        }