通过像素二进制文件交织成​​光栅格转换带 [英] Converting band interleaved by pixel binary files into raster grids

查看:231
本文介绍了通过像素二进制文件交织成​​光栅格转换带的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个BIP二进制文件 https://drive.google.com/open?id=0BwkLXkUMkLd4SnBmUHNmMW5CcDg
以下信息:

  NCOL<  -  193
nrow< - 94
XMIN< - -180
XMAX< - 180
YMIN< - -88.542000
YMAX< - 88.542000

该文件有365乐队,我希望能够将它们转换成光栅网格(光栅堆栈)。
我可以在R读取这些文件,但我不知道该如何处理带。以下是我迄今所做的:

  CNT<  -  NCOL * nrow * 365
数据< - readBin(文件,内容=双规,N = CNT,大小= 4,尾数= .Platform $端)
data.m< - 矩阵(数据,NCOL = 193,nrow = 94)#我不知道如何添加带
data.r< - 栅格(data.m,XMN = XMIN,XMX = XMAX,YMN = YMIN,YMX = YMAX)
图(data.r)


解决方案

使用光栅::砖,因为它是建立一个基于多频段,包括BIL和BIP文件多波段栅格的功能。
如果碰巧不承认你的GEOREF的数据,你可以输入它作为参数时,读取文件:NCOLS = 193,XMN = -180,XMX = 180,YMN = -88.542000,YMX = 88.542000,NL = 365

下面是根据您所提供的文件中的一个示例实现。既然不承认为BIP文件,你首先要阅读它,并将它转换成一个三维数组。然后,你可以简单地使用它与砖命令来创建栅格堆栈。现在,棘手的事情是,如果在砖的命令不兼容的订单,让您拥有的数据文件的尺寸使用aperm功能调换的尺寸。在此之后,它是直线前进整个数组转换成一个地理参考堆栈。

  WD =D:/温度/
setwd(WD)
库(光栅)
NCOL< - 193
nrow< - 94
nbands< - 365
CNT< - NCOL * nrow * nbands
数据< - readBin(Tavg.dat什么=双规,N = CNT,大小= 4,尾数= .Platform $端)
数据2 =阵列(数据,C(nbands,NCOL,nrow))
数据2< - aperm(数据2,C(3,2,1))#for移调
raster_brick =砖(DATA2,XMN = -180,XMX = 180,YMN = -88.542000,YMX = 88.542000)
积(raster_brick [[1]])

这是第一个波段的图像:

I have a BIP binary file https://drive.google.com/open?id=0BwkLXkUMkLd4SnBmUHNmMW5CcDg with the following information:

ncol <- 193 
nrow <- 94  
xmin <- -180
xmax<-  180
ymin <- -88.542000
ymax <- 88.542000

The file has 365 bands, I want to be able to convert them into raster grids (raster stack). I can read the files in R, but I don't know how to deal with the bands. Here is what I have done so far:

cnt <- ncol*nrow*365
data <- readBin(file,what= "double", n=cnt, size=4,endian=.Platform$endian)
data.m <- matrix(data, ncol=193, nrow=94) # I don't know how to add the bands
data.r <- raster(data.m, xmn=xmin, xmx=xmax, ymn=ymin, ymx=ymax)
plot(data.r)

解决方案

Use raster::brick as it is a function to create multi-band rasters based on files with multiple bands including BIL and BIP. If it by chance does not recognize your georef data, you can input it as arguments when reading the file: ncols=193, xmn=-180, xmx=180, ymn=-88.542000, ymx=88.542000, nl=365.

Here is an example implementation based on the file you provided. Since it was not recognized as a BIP file, you first have to read it and convert it into an 3D array. Then you can simply use it with the brick command to create the raster stack. Now, the tricky thing is that the dimensions of the data file where in an order incompatible with the brick command, so you have to transpose the dimensions using the aperm function. After that, it is straight forward to convert the entire array into a georeferenced stack.

wd="D:/temp/"
setwd(wd)
library(raster)
ncol <- 193 
nrow <- 94  
nbands <- 365
cnt <- ncol*nrow*nbands
data <- readBin("Tavg.dat",what= "double", n=cnt, size=4,endian=.Platform$endian)
data2=array(data,c(nbands, ncol, nrow))
data2 <- aperm(data2, c(3,2,1)) #for transposing
raster_brick=brick(data2, xmn=-180, xmx=180, ymn=-88.542000, ymx=88.542000)
plot(raster_brick[[1]])

Here is the first band image:

这篇关于通过像素二进制文件交织成​​光栅格转换带的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆