| | |
| | | { |
| | | public class GdalHelper |
| | | { |
| | | #region 成员变量+构造函数 |
| | | private static bool isInited; |
| | | |
| | | private static GdalHelper instance; |
| | |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 实例 |
| | |
| | | } |
| | | |
| | | String srsName = ds.GetSpatialRef().GetName(); |
| | | if (srsName.Contains(CGCS2000)) |
| | | { |
| | | point.TransformTo(sr4490); |
| | | } |
| | | else |
| | | { |
| | | //if (srsName.Contains(CGCS2000)) |
| | | //{ |
| | | // point.TransformTo(sr4490); |
| | | //} |
| | | //else |
| | | //{ |
| | | point.TransformTo(sr4326); |
| | | } |
| | | //} |
| | | point.SwapXY(); |
| | | |
| | | return point; |
| | |
| | | ds = Gdal.Open(file, Access.GA_ReadOnly); |
| | | if (null == ds) return; |
| | | |
| | | OSGeo.GDAL.Band band = ds.GetRasterBand(1); |
| | | Band band = ds.GetRasterBand(1); |
| | | if (0 == band.GetOverviewCount()) |
| | | { |
| | | ds.BuildOverviews("nearest", new int[] { 2, 4, 6, 8, 16 }); |
| | |
| | | /// <summary> |
| | | /// 创建PNG |
| | | /// </summary> |
| | | public void CreatePng(string filePath, int width, int height, int bands = 3) |
| | | public void CreatePng(byte[] buffer, string filePath, int width, int height, int bands = 3) |
| | | { |
| | | // 创建内存驱动 |
| | | OSGeo.GDAL.Driver memDriver = Gdal.GetDriverByName("MEM"); |
| | |
| | | { |
| | | Band band = ds.GetRasterBand(i); |
| | | band.SetRasterColorInterpretation((ColorInterp)i); |
| | | } |
| | | |
| | | // 填充内存图像 |
| | | byte[] buffer = new byte[width * height * bands]; |
| | | for (int i = 0; i < buffer.Length; i++) |
| | | { |
| | | buffer[i] = (byte)(i % 256); |
| | | } |
| | | |
| | | // 写入内存图像 |