管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-07-18 8e96c01eb724a292d8c7f8e1c74dbf4384e56188
修改GDAL帮助类
已修改1个文件
99 ■■■■■ 文件已修改
SimuTools/Tools/GdalHelper.cs 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/Tools/GdalHelper.cs
@@ -22,6 +22,8 @@
        public static SpatialReference sr4490 { set; get; }
        public static readonly String CGCS2000 = "CGCS2000";
        /// <summary>
        /// 构造函数
        /// </summary>
@@ -80,5 +82,102 @@
            Ogr.RegisterAll();
            Gdal.AllRegister();
        }
        /**
         * 获取Dataset的最小点
         */
        private static Geometry GetMinPoint(Dataset ds)
        {
            double[] transform = new double[6];
            ds.GetGeoTransform(transform);
            double xMin = transform[0];
            double yMin = transform[3] - ds.RasterYSize * transform[1];
            Geometry point = new Geometry(wkbGeometryType.wkbPoint);
            point.AddPoint(xMin, yMin, 0);
            return Transform(ds, point);
        }
        /**
         * 获取Dataset的最大点
         */
        private static Geometry GetMaxPoint(Dataset ds)
        {
            /*
             * transform[0] 左上角x坐标
             * transform[1] 东西方向分辨率
             * transform[2] 旋转角度, 0表示图像 "北方朝上"
             *
             * transform[3] 左上角y坐标
             * transform[4] 旋转角度, 0表示图像 "北方朝上"
             * transform[5] 南北方向分辨率
             */
            double[] transform = new double[6];
            ds.GetGeoTransform(transform);
            double xMax = transform[0] + (ds.RasterYSize * transform[1]);
            double yMax = transform[3];
            Geometry point = new Geometry(wkbGeometryType.wkbPoint);
            point.AddPoint(xMax, yMax, 0);
            return Transform(ds, point);
        }
        /**
         * 坐标转换
         */
        public static Geometry Transform(Dataset ds, Geometry point)
        {
            point.AssignSpatialReference(ds.GetSpatialRef());
            if (ds.GetSpatialRef().IsGeographic() > 0)
            {
                return point;
            }
            String srsName = ds.GetSpatialRef().GetName();
            if (srsName.Contains(CGCS2000))
            {
                point.TransformTo(sr4490);
            }
            else
            {
                point.TransformTo(sr4326);
            }
            point.SwapXY();
            return point;
        }
        /**
         * 创建金字塔
         */
        public static void CreatePyramid(String file)
        {
            Dataset ds = null;
            try
            {
                if (!File.Exists(file)) return;
                ds = Gdal.Open(file, Access.GA_ReadOnly);
                if (null == ds) return;
                Band band = ds.GetRasterBand(1);
                if (0 == band.GetOverviewCount())
                {
                    ds.BuildOverviews("nearest", new int[] { 2, 4, 6, 8, 16 });
                }
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message);
            }
            finally
            {
                if (null != ds) ds.Dispose();
            }
        }
    }
}