在 QGIS 中開啟 BIL、BIP 或 BSQ 格式檔案

在處理遙測和科學資料時,常會遇到像是 BILBIPBSQ 類型的格式。QGIS 用來讀取影像資料的 GDAL 函式庫有支援此類格式,但它沒有辦法直接開啟這些檔案。這裡我們要展示如果從此格式建立相關的支援檔案,讓它們可以在 QGIS 中讀取。

波段依行交錯排列 (Band interleaved by line,BIL)、波段依像素交錯排列 (Band interleaved by pixel,BIP),與波段序排列 (Band sequential,BSQ) 是三種常用於多波段影像儲存的格式。(更多資訊請參考這裡)

一般來說,這些檔案都會附有一個 .hdr 檔。如果你的資料集之中有 .hdr 檔,請務必確認 .bil、.bsq 或 .bip 的主檔名與 .hdr 檔相同,而且他們必須在同一個資料夾之中。舉例來說,如果有個檔案名稱為 image.bil,伴隨的檔案應為 image.hdr,而且會與 image.bil 位在相同資料夾。如此一來,當你選擇 圖層 ‣ 加入影像圖層,然後開啟 image.bil 時,就不會出現任何問題。

有些時候,這些檔案偏偏就是沒有 .hdr 檔。這種情況下,你需要利用本教學的方法自己創造一個才行。

取得資料

我們要使用 全球土地覆蓋設施(Global Land Cover Facility)提供的 AVHRR 全球土地覆蓋分類資料(Global Land Cover Classification data)作為示例。

此資料集以 BSQ 檔發布。下載像素解析度 1 度的資料集

為了方便起見,你也可以直接用下面的連結下載:

gl-latlong-1deg-landcover.bsq.gz

資料來源 [GLCF]

操作流程

  1. 解壓縮並取出 .bsq 檔:如使用 Windows,可以使用 7-Zip 讀取和解壓縮 .gz 檔。你會看到壓縮檔中只有一個叫做 gl-latlong-1deg-landcover.bsq 的 .bsq 檔,沒有 hdr 檔。

../_images/1196.png
  1. 如果你嘗試在 QGIS 中開啟 gl-latlong-1deg-landcover.bsq 的話,會有錯誤訊息顯示。

../_images/2160.png
  1. 如要克服此錯誤,我們得自己創造一個副檔名為 .hdr 的檔案。hdr 意味著檔頭(header),內含著資料集的結構以及各種資訊。這些資訊通常可以在資料集的詮釋資料(Metadata)中找到,如果你連詮釋資料都沒有,找看看資料來源的網站或文件說明有沒有提供。有些資訊就算你不知道,也可以用猜的。在本例中,資料的下載頁面有提供連結至詮釋資料,把它下載下來然後開啟它。

../_images/3100.png
  1. .hdr 檔必須要是純文字檔案,並且編排為以下的格式才行。我們已經找到某些參數了,但其他的還需要花點心力。格式的細節請參考這裡

ncols <number of columns or width of the raster>
nrows <number of rows or height of the raster>
cellsize <pixel size or resolution>
xllcorner <X coordinate of lower-left corner of the raster>
yllcorner <Y coordinate of the lower-left corner of the raster>
nodata_value <pixel value to be ignored>
nbits <number of bits per pixel>
pixeltype <type of values stored in a pixel, typically float or integer>
byteorder <byte order in which image pixel values are stored, msb or lsb>
  1. Open a text editor and create a file in the format specified in the previous step. Save the file as gl-latlong-1deg-landcover.hdr. Make sure the file doesn’t have .txt at the end. Some of the values in the text files are easy to understand. The ncols and nrows come from the metadata as the Number of Lines and Number of Pixels per Line. The cellsize is 1 as the Pixel resolution from the metadata. The X,Y coordinate of lower-left corner needs to be worked out by us. Since the file covers the entire World and units are lat/long, xllcorner and yllcorner are -180 and -90 respectively. We do not have any information about the nodata_value, so -9999 is a safe bet. From metadata again, Pixel Format is Byte, so nbits will equal to 8 and pixeltype will be byte_unsigned. We do not have information about the byteorder, so leave it as msbfirst. You may download the correctly formatted HDR file from here.

../_images/557.png
  1. 現在我們有檔頭檔案了,把它移到與 gl-latlong-1deg-landcover.bsq 相同的目錄下,然後再 QGIS 中選擇 圖層 ‣ 加入影像圖層,選擇 gl-latlong-1deg-landcover.bsq 作為輸入檔案然後按下 開啟

../_images/655.png
  1. 接下來的視窗會要你選擇 CRS。由於檔案是以經緯度編排,這邊的 CRS 要選 WGS84 EPSG:4326。最後,你就可以看到 QGIS 已經載入本資料了。

../_images/754.png

If you want to give feedback or share your experience with this tutorial, please comment below. (requires GitHub account)