GDAL 遥感图像处理后的数据保存为图像文件的实现方法
在遥感图像处理中,GDAL库不仅能读取和处理大部分的遥感图像数据,而且还能够实现图像处理后将数据保存为图像的功能。
本文就详细介绍如何将内存中的图像数据保存为.tif格式。
首先,遥感数据处理完,保存在一维数组data中,图像的宽和高为width和height,图像有三个波段。在保存时要使图像的每一行对其,保证位数为32的倍数
先上实现的代码,源程序如下:
int bytesPerLine=(width*+)/;//字节对齐
unsigned char *data=new unsigned char[bytesPerLine*height]; //图像处理...... GDALAllRegister();//注册数据集
GDALDriver *poDriver;
GDALDataset *BiomassDataset;
poDriver = GetGDALDriverManager()->GetDriverByName("Gtiff"); const char *output_file="D:\xxxx"; BiomassDataset=poDriver->Create(output_file,width,height,,GDT_Byte, NULL); int panBandMap []= {,,};
BiomassDataset->RasterIO(GF_Write,,,width,height,data_show_,width,height,GDT_Byte,,panBandMap,,bytesPerLine,); GDALClose(BiomassDataset);
BiomassDataset=NULL; delete []data;
data=NULL;
这里关键的就是Create和RasterIO两个函数
Create函数的功能为创建一个文件,创建成功就返回一个GDALDataSet类指针对象,然后再使用这个指针对象调用RasterIO向文件内写数据。Create函数的原型:
GDALDataset * GDALDriver::Create ( const char * pszFilename,
int nXSize,
int nYSize,
int nBands,
GDALDataType eType,
char ** papszOptions
)
Parameters:
| pszFilename | the name of the dataset to create. UTF-8 encoded. | |
| nXSize | width of created raster in pixels. | |
| nYSize | height of created raster in pixels. | |
| nBands | number of bands. | |
| eType | type of raster. | |
| papszOptions | list of driver specific control parameters. |
需要注意的是nXSize和nXSize均是值像素的个数,而非字节个数,所以程序中是width和height。文件创建好了,里面数据是空的,下面就往文件里面写图像数据
RasterIO是GDALDataSet类的方法,功能是写数据,函数原型如下:
CPLErr GDALDataset::RasterIO ( GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
int nYSize,
void * pData,
int nBufXSize,
int nBufYSize,
GDALDataType eBufType,
int nBandCount,
int * panBandMap,
int nPixelSpace,
int nLineSpace,
int nBandSpace
)
Parameters:
| eRWFlag | Either GF_Read to read a region of data, or GF_Write to write a region of data. | |
| nXOff | The pixel offset to the top left corner of the region of the band to be accessed. This would be zero to start from the left side. | |
| nYOff | The line offset to the top left corner of the region of the band to be accessed. This would be zero to start from the top. | |
| nXSize | The width of the region of the band to be accessed in pixels. | |
| nYSize | The height of the region of the band to be accessed in lines. | |
| pData | The buffer into which the data should be read, or from which it should be written. This buffer must contain at least nBufXSize * nBufYSize * nBandCount words of type eBufType. It is organized in left to right,top to bottom pixel order. Spacing is controlled by the nPixelSpace, and nLineSpace parameters. | |
| nBufXSize | the width of the buffer image into which the desired region is to be read, or from which it is to be written. | |
| nBufYSize | the height of the buffer image into which the desired region is to be read, or from which it is to be written. | |
| eBufType | the type of the pixel values in the pData data buffer. The pixel values will automatically be translated to/from the GDALRasterBand data type as needed. | |
| nBandCount | the number of bands being read or written. | |
| panBandMap | the list of nBandCount band numbers being read/written. Note band numbers are 1 based. This may be NULL to select the first nBandCount bands. | |
| nPixelSpace | The byte offset from the start of one pixel value in pData to the start of the next pixel value within a scanline. If defaulted (0) the size of the datatype eBufType is used. | |
| nLineSpace | The byte offset from the start of one scanline in pData to the start of the next. If defaulted (0) the size of the datatype eBufType * nBufXSize is used. | |
| nBandSpace | the byte offset from the start of one bands data to the start of the next. If defaulted (0) the value will be nLineSpace * nBufYSize implying band sequential organization of the data buffer. |
这里的图像数据宽度和高度均是指图像像素点的个数,所以都是width和height。要特别注意最后四个参数。
int* panBandMap:波段的排列顺序,比如RGB,BGR等
int nPixelSpace:写入时相邻像素间的字节数大小,这里每个像素三个波段,因此为3
int nLineSpace:图像相邻行见字节数的大小,这里一行又bytePerLine个字节,因此为bytePerLine
int nBandSpace:写入时相邻波段见字节大小,这里写入的波段都是紧挨着的,因此为1
GDAL 遥感图像处理后的数据保存为图像文件的实现方法的更多相关文章
- Python将数据保存为txt文件的方法
f = open('name.txt',mode='w') #打开文件,若文件不存在系统自动创建. #参数name 文件名,mode 模式. #w 只能操作写入 r 只能读取 a 向文件追加 #w+ ...
- [转]RGB数据保存为BMP图片
转自:http://blog.csdn.net/yixianfeng41/article/details/52591585 一.BMP文件由文件头.位图信息头.颜色信息和图形数据四部分组成. 1.BM ...
- java大并发数据保存方案
做了几年.net,如今终于要做java了. 需求: 线下终端会定时上传gps位置到服务端,服务端收到数据保存到mysql数据库,当线下终端过多时,问题出现了,首当其冲的是数据库连接池经常会崩溃,单个t ...
- PDA手持扫描资产标签,盘点完成后将数据上传到PC端,固定资产系统查看盘点结果
固定资产管理系统介绍: 致力于研发条码技术.集成条码系统的专业性公司,针对客户的不同需求,提供一站式的企业条码系统解决方案:包括功能强大的软件系统.安全可靠的无线网络.坚固耐用的硬件系统.灵活易用的管 ...
- SqlServer触发器判断对表操作类型(增、删、改)并将修改后的数据映射到新表
该文章为原创,日后可能会根据实际开发经验和网友评论,进行相应地方修改,为获得最新博客动态,望在转发博客的时候注明出处. 触发器要实现的功能: (1)获取对表Table1数据操作操作类型(insert. ...
- input中空格后的数据不显示
bug,input中空格后的数据不显示 昨天在修bug,有一个bug是用户修改的个人信息的地址栏,输入有空格的话,空格后面的内容存不上,而且没有报错,奇怪了,只好跟踪下. 页面上的输入框就是个 ...
- Android中的数据保存
形式 Android的数据保存分为3种形式:file, SharedPreference, Database 文件 主要思想就是通过Context类中提供的openFileInput和openFile ...
- 编辑器插件数据保存之Serializable
Editor数据保存需求 做编辑器插件开发时,当打开一个窗口,对数值进行修改后,在关闭窗口或重新打开Unity时,希望能保存上次的数据. 相关知识 Serialization ,ScriptableO ...
- 基于Qt的遥感图像处理软件设计总结
开发工具 VS2008+Qt4.8.0+GDAL1.9 要点 接口要独立,软件平台与算法模块独立,平台中各接口设计灵活,修改时容易. 设计软件时一步步来,每个功能逐一实现,某个功能当比较独立时可以 ...
随机推荐
- PHP中想过获取系统内置的所有常量吗?
print_r(get_defined_constants(true)); OK!这样就可以了,赶紧去试试吧
- php 和mysql httpd 简单网页的搭建
使用两台服务器 Centos 7 做 php和httpd和php-sql 服务的安装 CentOS 5 做php 和 mysql 的安装 1.搭建本地yum源 两台服务器 都是 2.关闭防火墙和s ...
- 从0开始学Swift笔记整理(五)
这是跟在上一篇博文后续内容: --Core Foundation框架 Core Foundation框架是苹果公司提供一套概念来源于Foundation框架,编程接口面向C语言风格的API.虽然在Sw ...
- 【转载】我也说 IEnumerable,ICollection,IList,List之间的区别
做C#的同学们,都知道,一类只能有一个继承类,但可以实现多个接口.这句话就告诉我们:IEnumerable,ICollection,IList,List区别了 首先我看看 IEnumerable: / ...
- 在ASP.NET 5中显示错误信息
在 ASP.NET 5 中如果不进行显示错误信息的相关配置,在发生错误时,在浏览器中只能看到空白页面. 显示错误信息的配置方法如下: 1)在 project.json 中添加对 Microsoft.A ...
- Hash哈希(一)
Hash哈希(一) 哈希是大家比较常见一个词语,在编程中也经常用到,但是大多数人都是知其然而不知其所以然,再加上这几天想写一个一致性哈希算法,突然想想对哈希也不是很清楚,所以,抽点时间总结下Hash知 ...
- C++数组和指针
<C++ Primer 4th>读书摘要 与 vector 类型相似,数组也可以保存某种类型的一组对象:而它们的区别在于,数组的长度是固定的.数组一经创建,就不允许添加新的元素.指针则可以 ...
- Redis教程(八):事务详解
转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/135.html?1455806987 一.概述: 和众多其它数据库一样,R ...
- duilib进阶教程 -- 总结 (17)
整个教程的代码下载:http://download.csdn.net/detail/qq316293804/6502207 (由于duilib进阶教程主要介绍界面,所以这个教程只给出界面相关的代码,完 ...
- Atitit. 高级软件工程师and 普通的区别 高级编程的门槛总结
Atitit. 高级软件工程师and 普通的区别 高级编程的门槛总结 1. 完备的知识体系 2 2. 编程理论/原理的掌握 2 1.1. 掌握常用的概念(ORM,IOC,AOP,event driv ...