1 //定义转换参数
2 private readonly double[] d_transform = { 69.999999999999972, 0.01, 0.0, 44.999999999999979, 0.0, -0.01 };
3 //定义坐标系统
4 private readonly string d_project = "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]";
5
6 //gdal注册
7 Gdal.AllRegister();
8 driver = Gdal.GetDriverByName("GTiff");
9 Dataset ds = driver.Create(filePath, xSize, ySize, 1, DataType.GDT_Float32, new string[] { });
10 ds.SetGeoTransform(d_transform); //影像转换参数
11 ds.SetProjection(d_project); //投影
12 //压缩方式,设置后重新读取发现并没有这个metadata参数,具体情况未知
13 ds.SetMetadataItem("COMPRESSION", "LZW", "IMAGE_STRUCTURE");
14 //初始化数组
15 ds.GetRasterBand(1).WriteRaster(0, 0, xSize, ySize, buffer, xSize, ySize, 0, 0);
16 ds.GetRasterBand(1).FlushCache();
17 ds.FlushCache();
18 ds.Dispose();
19
20 //其中buffer为float类型数组,长度为[xSize*ySize];
ds.SetMetadataItem("COMPRESSION", "LZW", "IMAGE_STRUCTURE");
这个参数设置后重新读取发现并没有这个metadata参数,有知道的烦请留言
重新获取可以通过
string[] metadata = ds.GetMetadata("IMAGE_STRUCTURE");