コード例 #1
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]);
        }
コード例 #2
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));
        }