GDAL中RasterIO函数(把文件读取为一个一维数组)和ReadBlock函数(读取栅格数据块)
CPLErr GDALRasterBand::RasterIO |
( |
eRWFlag, |
|
|
int |
nXOff, |
|
|
int |
nYOff, |
|
|
int |
nXSize, |
|
|
int |
nYSize, |
|
|
void * |
pData, |
|
|
int |
nBufXSize, |
|
|
int |
nBufYSize, |
|
|
eBufType, |
||
|
int |
nPixelSpace, |
|
|
int |
nLineSpace |
|
|
) |
|
|
Read/write a region of image data for this band.
This method allows reading a region of a GDALRasterBand into a buffer, or writing data from a buffer into a region of a GDALRasterBand. It automatically takes care of data type translation if the data type (eBufType) of the buffer is different than that of the GDALRasterBand. The method also takes care of image decimation / replication if the buffer size (nBufXSize x nBufYSize) is different than the size of the region being accessed (nXSize x nYSize).
The nPixelSpace and nLineSpace parameters allow reading into or writing from unusually organized buffers. This is primarily used for buffers containing more than one bands raster data in interleaved format.
Some formats may efficiently implement decimation into a buffer by reading from lower resolution overview images.
For highest performance full resolution data access, read and write on "block boundaries" as returned by GetBlockSize(), or use the ReadBlock() and WriteBlock() methods.
This method is the same as the C GDALRasterIO() function.
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 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. |
|
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. |
Returns:
CE_Failure if the access fails, otherwise CE_None.
CPLErr GDALRasterBand::ReadBlock |
( |
int |
nXBlockOff, |
|
|
|
int |
nYBlockOff, |
|
|
|
void * |
pImage |
|
|
) |
|
|
|
Read a block of image data efficiently.
This method accesses a "natural" block from the raster band without resampling, or data type conversion. For a more generalized, but potentially less efficient access use RasterIO().
This method is the same as the C GDALReadBlock() function.
See the GetLockedBlockRef() method for a way of accessing internally cached block oriented data without an extra copy into an application buffer.
Parameters:
nXBlockOff |
the horizontal block offset, with zero indicating the left most block, 1 the next block and so forth. |
|
nYBlockOff |
the vertical block offset, with zero indicating the left most block, 1 the next block and so forth. |
|
pImage |
the buffer into which the data will be read. The buffer must be large enough to hold GetBlockXSize()*GetBlockYSize() words of type GetRasterDataType(). |
Returns: CE_None on success or CE_Failure on an error.
The following code would efficiently compute a histogram of eight bit raster data. Note that the final block may be partial ... data beyond the edge of the underlying raster band in these edge blocks is of an undermined value.
CPLErr GetHistogram( GDALRasterBand *poBand, int *panHistogram )
{
int nXBlocks, nYBlocks, nXBlockSize, nYBlockSize;
int iXBlock, iYBlock;
GByte *pabyData;
memset( panHistogram, 0, sizeof(int) * 256 );
CPLAssert( poBand->GetRasterDataType() == GDT_Byte );
poBand->GetBlockSize( &nXBlockSize, &nYBlockSize );
nXBlocks = (poBand->GetXSize() + nXBlockSize - 1) / nXBlockSize;
nYBlocks = (poBand->GetYSize() + nYBlockSize - 1) / nYBlockSize;
pabyData = (GByte *) CPLMalloc(nXBlockSize * nYBlockSize);
for( iYBlock = 0; iYBlock < nYBlocks; iYBlock++ )
{
for( iXBlock = 0; iXBlock < nXBlocks; iXBlock++ )
{
int nXValid, nYValid;
poBand->ReadBlock( iXBlock, iYBlock, pabyData );
// Compute the portion of the block that is valid
// for partial edge blocks.
if( (iXBlock+1) * nXBlockSize > poBand->GetXSize() )
nXValid = poBand->GetXSize() - iXBlock * nXBlockSize;
else
nXValid = nXBlockSize;
if( (iYBlock+1) * nYBlockSize > poBand->GetYSize() )
nYValid = poBand->GetYSize() - iYBlock * nYBlockSize;
else
nYValid = nYBlockSize;
// Collect the histogram counts.
for( int iY = 0; iY < nYValid; iY++ )
{
for( int iX = 0; iX < nXValid; iX++ )
{
panHistogram[pabyData[iX + iY * nXBlockSize]] += 1;
}
}
}
}
}
GDAL中RasterIO函数(把文件读取为一个一维数组)和ReadBlock函数(读取栅格数据块)的更多相关文章
- linux中合并多个文件内容到一个文件的例子
尊敬的用户您好,从即日起 导入 及 导出 功能已经下线,请到阿里云官方数据库管理平台 iDB Cloud 使用该功能! 继续在 iDB Cloud 中发现导出的数据库文件是按照每个表生成的SQL文件, ...
- “在注释中遇到意外的文件结束”--记一个令人崩溃的bug
下午写程序,写的好好的,突然报错"在注释中遇到意外的文件结束". 下面是官方给出的错误原因是缺少注释终结器 (* /). // C1071.cpp int main() { } / ...
- shell脚本实例一,移动文件夹中大于2000B的文件到另一个文件夹
shell脚本能帮我们简化linux下的一些工作,现在有个需求,把TMPA文件夹下大于2000B的文件都移动到TMPB下 #! /bin/bash function movefiles() { ` d ...
- 在vi中打开多个文件,复制一个文件中多行到另一个文件中
:set number 查看行号1.vi a.txt b.txt或者vi *.txt 2.文件间切换 :n切换到下一个文件,:wn保存再切换 :N到上一个文件,:wN保存再切换 :.=看当前行 3.比 ...
- mysql函数取出单个字段重新组成一维数组
array_column():
- php 把一个一维数组的值依次赋值到二维数组中的每一项
Array( [0] => 1 [1] => 4 [2] => 2 [3] => 6 ) Array( [0] => Array ( [field_name] => ...
- JS 封装一个求数组最大值的函数
var aa = [1,2,3,4,9,2,5]; z(aa); function z(attr){ var b = 0 for(var i =1;i<aa.length;i++){ if(aa ...
- php文件加载、错误处理、方法函数和数组
数组运算符注意:php中,数组的元素的顺序,不是由下标(键名)决定的,而是完全由加入的顺序来决定.联合(+):将右边的数组项合并到左边数组的后面,得到一个新数组.如有重复键,则结果以左边的为准$v1 ...
- python 集合、函数和文件操作
1.set集合 set集合是一个无序.不可重复.可嵌套的序列,基本功能是进行成员关系测试和删除重复元素,可以使用大括号({})或者 set()函数创建集合,注意:创建一个空集合必须用 set() 而不 ...
随机推荐
- AutoCompleteTextView输入汉字拼音首字母实现过滤提示(支持多音字,Filterable的使用)
AutoCompleteTextView具有输入提示的功能,但是它的这种提示不适合对股票列表的过滤,如果你玩过股票软件,就会知道只要输入股票名称的首字母或股票代码就会出现符合匹配的股票,这种过滤怎么实 ...
- 分享8款绚丽的HTML5/jQuery特效插件
有几天没有分享前端资源了,今天要向大家分享15款非常给力的HTML5/jQuery特效插件,废话少说,一起来看看. 1.CSS3图片重力感应特效 很酷的一款CSS3模拟重力感应特效,你可以拖动图片来甩 ...
- java 图的邻接矩阵
有向图 在有向图中,结点对<x ,y>是有序的,结点对<x,y>称为从结点x到结点y的一条有向边,因此,<x,y>与<y,x>是两条不同的边.有向图中的 ...
- Android学习笔记之JSON数据解析
转载:Android学习笔记44:JSON数据解析 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,为Web应用开发提供了一种 ...
- Ubuntu下VSFTPD(六)(常见FTP命令及其功能) (
常见FTP命令及其功能 FTP 命令 功能 FTP 命令 功能 ls 显示服务器上的目录 ls [remote-dir][local-file] 显示远程目录remote-dir,并存入本地文件 ...
- 关于Spring IOC容器解释
何谓控制反转(IoC = Inversion of Control),何谓依赖注入(DI = Dependency Injection)?之前看到过两个比喻,觉得比较形象,特在此写下: IoC,用白话 ...
- Unity3D 使用脚本来控制 UI 的 Image 显示的图片。
记录一下这个问题. 原文地址:http://tieba.baidu.com/p/3561719701 object obj = Resources.Load(资源名, typeof(Sprite)); ...
- Handsontable 学习笔记-Methods
Handson: 亲自实践 先给出数据源和基本配置: var data =[ ["A1","B1","C1","D1"] ...
- Android 4.4 新特性分析-15项大改进!
Google发布了Android 4.4 KitKat,并其同时面世的还有新旗舰Nexus 5.Android 4.4 KitKat有怎样的改进.是否值得升级呢,下面就为大家呈现Android 4.4 ...
- ASCII码表 char(9),char(10),char(13)等
char(9) 水平制表符 char(10) 换行 char(13) 回车 测试ASCII码的方法: 在记事本中,按住ALT键,同时用小键盘输入十进制的ASCII码,然后松手,就可以看到效果了! ...