tif/image数据的读写
2023-01-05 14:26:04
115次阅读
1个评论
#include "rasterdataset/rasteraccessor.h"
using namespace EarthView::World::Core;
using namespace EarthView::World::Spatial2D::Raster;
using namespace EarthView::World::Spatial::GeoDataset;
//打开栅格数据集
EVString pszFullpathName = "C:/test.tif"; // tif数据的路径
CRasterDataSet* pDataSet = CRasterFileOperator::open(pszFullpathName, EV_READONLY);
ev_int32 iWidth = pDataSet->getRasterWidth(); //获取数据宽
ev_int32 iHeight = pDataSet->getRasterHeight(); //获取数据高
ev_int32 iBandCount = pDataSet->getBandCount(); //获取数据的波段数
EVRasterDataType iDataType = pDataSet->getRasterDataType(); //获取数据的数据类型
ev_int32 iDataTypeSize = CRasterDataSet::getDataTypeSize(iDataType);
ev_uchar* pDataBuffer = new ev_uchar[iWidth*iHeight*iDataTypeSize*iBandCount] //对于数据量较大的影像文件需要分块读取
//读取数据
pDataSet->rasterIO(IO_READ,0,0,iWidth,iHeight,iBandCount,0,pDataBuffer,iWidth,iHeight,iDataType);
CRasterFileOperator::close(pDataSet); //关闭数据集
//创建tif数据并写入数据
EVString pszOutName = "C:/test1.tif"; // tif数据的路径
CRasterDataSet* pDS = CRasterFileOperator::create(pszOutName,iWidth,iHeight,iBandCount,iDataType,RT_TIF); //创建tif
pDS->rasterIO(IO_WRITE,0,0,iWidth,iHeight,iBandCount,0,pDataBuffer,iWidth,iHeight,iDataType); //写入像素值
CRasterFileOperator::close(pDS); //关闭数据集
using namespace EarthView::World::Core;
using namespace EarthView::World::Spatial2D::Raster;
using namespace EarthView::World::Spatial::GeoDataset;
//打开栅格数据集
EVString pszFullpathName = "C:/test.tif"; // tif数据的路径
CRasterDataSet* pDataSet = CRasterFileOperator::open(pszFullpathName, EV_READONLY);
ev_int32 iWidth = pDataSet->getRasterWidth(); //获取数据宽
ev_int32 iHeight = pDataSet->getRasterHeight(); //获取数据高
ev_int32 iBandCount = pDataSet->getBandCount(); //获取数据的波段数
EVRasterDataType iDataType = pDataSet->getRasterDataType(); //获取数据的数据类型
ev_int32 iDataTypeSize = CRasterDataSet::getDataTypeSize(iDataType);
ev_uchar* pDataBuffer = new ev_uchar[iWidth*iHeight*iDataTypeSize*iBandCount] //对于数据量较大的影像文件需要分块读取
//读取数据
pDataSet->rasterIO(IO_READ,0,0,iWidth,iHeight,iBandCount,0,pDataBuffer,iWidth,iHeight,iDataType);
CRasterFileOperator::close(pDataSet); //关闭数据集
//创建tif数据并写入数据
EVString pszOutName = "C:/test1.tif"; // tif数据的路径
CRasterDataSet* pDS = CRasterFileOperator::create(pszOutName,iWidth,iHeight,iBandCount,iDataType,RT_TIF); //创建tif
pDS->rasterIO(IO_WRITE,0,0,iWidth,iHeight,iBandCount,0,pDataBuffer,iWidth,iHeight,iDataType); //写入像素值
CRasterFileOperator::close(pDS); //关闭数据集
0
0
2023-03-30 15:57:01
读取tiff,能读到高程还是影像吗
共1条
1