Exemplo n.º 1
0
        //获取某个位置相对于栅格位置的坐标
        public RasterPositionValue Coordinate(IPoint point)
        {
            IRasterProps rasterProps = (IRasterProps)GetRaster();

            if (!Contains(rasterProps.Extent.Envelope, point))
            {
                return(null);
            }
            int    xIndex           = (int)((point.X - rasterProps.Extent.XMin) / rasterProps.MeanCellSize().X);
            int    yIndex           = (int)((rasterProps.Extent.YMax - point.Y) / rasterProps.MeanCellSize().Y);
            object readValue        = Read(xIndex, yIndex);
            RasterPositionValue res = new RasterPositionValue()
            {
                XIndex = xIndex, YIndex = yIndex
            };

            if (readValue != null)
            {
                res.HasValue    = true;
                res.RasterValue = Convert.ToSingle(readValue);
            }
            else
            {
                res.HasValue    = false;
                res.RasterValue = -1;
            }
            return(res);
        }
Exemplo n.º 2
0
        private void SetMeanCellSize()
        {
            if (chkSocCellSize.Checked)
            {
                IRasterBandCollection rasterBands = m_pRaster.RasterDataset as IRasterBandCollection;
                if (rasterBands.Count < 1)
                {
                    return;
                }
                IRasterProps props = rasterBands.Item(0) as IRasterProps;

                //更改分辨率首先要修改图层范围
                if (SetLayerExtent(props.MeanCellSize().X, props.MeanCellSize().Y))
                {
                    txtCellSizeX.Text = props.MeanCellSize().X.ToString();
                    txtCellSizeY.Text = props.MeanCellSize().Y.ToString();
                }
            }
            else
            {
                if (SetLayerExtent(m_pRasterProps.MeanCellSize().X, m_pRasterProps.MeanCellSize().Y))
                {
                    txtCellSizeX.Text = m_pRasterProps.MeanCellSize().X.ToString();
                    txtCellSizeY.Text = m_pRasterProps.MeanCellSize().Y.ToString();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取该栅格图像的相关数据
        /// <remarks>
        /// <list type="bullet">
        /// <item>
        /// <term>
        /// 初始化_pDataset
        /// </term>
        /// <item>
        /// 获取栅格的Height和Width
        /// </item>
        /// </item>
        /// </list>
        /// </remarks>
        /// </summary>
        /// <returns></returns>
        private void Open()
        {
            //Open
            IWorkspaceFactory pRFactory       = new RasterWorkspaceFactoryClass();
            IRasterWorkspace2 rasterWorkspace = pRFactory.OpenFromFile(_rasterWorkSapce, 0) as IRasterWorkspace2;

            if (rasterWorkspace == null)
            {
                throw new ArgumentException("栅格文件无法打开");
            }
            _pDataset = rasterWorkspace.OpenRasterDataset(_rasterName);
            //set height and width

            IRasterProps pRasterProps = (IRasterProps)GetRaster();

            RasterInfo = new RasterInformation()
            {
                Width       = pRasterProps.Width,
                Height      = pRasterProps.Height,
                XCellSize   = pRasterProps.MeanCellSize().X,
                YCellSize   = pRasterProps.MeanCellSize().Y,
                OriginPoint = new PointClass()
                {
                    X = pRasterProps.Extent.XMin, Y = pRasterProps.Extent.YMin
                },
                SpatialReference = ((IGeoDataset)_pDataset).SpatialReference
            };
        }
Exemplo n.º 4
0
        /// <summary>
        /// 该函数获得栅格影像分辨率大小
        /// </summary>
        /// <param name="sLayerName"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private double GetRasterCellSize(string sLayerName)
        {
            double       dCellSize   = 0;
            int          i           = 0;
            ILayer       pLyr        = default(ILayer);
            IRasterLayer pRlyr       = default(IRasterLayer);
            IRaster      pRaster     = default(IRaster);
            IRasterProps pRasterProp = default(IRasterProps);
            double       cellX;
            double       cellY;

            for (i = 0; i <= pCurMap.LayerCount - 1; i++)
            {
                pLyr = pCurMap.get_Layer(i);
                if ((pLyr != null))
                {
                    if (pLyr is IRasterLayer)
                    {
                        if (pLyr.Name == sLayerName)
                        {
                            pRlyr       = (IRasterLayer)pLyr;
                            pRaster     = pRlyr.Raster;
                            pRasterProp = (IRasterProps)pRaster;
                            cellX       = pRasterProp.MeanCellSize().X;
                            cellY       = pRasterProp.MeanCellSize().Y;

                            dCellSize = (cellX + cellY) / 2.0;
                        }
                    }
                }
            }
            return(dCellSize);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 栅格分块
        /// </summary>
        /// <param name="pRasterDataset"></param>
        /// <param name="pOutputWorkspace"></param>
        /// <param name="pWidth"></param>
        /// <param name="pHeight"></param>
        public static void CreateTilesFromRasterDataset(IRasterDataset pRasterDataset, IWorkspace pOutputWorkspace, int pWidth, int pHeight)
        {
            IRasterProps pRasterProps = (IRasterProps)pRasterDataset.CreateDefaultRaster();// cast IRaster to IRasterProps
            double       xTileSize    = pRasterProps.MeanCellSize().X *pWidth;
            double       yTileSize    = pRasterProps.MeanCellSize().Y *pHeight;


            int xTileCount = (int)Math.Ceiling((double)pRasterProps.Width / pWidth);
            int yTileCount = (int)Math.Ceiling((double)pRasterProps.Height / pHeight);

            IEnvelope pExtent     = pRasterProps.Extent;
            IEnvelope pTileExtent = new EnvelopeClass();
            ISaveAs   pSaveAs     = null;

            for (int i = 0; i < xTileCount; i++)
            {
                for (int j = 0; j < yTileCount; j++)
                {
                    pRasterProps = (IRasterProps)pRasterDataset.CreateDefaultRaster();

                    pTileExtent.XMin = pExtent.XMin + i * xTileSize;
                    pTileExtent.XMax = pTileExtent.XMin + xTileSize;
                    pTileExtent.YMin = pExtent.YMin + j * yTileSize;
                    pTileExtent.YMax = pTileExtent.YMin + yTileSize;


                    pRasterProps.Height = pHeight;
                    pRasterProps.Width  = pWidth;

                    pRasterProps.Extent = pTileExtent;
                    pSaveAs             = (ISaveAs)pRasterProps;
                    pSaveAs.SaveAs("tile_" + i + "_" + j + ".tif", pOutputWorkspace, "TIFF");
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取像元大小最小(分辨率最高)的栅格
        /// </summary>
        /// <param name="inRasters">输入栅格集合</param>
        /// <returns></returns>
        public static IRaster GetMinCellSizeRaster(IList <IRaster> inRasters)
        {
            if (inRasters.Count == 0)
            {
                return(null);
            }
            IRasterProps rasterProps = (IRasterProps)inRasters[0];

            rasterProps.SpatialReference = SpatialReferenceClass.GetRasterProjectedReference(inRasters[0]); //转换为投影坐标系
            double minSize  = (rasterProps.MeanCellSize().X + rasterProps.MeanCellSize().Y) / 2.0;          //栅格的平均像元大小
            int    minIndex = 0;

            for (int i = 1; i < inRasters.Count; i++)
            {
                rasterProps = (IRasterProps)inRasters[i];
                rasterProps.SpatialReference = SpatialReferenceClass.GetRasterProjectedReference(inRasters[i]);
                double cellSize = (rasterProps.MeanCellSize().X + rasterProps.MeanCellSize().Y) / 2.0;
                if (cellSize < minSize)
                {
                    minIndex = i;
                }
            }

            return(inRasters[minIndex]);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取像元面积(单位:平方米,保留5位小数)
        /// </summary>
        /// <param name="raster">栅格</param>
        /// <returns></returns>
        public static double GetCellArea(IRaster raster)
        {
            IRasterProps rasterProps = (IRasterProps)raster;

            rasterProps.SpatialReference = SpatialReferenceClass.GetRasterProjectedReference(raster);
            double sizeX = rasterProps.MeanCellSize().X;
            double sizeY = rasterProps.MeanCellSize().Y;

            return(Math.Round(sizeX * sizeY, 5));
        }
Exemplo n.º 8
0
        //获取最大最小栅格值
        private void SetMaxMinValue(int flag)
        {
            if (flag == 1)
            {
                textBoxMax.Text = "高:255";
                textBoxMin.Text = "低:0";
                return;
            }
            uint valueMax = 50;
            uint valueMin = 50;

            IRasterLayer pRasterLayer = m_layer as IRasterLayer;
            IRaster      pRaster      = pRasterLayer.Raster;
            IRasterProps pRasterProps = pRaster as IRasterProps;
            int          Height       = pRasterProps.Height;
            int          Width        = pRasterProps.Width;
            double       dX           = pRasterProps.MeanCellSize().X;
            double       dY           = pRasterProps.MeanCellSize().Y; //栅格的高度
            IEnvelope    extent       = pRasterProps.Extent;           //当前栅格数据集的范围
            rstPixelType pixelType    = pRasterProps.PixelType;        //当前栅格像素类型
            IPnt         pntSize      = new PntClass();

            pntSize.SetCoords(dX, dY);


            IPixelBlock pixelBlock = pRaster.CreatePixelBlock(pntSize);
            IPnt        pnt        = new PntClass();

            for (int i = 0; i < Height; i += 10)
            {
                for (int j = 0; j < Width; j += 10)
                {
                    pnt.SetCoords(i, j);
                    pRaster.Read(pnt, pixelBlock);
                    if (pixelBlock != null)
                    {
                        object obj  = pixelBlock.GetVal(0, 0, 0);
                        uint   temp = Convert.ToUInt32(obj);

                        if (temp > valueMax)
                        {
                            valueMax = temp;
                        }
                        else if (temp < valueMin)
                        {
                            valueMin = temp;
                        }
                    }
                }
            }
            textBoxMax.Text = "高:" + valueMax.ToString();
            textBoxMin.Text = "低:" + valueMin.ToString();
        }
Exemplo n.º 9
0
        public void GetRasterProps(IRasterDataset pRaster)
        {
            //IRasterProps pRasterPros = pRaster as IRasterProps;

            //int pH = pRasterPros.Height;//3973

            //int pW = pRasterPros.Width;//5629
            IRasterProps rasterProps = (IRasterProps)pRaster;

            cumRaster.dHeight = rasterProps.Height;           //当前栅格数据集的行数
            cumRaster.dWidth  = rasterProps.Width;            //当前栅格数据集的列数
            cumRaster.dx      = rasterProps.MeanCellSize().X; //栅格的宽度
            cumRaster.dy      = rasterProps.MeanCellSize().Y; //栅格的高度
            cumRaster.extent  = rasterProps.Extent;           //当前栅格数据集的范围
        }
Exemplo n.º 10
0
        //public IFeatureClass createPolygons3()
        //{
        //    createFeatureClass();

        //}
        public IFeatureClass createPolygons2()
        {
            createFeatureClass();
            IRasterProps           rsProp   = (IRasterProps)inputRaster;
            int                    bndCnt   = ((IRasterBandCollection)inputRaster).Count;
            IPnt                   rsPnt    = rsProp.MeanCellSize();
            double                 cellArea = rsPnt.X * rsPnt.Y;
            double                 tCells   = minArea / cellArea;
            IFunctionRasterDataset sDset    = rsUtil.createMeanShiftFuction(inputRaster, (int)tCells);

            FunctionRasters.meanShiftFunctionDataset rFunc = (FunctionRasters.meanShiftFunctionDataset)sDset.Function;
            IRaster2               rs2   = (IRaster2)rsUtil.createRaster(sDset);
            IRasterCursor          rsCur = rs2.CreateCursorEx(null);
            IRasterDomainExtractor dExt  = new RasterDomainExtractorClass();

            do
            {
                IPixelBlock            pb     = rsCur.PixelBlock;
                IFunctionRasterDataset pbDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, sDset);
                IRaster rs          = rsUtil.createRaster(pbDset);
                int     numClusters = rFunc.NumClusters;
                for (int c = 0; c < numClusters; c++)
                {
                    IFunctionRasterDataset fd  = rsUtil.calcEqualFunction(pbDset, c);
                    IFunctionRasterDataset fd2 = rsUtil.setNullValue(fd, 0);
                    IPolygon polys             = dExt.ExtractDomain(rsUtil.createRaster(fd2), true);
                }
            } while (rsCur.Next() == true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur);



            return(outftr);
        }
 /// <summary>
 /// Called when the user clicks a command.
 /// </summary>
 /// <remarks>Note to inheritors: override OnClick and use this method to
 ///             perform the actual work of the custom command.</remarks>
 public override void OnClick()
 {
     if (this.m_rasterLayer != null)
     {
         //Logger logger = new Logger();
         try
         {
             if (this.m_hookHelper.FocusMap.SpatialReference != null && !(this.m_hookHelper.FocusMap.SpatialReference is IUnknownCoordinateSystem))
             {
                 double mapScale = this.m_hookHelper.FocusMap.MapScale;
                 double num      = MapAPI.ConvertPixelsToMapUnits(this.m_hookHelper.FocusMap as IActiveView, (this.m_rasterLayer.Raster as IGeoDataset).SpatialReference, 1.0, false);
                 if (num != 0.0)
                 {
                     IRasterProps rasterProps = this.m_rasterLayer.Raster as IRasterProps;
                     double       x           = rasterProps.MeanCellSize().X;
                     double       mapScale2   = mapScale * x / num;
                     (this.m_hookHelper.FocusMap as IActiveView).Extent = this.m_rasterLayer.AreaOfInterest;
                     this.m_hookHelper.FocusMap.MapScale = mapScale2;
                     this.m_hookHelper.ActiveView.Refresh();
                     //logger.Log(LogLevel.Info, EventType.UserManagement, AppMessage.MSG0106, null);
                 }
             }
         }
         catch (Exception ex)
         {
             //logger.Log(LogLevel.Error, EventType.UserManagement, AppMessage.MSG0106, ex);
             Log.WriteLog(typeof(CmdZoomToRasterResolution), ex);
         }
     }
 }
Exemplo n.º 12
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.º 13
0
        /// <summary>
        /// 根据mapcontrol绘制的多边形在样本表格中生成样本
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BegineCreateSample(IGeometry SampleGeometry)
        {
            IPolygon polygon = (IPolygon)SampleGeometry;

            if (SampleLayerCombox.Tag != null)
            {
                //计算像元数
                IArea        area        = polygon as IArea;
                IGeoDataset  geodataset  = SampleLayerCombox.Tag as IGeoDataset;
                IRaster      raster      = geodataset as IRaster;
                IRasterProps rasterprops = raster as IRasterProps;
                double       pixelcount  = System.Math.Abs(area.Area) / (rasterprops.MeanCellSize().X *rasterprops.MeanCellSize().Y);

                //生成表格
                if (SC_dataGridView.ColumnCount == 0)
                {
                    SC_dataGridView.Columns.Add("ID", "ID");
                    SC_dataGridView.Columns.Add("name", "样本名称");
                    SC_dataGridView.Columns.Add("value", "样本值");
                    SC_dataGridView.Columns.Add("color", "样本颜色");
                    SC_dataGridView.Columns.Add("count", "像元数(近似值)");
                }
                SC_dataGridView.Rows.Add();
                SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["ID"].Value    = SC_dataGridView.Rows.Count;
                SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["name"].Value  = "样本" + (SC_dataGridView.Rows.Count).ToString();
                SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["value"].Value = (SC_dataGridView.Rows.Count).ToString();
                SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["count"].Value = Convert.ToInt32(pixelcount) + 1;

                //生成随机色
                Random random    = new Random();
                Color  linecolor = new Color();
                linecolor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
                //填充单元格颜色
                SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["color"].Style.BackColor = linecolor;
                //将polygon存放到gridview表color列对应的tag中
                SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["color"].Tag = polygon;

                //新建绘制图形的填充符号
                IRgbColor arccolor = new RgbColorClass();
                arccolor.RGB = linecolor.B * 65536 + linecolor.G * 256 + linecolor.R;
                ILineSymbol outline = new SimpleLineSymbolClass();
                outline.Width = 3;
                outline.Color = arccolor;
                IFillSymbol       fillsymbol = new SimpleFillSymbolClass();
                ISimpleFillSymbol pFillsyl   = fillsymbol as ISimpleFillSymbol;
                pFillsyl.Style     = esriSimpleFillStyle.esriSFSNull;
                fillsymbol.Outline = outline;

                IPolygonElement PolygonElement = new PolygonElementClass();
                IElement        pElement       = PolygonElement as IElement;
                pElement.Geometry = SampleGeometry;

                IFillShapeElement FillShapeElement = pElement as IFillShapeElement;
                FillShapeElement.Symbol = fillsymbol;
                IGraphicsContainer pGraphicsContainer = main.getMapControl().Map as IGraphicsContainer;
                pGraphicsContainer.AddElement((IElement)PolygonElement, 0);
                main.getMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }
Exemplo n.º 14
0
        public static void exportRasterData(string parth, IRasterLayer rasterLayer, float[,] rasterMat)   //输出栅格数据
        {
            string            directory        = parth.Substring(0, parth.LastIndexOf("\\"));
            string            name             = parth.Substring(parth.LastIndexOf("\\") + 1);
            IWorkspaceFactory workspaceFac     = new RasterWorkspaceFactoryClass();
            IRasterWorkspace2 rasterWorkspace2 = workspaceFac.OpenFromFile(directory, 0) as IRasterWorkspace2;

            IRasterInfo rasterInfo  = (rasterLayer.Raster as IRawBlocks).RasterInfo;
            IPoint      originPoint = new Point();

            originPoint.PutCoords(rasterInfo.Origin.X, rasterInfo.Origin.Y - (rasterLayer.Raster as IRasterProps).Height * (rasterLayer.Raster as IRasterProps).MeanCellSize().Y);
            IRasterProps   rasterProps   = rasterLayer.Raster as IRasterProps;
            IRasterDataset rasterDataSet = rasterWorkspace2.CreateRasterDataset(name, "IMAGINE Image", originPoint, rasterProps.Width, rasterProps.Height,
                                                                                rasterProps.MeanCellSize().X, rasterProps.MeanCellSize().Y, 1, rstPixelType.PT_FLOAT, rasterProps.SpatialReference, true) as IRasterDataset2;

            IRaster2 raster2 = rasterDataSet.CreateDefaultRaster() as IRaster2;

            IPnt pntClass = new Pnt();

            pntClass.X = rasterProps.Width;
            pntClass.Y = rasterProps.Height;
            IRasterCursor rasterCursor   = raster2.CreateCursorEx(pntClass);
            IRasterCursor inRasterCursor = (rasterLayer.Raster as IRaster2).CreateCursorEx(pntClass);

            IRasterEdit rasterEdit = raster2 as IRasterEdit;

            if (rasterEdit.CanEdit())
            {
                IPixelBlock3 pixelBlock3   = rasterCursor.PixelBlock as IPixelBlock3;
                IPixelBlock3 inPixelBlock3 = inRasterCursor.PixelBlock as IPixelBlock3;
                System.Array pixels        = (System.Array)rasterMat;
                pixelBlock3.set_PixelData(0, (System.Array)pixels);
                rasterEdit.Write(rasterCursor.TopLeft, (IPixelBlock)pixelBlock3);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pixelBlock3);
            }
            rasterEdit.Refresh();
            IGeoDataset   inDataset   = rasterLayer.Raster as IGeoDataset;
            IGeoDataset   outDataset  = rasterDataSet as IGeoDataset;
            IExtractionOp op          = new RasterExtractionOpClass();
            var           outDataset1 = op.Raster(outDataset, inDataset);
            var           clipRaster  = (IRaster)outDataset1;
            ISaveAs       pSaveAs     = clipRaster as ISaveAs;

            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterCursor);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(raster2);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterDataSet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterWorkspace2);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceFac);
            if (File.Exists(parth))
            {
                File.Delete(parth);
            }
            workspaceFac = new RasterWorkspaceFactoryClass();
            IDataset outdataset = pSaveAs.SaveAs(name, workspaceFac.OpenFromFile(directory, 0), "IMAGINE Image");

            System.Runtime.InteropServices.Marshal.ReleaseComObject(outdataset);
            return;
        }
Exemplo n.º 15
0
        private Pt2d getProjectBackwardPoint(IPoint pGeoCoords, IRaster pDemRaster, ClsGetCameraView pGetCameraView,
                                             Matrix pRotateMatrix, ClsCameraPara cameraPara)
        {
            Pt3d ptFeaturePoint = new Pt3d();

            ptFeaturePoint.X = pGeoCoords.X;
            ptFeaturePoint.Y = pGeoCoords.Y;

            //从DEM上得到相应高程
            IRasterProps pDemRasterProps = pDemRaster as IRasterProps;
            double       nGeoRange       = pDemRasterProps.MeanCellSize().X * 10;
            Pt2i         ptLeftTop       = new Pt2i();

            double[,] dbSubData = pGetCameraView.getSubDem(pDemRaster, ptFeaturePoint, nGeoRange, ref ptLeftTop);
            if (dbSubData == null)
            {
                return(null);
            }

            if (pGetCameraView.GetGeoZ(pDemRaster, dbSubData, ptLeftTop, ptFeaturePoint.X, ptFeaturePoint.Y, ref ptFeaturePoint.Z))
            {
                Pt2d pt2d = new Pt2d();

                double dbX, dbY, dbZ;
                Pt3d   ptCurrentFeaturePoint = ptFeaturePoint;

                //判断是否在视场前方
                if (!IsInCameraFrontArea(ptCurrentFeaturePoint, pRotateMatrix, cameraPara))
                {
                    return(null);
                }

                dbX = pRotateMatrix.getNum(0, 0) * (ptCurrentFeaturePoint.X - cameraPara.dX) + pRotateMatrix.getNum(1, 0) * (ptCurrentFeaturePoint.Y - cameraPara.dY)
                      + pRotateMatrix.getNum(2, 0) * (ptCurrentFeaturePoint.Z - cameraPara.dZ);
                dbY = pRotateMatrix.getNum(0, 1) * (ptCurrentFeaturePoint.X - cameraPara.dX) + pRotateMatrix.getNum(1, 1) * (ptCurrentFeaturePoint.Y - cameraPara.dY)
                      + pRotateMatrix.getNum(2, 1) * (ptCurrentFeaturePoint.Z - cameraPara.dZ);
                dbZ = pRotateMatrix.getNum(0, 2) * (ptCurrentFeaturePoint.X - cameraPara.dX) + pRotateMatrix.getNum(1, 2) * (ptCurrentFeaturePoint.Y - cameraPara.dY)
                      + pRotateMatrix.getNum(2, 2) * (ptCurrentFeaturePoint.Z - cameraPara.dZ);

                Pt2d ptImageTmp = new Pt2d();
                ptImageTmp.X = (int)Math.Round(-cameraPara.dFocus * dbX / dbZ);
                ptImageTmp.Y = (int)Math.Round(-cameraPara.dFocus * dbY / dbZ);

                //ptImageTmp.Y *= -1;
                //像主点坐标系===>笛卡尔坐标系(以东为X,以北为Y)
                ptImageTmp.X += cameraPara.dPx;
                ptImageTmp.Y += (-1 * cameraPara.dPy);
                //ptImageTmp.Y *= -1;


                //arcgis显示时把左上角放于原点
                //ptImageTmp.Y -= cameraPara.nH;

                return(ptImageTmp);
            }

            return(null);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Show the extent of input layer in the control.
        /// </summary>
        /// <param name="rasterLayer"></param>
        private void ShowExtent(IRasterLayer rasterLayer)
        {
            IRasterProps rasterProps = (IRasterProps)rasterLayer.Raster;

            leftCoorTextBox.Text = rasterProps.Extent.XMin.ToString();
            buttomCoorTextBox.Text = rasterProps.Extent.YMin.ToString();

            IPnt pixelSize = rasterProps.MeanCellSize();
            pixelSizeTextBox.Text = pixelSize.Y.ToString();
        }
Exemplo n.º 17
0
        private void FrmExportRaster_Load(object sender, EventArgs e)
        {
            m_pRasterLayer = m_pLayer as IRasterLayer;
            IRaster2 pRasterOrg = m_pRasterLayer.Raster as IRaster2;

            IClone pClone    = pRasterOrg as IClone;
            IClone cloneDest = pClone.Clone();

            m_pRaster      = cloneDest as IRaster2;
            m_pSpatialRef  = ((IGeoDataset)m_pRasterLayer).SpatialReference;
            m_pRasterProps = m_pRaster as IRasterProps;

            //更新图层范围
            SetLayerExtent(m_pRasterProps.MeanCellSize().X, m_pRasterProps.MeanCellSize().Y);

            m_Envelope = m_pRasterProps.Extent;
            m_nRows    = m_pRasterProps.Height;
            m_nCols    = m_pRasterProps.Width;

            InitialData(m_pRasterProps);

            rdoLayer.Checked = true;
            if (m_pMap.SpatialReference == null)
            {
                rdoWorkspace.Enabled = false;
            }

            IRasterBandCollection pRB = m_pRaster.RasterDataset as IRasterBandCollection;

            comboBoxExBands.Items.Add("所有波段");
            for (int i = 0; i < pRB.Count; i++)
            {
                comboBoxExBands.Items.Add("Band" + (i + 1).ToString());
            }
            comboBoxExBands.SelectedIndex = 0;
            //SetMeanCellSize();
            chkSocCellSize.Checked = true;
            //设置缺少目录
        }
Exemplo n.º 18
0
        /// <summary>
        /// Creates a random raster given a template raster (defined extent and cell size)
        /// </summary>
        /// <param name="templateRasterPath">full path location of the template raster</param>
        /// <param name="outRasterPath">the full path location of the output random raster</param>
        /// <returns>geoprocessing messages</returns>
        public string createRandomRaster(string templateRasterPath, string outRasterPath)
        {
            ESRI.ArcGIS.SpatialAnalystTools.CreateRandomRaster cRndRst = new CreateRandomRaster();
            string         bnd     = "";
            IRasterDataset rDset   = rsUtil.openRasterDataset(templateRasterPath, out bnd);
            IRaster        rst     = rsUtil.createRaster(rDset);
            IRasterProps   rstProp = (IRasterProps)rst;
            IPnt           pnt     = rstProp.MeanCellSize();

            cRndRst.cell_size  = pnt.X;
            cRndRst.out_raster = outRasterPath;
            return(getMessages(gpExecute(cRndRst)));
        }
Exemplo n.º 19
0
        //获取图层属性
        private void ReadLayerProperties(ILayer layer, AdvTree tree)
        {
            tree.BeginUpdate();
            tree.Nodes.Clear();
            if (layer is IFeatureLayer)
            {
                ILayerGeneralProperties layerProperties = layer as ILayerGeneralProperties;
                AddChildNode(tree.Nodes, "LastMaximumScale", layerProperties.LastMaximumScale.ToString());
                AddChildNode(tree.Nodes, "LastMinimumScale", layerProperties.LastMinimumScale.ToString());
                AddChildNode(tree.Nodes, "LayerDescription ", layerProperties.LayerDescription);
            }
            else if (layer is IRasterLayer)
            {
                IRasterLayer rasterLayer = layer as IRasterLayer;
                if (rasterLayer.Raster != null)
                {
                    IRaster  raster                   = rasterLayer.Raster;
                    IRaster2 raster2                  = raster as IRaster2;
                    IRasterBandCollection coll        = raster2 as IRasterBandCollection;
                    IRasterProps          rasterProps = raster2 as IRasterProps;
                    //基本信息
                    Node node = AddChildNode(tree.Nodes, "基本信息", null);
                    AddChildNode(node.Nodes, "行数,列数", rasterProps.Height.ToString() + "," + rasterProps.Width.ToString());
                    AddChildNode(node.Nodes, "波段数", coll.Count.ToString());
                    AddChildNode(node.Nodes, "像元大小(x,y)", rasterProps.MeanCellSize().X.ToString() + "," + rasterProps.MeanCellSize().Y.ToString());
                    AddChildNode(node.Nodes, "波段数", coll.Count.ToString());
                    AddChildNode(node.Nodes, "像素类型", rasterProps.PixelType.ToString());
                    AddChildNode(node.Nodes, "无效值", ClsGetCameraView.getNoDataValue(rasterProps.NoDataValue).ToString());

                    node = AddChildNode(tree.Nodes, "坐标范围", null);
                    AddChildNode(node.Nodes, "上", rasterProps.Extent.YMax.ToString());
                    AddChildNode(node.Nodes, "左", rasterProps.Extent.XMin.ToString());
                    AddChildNode(node.Nodes, "右", rasterProps.Extent.XMax.ToString());
                    AddChildNode(node.Nodes, "下", rasterProps.Extent.YMin.ToString());

                    node = AddChildNode(tree.Nodes, "统计信息", null);
                    ClsGDBDataCommon cls = new ClsGDBDataCommon();
                    for (int i = 0; i < coll.Count; i++)
                    {
                        double[] dValue   = cls.GetRasterStatistics(m_pLayer, i);
                        Node     nodeBand = AddChildNode(node.Nodes, "Band_" + (i + 1).ToString(), null);
                        AddChildNode(nodeBand.Nodes, "最大值", dValue[0].ToString());
                        AddChildNode(nodeBand.Nodes, "最小值", dValue[1].ToString());
                        AddChildNode(nodeBand.Nodes, "平均值", dValue[2].ToString());
                        AddChildNode(nodeBand.Nodes, "标准差", dValue[3].ToString());
                    }
                }
            }
            tree.EndUpdate(true);
            tree.ExpandAll();
        }
Exemplo n.º 20
0
 public bool RasterClip(IRasterLayer pRasterLayer, IPolygon clipGeo, string FileName)
 {
     try
     {
         IRaster       pRaster                      = pRasterLayer.Raster;
         IRasterProps  pProps                       = pRaster as IRasterProps;
         object        cellSizeProvider             = pProps.MeanCellSize().X;
         IGeoDataset   pInputDataset                = pRaster as IGeoDataset;
         IExtractionOp pExtractionOp                = new RasterExtractionOpClass();
         IRasterAnalysisEnvironment pRasterAnaEnvir = pExtractionOp as IRasterAnalysisEnvironment;
         pRasterAnaEnvir.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
         object extentProvider = clipGeo.Envelope;
         object snapRasterData = Type.Missing;
         pRasterAnaEnvir.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
         IGeoDataset pOutputDataset = pExtractionOp.Polygon(pInputDataset, clipGeo as IPolygon, true); //裁切操作
         IRaster     clipRaster;                                                                       //裁切后得到的IRaster
         if (pOutputDataset is IRasterLayer)
         {
             IRasterLayer rasterLayer = pOutputDataset as IRasterLayer;
             clipRaster = rasterLayer.Raster;
         }
         else if (pOutputDataset is IRasterDataset)
         {
             IRasterDataset rasterDataset = pOutputDataset as IRasterDataset;
             clipRaster = rasterDataset.CreateDefaultRaster();
         }
         else if (pOutputDataset is IRaster)
         {
             clipRaster = pOutputDataset as IRaster;
         }
         else
         {
             return(false);
         }
         //保存裁切后得到的clipRaster
         //如果直接保存为img影像文件
         IWorkspaceFactory pWKSF      = new RasterWorkspaceFactoryClass();
         IWorkspace        pWorkspace = pWKSF.OpenFromFile(System.IO.Path.GetDirectoryName(FileName), 0);
         ISaveAs           pSaveAs    = clipRaster as ISaveAs;
         IDataset          pDataset   = pSaveAs.SaveAs(System.IO.Path.GetFileName(FileName) + ".tif", pWorkspace, "TIFF");//以TIF格式保存
         System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataset);
         return(true);
         //MessageBox.Show("成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(false);
     }
 }
Exemplo n.º 21
0
        public IFeatureClass createPolygons()
        {
            IRasterProps rsProp = (IRasterProps)inputRaster;

            IPnt   rsPnt    = rsProp.MeanCellSize();
            double cellArea = rsPnt.X * rsPnt.Y;
            double tCells   = minArea / cellArea;
            int    rws      = (int)Math.Sqrt(tCells);

            if (rws < 3)
            {
                rws = 3;
            }
            int clms = rws;

            esriUtil.Statistics.dataPrepClusterBinary dpClus = new Statistics.dataPrepClusterBinary(inputRaster, specificity, 100000, 0.001);
            IRaster clusRs = rsUtil.createRaster(rsUtil.calcClustFunctionBinary(inputRaster, dpClus));

            Console.WriteLine("Exracting Domains");
            extractDomains(clusRs, dpClus);
            //IFeatureCursor ftrCur = outftr.Search(null, false);
            //IFeature ftr = ftrCur.NextFeature();
            //Console.WriteLine("removing small polygons");
            //while (ftr != null)
            //{
            //    IArea pArea = (IArea)ftr.Shape;
            //    double area = pArea.Area;
            //    if (area < MinArea)
            //    {
            //        addToNeighboringFeature(ftr, outftr, dpClus);
            //    }
            //    ftr = ftrCur.NextFeature();
            //}
            //Console.WriteLine("splitting large polygons");
            //ftrCur = outftr.Search(null, false);
            //ftr = ftrCur.NextFeature();
            //while (ftr != null)
            //{
            //    IArea pArea = (IArea)ftr.Shape;
            //    double area = pArea.Area;
            //    if (area > MaxArea)
            //    {
            //        splitFeature(ftr, outftr, true);
            //    }
            //    ftr = ftrCur.NextFeature();
            //}
            //System.Runtime.InteropServices.Marshal.ReleaseComObject(ftrCur);
            return(outftr);
        }
Exemplo n.º 22
0
        //获得栅格象素分辨率大小
        private double GetRasterCellSize(string LayerName)
        {
            double       dCellSize = 0;
            AxMapControl axMap     = pMainFrm.getMapControl();

            for (int i = 0; i <= axMap.LayerCount - 1; i++)
            {
                ILayer pLyr = axMap.get_Layer(i);
                if (pLyr != null)
                {
                    if (pLyr is IRasterLayer)
                    {
                        if (pLyr.Name == LayerName)
                        {
                            IRasterLayer pRlyr       = pLyr as IRasterLayer;
                            IRaster      pRaster     = pRlyr.Raster;
                            IRasterProps pRasterProp = pRaster as IRasterProps;
                            dCellSize = (pRasterProp.MeanCellSize().X + pRasterProp.MeanCellSize().Y) / 2;
                        }
                    }
                }
            }
            return(dCellSize);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 获取栅格元数据
        /// </summary>
        private void GetRasterMeta()
        {
            textBoxLayerName.Text  = pRasterLayer.Name;
            textBoxDataType.Text   = "栅格数据";
            textBoxCreateTime.Text = DateTime.Now.ToString("yyyy年MM月dd日 hh时mm分ss秒");

            IRaster        pRaster        = pRasterLayer.Raster;
            IRasterDataset pRasterDataset = new RasterDatasetClass();
            IRasterProps   pRasterProps   = (IRasterProps)pRaster;

            textBoxRHeight.Text    = pRasterProps.Height.ToString();
            textBoxProjection.Text = pRasterProps.SpatialReference.Name;
            textBoxRWidth.Text     = pRasterProps.Width.ToString();

            //投影到经纬度
            IEnvelope pExtent = pRasterProps.Extent;

            try
            {
                ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass();
                ISpatialReference        pSR = spatialrefFactory.CreateGeographicCoordinateSystem((int)(esriSRGeoCSType.esriSRGeoCS_WGS1984));
                pExtent.Project(pSR);
            }
            catch { MessageBox.Show("输入文件空间参考有误"); }
            textBoxRMinX.Text = pExtent.XMin.ToString();
            textBoxRMinY.Text = pExtent.YMin.ToString();
            textBoxRMaxX.Text = pExtent.XMax.ToString();
            textBoxRMaxY.Text = pExtent.YMax.ToString();

            IPnt pPnt = pRasterProps.MeanCellSize();

            textBoxRResolution.Text = Math.Min(pPnt.X, pPnt.Y).ToString();

            try
            {
                object nodata = pRasterProps.NoDataValue;
                if (nodata.GetType().IsArray)
                {
                    Array a = ((Array)nodata);
                    textBoxRNoDataValue.Text = a.GetValue(0).ToString();
                }
            }
            catch { MessageBox.Show("无效值获取失败"); }
            textBoxRBandCount.Text = pRasterLayer.BandCount.ToString();
        }
Exemplo n.º 24
0
        public static void RasterClip(IRasterLayer pRasterLayer, IPolygon clipGeo)
        {
            IRaster       pRaster                      = pRasterLayer.Raster;
            IRasterProps  pProps                       = pRaster as IRasterProps;
            object        cellSizeProvider             = pProps.MeanCellSize().X;
            IGeoDataset   pInputDataset                = pRaster as IGeoDataset;
            IExtractionOp pExtractionOp                = new RasterExtractionOpClass();
            IRasterAnalysisEnvironment pRasterAnaEnvir = pExtractionOp as IRasterAnalysisEnvironment;

            pRasterAnaEnvir.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            object extentProvider = clipGeo.Envelope;
            object snapRasterData = Type.Missing;

            pRasterAnaEnvir.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvMinOf, ref extentProvider, ref snapRasterData);
            //IWorkspaceFactory pWrokspaceFactory = new RasterWorkspaceFactoryClass();
            //if (flag == 0)
            //{
            //    flag++;
            //}
            //if (flag == 1)
            //{
            //    pRasterAnaEnvir.OutWorkspace = pWrokspaceFactory.OpenFromFile("D://temp", 0);
            //}
            IGeoDataset pOutputDataset = pExtractionOp.Polygon(pInputDataset, clipGeo, true); //裁切操作
            IRaster     clipRaster     = pOutputDataset as IRaster;                           //裁切后得到的IRaster

            //保存裁切后得到的clipRaster
            //如果直接保存为img影像文件
            IWorkspaceFactory pWKSF    = new RasterWorkspaceFactory();
            SaveFileDialog    savefile = new SaveFileDialog();

            savefile.Title  = "选择输出影像";
            savefile.Filter = "栅格文件(*.tif)|*.tif|栅格文件(*.img)|*.img";
            if (savefile.ShowDialog() == DialogResult.OK)
            {
                IWorkspace pWorkspace = pWKSF.OpenFromFile(System.IO.Path.GetDirectoryName(savefile.FileName), 0);
                ISaveAs    pSaveAs    = clipRaster as ISaveAs;
                pSaveAs.SaveAs(System.IO.Path.GetFileName(savefile.FileName), pWorkspace, "TIFF");//以img格式保存;
                MessageBox.Show("裁切成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 25
0
        private IRaster RasterClip(IRasterLayer pRasterLayer, IPolygon clipGeo)
        {
            if (clipGeo == null)
            {
                return(null);
            }

            IRaster clipRaster = null;

            IRaster       pRaster                      = pRasterLayer.Raster;
            IRasterProps  pProps                       = pRaster as IRasterProps;
            object        cellSizeProvider             = pProps.MeanCellSize().X;
            IGeoDataset   pInputDataset                = pRaster as IGeoDataset;
            IExtractionOp pExtractionOp                = new RasterExtractionOpClass();
            IRasterAnalysisEnvironment pRasterAnaEnvir = pExtractionOp as IRasterAnalysisEnvironment;

            pRasterAnaEnvir.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            object extentProvider = clipGeo.Envelope;
            object snapRasterData = Type.Missing;

            pRasterAnaEnvir.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
            IGeoDataset pOutputDataset = pExtractionOp.Polygon(pInputDataset, clipGeo as IPolygon, true);

            if (pOutputDataset is IRasterLayer)
            {
                IRasterLayer rasterLayer = pOutputDataset as IRasterLayer;
                clipRaster = rasterLayer.Raster;
            }
            else if (pOutputDataset is IRasterDataset)
            {
                IRasterDataset rasterDataset = pOutputDataset as IRasterDataset;
                clipRaster = rasterDataset.CreateDefaultRaster();
            }
            else if (pOutputDataset is IRaster)
            {
                clipRaster = pOutputDataset as IRaster;
            }

            return(clipRaster);
        }
Exemplo n.º 26
0
        private void DrawPointsOnActiveView(int colindex, int rowindex, IRasterProps pRasterProps, IActiveView ActiveView)
        {
            IGraphicsContainer pGraphicContainer = ActiveView.GraphicsContainer;

            IRgbColor pRgbColor = m_pSnippet.getRGB(0, 255, 255);

            //ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
            //pSimpleLineSymbol.Width = 2;
            //pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            //pSimpleLineSymbol.Color = pRgbColor;

            ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();

            pSimpleMarkerSymbol.Size  = 8;
            pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
            pSimpleMarkerSymbol.Color = pRgbColor;

            double dblX = 0, dblY = 0;
            double dblCellSize = Convert.ToDouble(pRasterProps.MeanCellSize().X);

            dblX = pRasterProps.Extent.XMin + (dblCellSize / 2) + dblCellSize * colindex;
            dblY = pRasterProps.Extent.YMax - (dblCellSize / 2) - dblCellSize * rowindex;

            IPoint pPoint = new PointClass();

            pPoint.X = dblX;
            pPoint.Y = dblY;

            IElement pElement = new MarkerElementClass();

            IMarkerElement pMarkerElement = (IMarkerElement)pElement;

            pMarkerElement.Symbol = pSimpleMarkerSymbol;
            pElement.Geometry     = pPoint;

            pGraphicContainer.AddElement(pElement, 0);

            ActiveView.Refresh();
        }
Exemplo n.º 27
0
        private void GetRasterInfo(string file, ref StructProMeta meta)
        {
            IRasterLayer      pRasterLayer         = null;
            ISpatialReference spatialReferenceInfo = null;

            try
            {
                pRasterLayer = new RasterLayerClass();
                pRasterLayer.CreateFromFilePath(_file);
                IRaster      pRaster      = pRasterLayer.Raster;
                IRasterProps pRasterProps = pRaster as IRasterProps;
                meta.Resolution       = pRasterProps.MeanCellSize().X.ToString("f1");
                spatialReferenceInfo  = pRasterProps.SpatialReference;
                meta.CoordinateSystem = spatialReferenceInfo.Name;
                if (spatialReferenceInfo is IProjectedCoordinateSystem)
                {
                    IProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceInfo as IProjectedCoordinateSystem;
                    meta.MapProjection = projectedCoordinateSystem.Projection.Name;
                    IPoint point = pRasterProps.Extent.UpperLeft;
                    point.Project(projectedCoordinateSystem.GeographicCoordinateSystem);
                    meta.UpperLeftLat = point.Y.ToString();
                    meta.UpperLeftLon = point.X.ToString();
                    point             = pRasterProps.Extent.UpperRight;
                    point.Project(projectedCoordinateSystem.GeographicCoordinateSystem);
                    meta.UpperRightLat = point.Y.ToString();
                    meta.UpperRightLon = point.X.ToString();
                    point = pRasterProps.Extent.LowerRight;
                    point.Project(projectedCoordinateSystem.GeographicCoordinateSystem);
                    meta.LowerRightLat = point.Y.ToString();
                    meta.LowerRightLon = point.X.ToString();
                    point = pRasterProps.Extent.LowerLeft;
                    point.Project(projectedCoordinateSystem.GeographicCoordinateSystem);
                    meta.LowerLeftLat = point.Y.ToString();
                    meta.LowerLeftLon = point.X.ToString();
                }
            }
            catch (Exception)
            { }
        }
Exemplo n.º 28
0
 public void convertToPolygon()
 {
     if (modelrs == null)
     {
         Console.WriteLine("You must segment landfire data before you can covert to polygons");
         return;
     }
     try
     {
         if (modelrs != null)
         {
             string       rgNm         = rsUtil.getSafeOutputName(landfireworkspace, "RG");
             IRaster      rgRs         = rsUtil.createRaster(rsUtil.regionGroup(modelrs));
             IRasterProps modelrsProps = (IRasterProps)modelrs;
             IPnt         pnt          = modelrsProps.MeanCellSize();
             double       meanCellSize = pnt.X * pnt.Y;
             //Console.WriteLine(meanCellSize);
             int mincell = System.Convert.ToInt32((minarea / meanCellSize) + .5);
             int maxcell = System.Convert.ToInt32((maxarea / meanCellSize) + .5);
             //Console.WriteLine("number of cells = " + mincell.ToString());
             Console.WriteLine("Eliminating slivers");
             //IRaster rsE = rsUtil.eliminateSlivers(rgRs,mincell,maxcell);
             Console.WriteLine("Splitting Polygons");
             //IRaster rsS = rsUtil.splitRegions(rsE, mincell, maxcell);
             string outNm = "LandFireStands";
             outNm = returnSafeName(outNm);
             //Console.WriteLine("Converting to polygon");
             IConversionOp convOp = new RasterConversionOpClass();
             //IGeoDataset geoDset = convOp.RasterDataToPolygonFeatureData((IGeoDataset)rsS, LandFireWorkspace, outNm, false);
             //LandFireFeatureClass = (IFeatureClass)geoDset;
         }
         //Console.WriteLine("Finished Converting Polygons");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdRasterResample.OnClick implementation
            IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;

            if (pMapCtr != null)
            {
                m_frmRasterResample = new FrmRasterResample();
                IRasterProps pRasterProps = pRasterLayer.Raster as IRasterProps;
                m_frmRasterResample.Cellsize = pRasterProps.MeanCellSize().X;
                if (m_frmRasterResample.ShowDialog() == DialogResult.OK)
                {
                    IGeoDataset         pGeodataset         = pRasterLayer.Raster as IGeoDataset;
                    IRasterGeometryProc pRasterGeometryProc = new RasterGeometryProcClass();
                    ITransformationOp   pTransOP            = new RasterTransformationOpClass();
                    string name = pRasterLayer.Name;
                    if (m_frmRasterResample.resampleType == 0)
                    {
                        IGeoDataset pGeodataset2 = pTransOP.Resample(pGeodataset, m_frmRasterResample.Cellsize, esriGeoAnalysisResampleEnum.esriGeoAnalysisResampleNearest);
                        pRasterLayer.CreateFromDataset(pGeodataset2 as IRasterDataset);
                        pRasterLayer.Name = name;
                    }
                    if (m_frmRasterResample.resampleType == 1)
                    {
                        IGeoDataset pGeodataset2 = pTransOP.Resample(pGeodataset, m_frmRasterResample.Cellsize, esriGeoAnalysisResampleEnum.esriGeoAnalysisResampleBilinear);
                        pRasterLayer.CreateFromDataset(pGeodataset2 as IRasterDataset);
                        pRasterLayer.Name = name;
                    }
                    if (m_frmRasterResample.resampleType == 2)
                    {
                        IGeoDataset pGeodataset2 = pTransOP.Resample(pGeodataset, m_frmRasterResample.Cellsize, esriGeoAnalysisResampleEnum.esriGeoAnalysisResampleCubic);
                        pRasterLayer.CreateFromDataset(pGeodataset2 as IRasterDataset);
                        pRasterLayer.Name = name;
                    }
                    pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);
                }
            }
        }
Exemplo n.º 30
0
        public void RasterMeaAtt(IRaster pRaster, IGeometry pGeoMetry, ref double pixelmax, ref double pixelmin)
        {
            IPolygon      clipGeo                      = pGeoMetry as IPolygon;
            IRasterProps  pProps                       = pRaster as IRasterProps;
            object        cellSizeProvider             = pProps.MeanCellSize().X;
            IGeoDataset   pInputDataset                = pRaster as IGeoDataset;
            IExtractionOp pExtractionOp                = new RasterExtractionOpClass();
            IRasterAnalysisEnvironment pRasterAnaEnvir = pExtractionOp as IRasterAnalysisEnvironment;

            pRasterAnaEnvir.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
            object extentProvider = clipGeo.Envelope;
            object snapRasterData = Type.Missing;

            pRasterAnaEnvir.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref extentProvider, ref snapRasterData);
            IGeoDataset pOutputDataset = pExtractionOp.Polygon(pInputDataset, clipGeo as IPolygon, true); //裁切操作
            IRaster     clipRaster     = null;                                                            //裁切后得到的IRaster

            if (pOutputDataset is IRasterLayer)
            {
                IRasterLayer rasterLayer = pOutputDataset as IRasterLayer;
                clipRaster = rasterLayer.Raster;
            }
            else if (pOutputDataset is IRasterDataset)
            {
                IRasterDataset rasterDataset = pOutputDataset as IRasterDataset;
                clipRaster = rasterDataset.CreateDefaultRaster();
            }
            else if (pOutputDataset is IRaster)
            {
                clipRaster = pOutputDataset as IRaster;
            }
            else
            {
                //return false;
            }

            CalRasterAtt(clipRaster as IRaster2, ref pixelmax, ref pixelmin);
        }
Exemplo n.º 31
0
 public IPolygon GetBoundaryAsPolygon(IRasterProps props)
 {
     double left = props.Extent.XMin;
     double top = props.Extent.YMax;
     IPnt cellSize = props.MeanCellSize();
     PolygonClass result = new PolygonClass();
     object missing = Type.Missing;
     for (int x = 0; x <= m_Width; x += 1) {
         for (int y = 0; y <= m_Height; y += 1) {
             if ((!CellVisited(x, y)) && IsFilled(x, y) && (!IsFilled(x - 1, y))) {
                 List<IntPoint> bmRing = GetCurve(x, y);
                 RingClass ring = new RingClass();
                 foreach (IntPoint bmPt in bmRing) {
                     PointClass point = new PointClass();
                     point.PutCoords(left + bmPt.X * cellSize.X,
                                     top - bmPt.Y * cellSize.Y);
                     ring.AddPoint(point, ref missing, ref missing);
                 }
                 result.AddGeometry(ring, ref missing, ref missing);
             }
         }
     }
     return result;
 }