转换思路:
- 获取源影像的地理范围,将该地理范围进行坐标投影转换,得到目标影像的地理范围
- 根据源影像信息创建目标影像集,并设置坐标系为目标坐标系4490
- 将第一步得到的地理范围通过DatasetImage.SetGeoReference 方法 赋予目标影像
- 进行每个波段每个像素的赋值
发现转换结果有偏差,原因在于通过第1步获得的目标坐标系的地理范围不是正四方形,导致在第3步设置影像的地理范围时,把平行四边形的地理范围当作正四方形的地理范围,从而使得结果不正确
但DatasetImage。SetGeoReference 方法 只能设置正四方形,正确的影像转换应该是怎么操作呢? (CoordSysTranslator.Convert 方法除外)
具体转换代码:
var originDs = Application.ActiveApplication.Workspace.Datasources["测试"];
var targetDs = Application.ActiveApplication.Workspace.Datasources["MemoryDatasource"];
var originDataset = originDs.Datasets["test"] as DatasetImage;
// 获取四至点
int width = originDataset.Width;
int height = originDataset.Height;
Point2Ds point2Ds = new Point2Ds() {
originDataset.ImageToXY(new System.Drawing.Point(0, height- 1)),
originDataset.ImageToXY(new System.Drawing.Point(width - 1, 0))
};
string bandName;
DatasetImageInfo datasetImageInfo = new DatasetImageInfo();
datasetImageInfo.Name = "影像数据集信息";
datasetImageInfo.BlockSizeOption = originDataset.BlockSizeOption;
datasetImageInfo.Height = originDataset.Height;
datasetImageInfo.Width = originDataset.Width;
datasetImageInfo.EncodeType = originDataset.EncodeType;
datasetImageInfo.BandCount = originDataset.BandCount;
datasetImageInfo.PixelFormat = originDataset.GetPixelFormat(0);
// 通过影像数据集信息创建影像数据集
DatasetImage datasetImage = targetDs.Datasets.Create(datasetImageInfo);
datasetImage.PrjCoordSys = new PrjCoordSys(4490);
// 对四至点执行坐标转换 获得目标坐标系的四至
if (CoordSysTranslator.Convert(point2Ds, originDataset.PrjCoordSys, new PrjCoordSys(4490), new CoordSysTransParameter(), new CoordSysTransMethod()))
{
datasetImage.SetGeoReference(new Rectangle2D(point2Ds[0], point2Ds[1]));
}
// 进行每个像素点的赋值
int w, h, b;
int bandCount = originDataset.BandCount;
for (b = 0; b < bandCount; b++)
{
datasetImage[b] = originDataset[b];
datasetImage.SetPalette(originDataset.GetPalette(b), b);
datasetImage.SetNoData(originDataset.GetNoData(b), b);
for (w = 0; w < width; w++)
{
for (h = 0; h < height; h++)
{
datasetImage.SetValue(w, h, originDataset.GetValue(w, h, b), b);
}
}
}