TA的每日心情 | 开心 2020-3-20 17:50 |
---|
签到天数: 1 天 [LV.1]初来乍到
|
本帖最后由 liyihongcug 于 2020-3-16 14:38 编辑
手绘一个范围 需要获取范围内的 最大高程与最小高程,用于湮没分析
--找不到自己独立实现public struct FourP
{
public int stx;
public int xc;
public int sty;
public int yc;
public int zoom;
} public void PingTu(FourP fp)
{
//fp.yc = fp.yc - 1;
Gdal.AllRegister();
Driver dr = Gdal.GetDriverByName("GTiff");
Dataset dst = dr.Create("g:\\baiduZ"+fp.zoom.ToString ()+".tif", fp.xc *256, fp.yc*256, 3, DataType.GDT_Byte, null);
for (int iy = 0; iy < fp.yc; iy++)
{
for (int ix = 0; ix < fp.xc; ix++)
{
try
{
Dataset ds = Gdal.Open("g:\\bdmap\\Z" + fp.zoom.ToString() + "x" + iy.ToString() + "y" + ix.ToString() + ".jpg", Access.GA_ReadOnly);
SaveBitmapBuffered(ds, dst, ix, (fp.yc-1)-iy);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
} }
dst.Dispose();
} void SaveBitmapBuffered(Dataset ds, Dataset dw, int x, int y)
{
Band redBand = ds.GetRasterBand(1);
Band greenBand = ds.GetRasterBand(2);
Band blueBand = ds.GetRasterBand(3);
int width = redBand.XSize;
int height = redBand.YSize; DateTime start = DateTime.Now; byte[] r = new byte[width * height];
byte[] g = new byte[width * height];
byte[] b = new byte[width * height]; redBand.ReadRaster(0, 0, width, height, r, width, height, 0, 0);
greenBand.ReadRaster(0, 0, width, height, g, width, height, 0, 0);
blueBand.ReadRaster(0, 0, width, height, b, width, height, 0, 0);
TimeSpan renderTime = DateTime.Now - start;//计算生成一幅新的栅格图像所需要的时间
listBox1.Items.Add("SaveBitmapBuffered fetch time: " + renderTime.TotalMilliseconds + " ms");
Band wrb = dw.GetRasterBand(1);
wrb.WriteRaster(x * width, y * height, width, height, r, width, height, 0, 0);
Band wgb = dw.GetRasterBand(2);
wgb.WriteRaster(x * width, y * height, width, height, g, width, height, 0, 0);
Band wbb = dw.GetRasterBand(3);
wbb.WriteRaster(x * width, y * height, width, height, b, width, height, 0, 0); //dst.Dispose(); }
分享:
|
|