[英]Can't plot image which is converted from a raster
我將光柵轉換為圖像並想要 plot 它。 但是,然后我收到以下錯誤:
library(raster)
r
#class : RasterLayer
#dimensions : 23320, 37199, 867480680 (nrow, ncol, ncell)
#resolution : 0.02, 0.02 (x, y)
#extent : 341668.9, 342412.9, 5879602, 5880069 (xmin, xmax, ymin, ymax)
#crs : +proj=utm +zone=33 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
#source : r_tmp_2022-07-21_113344_507_06340.grd
#names : layer
#values : 2.220446e-16, 0.2999999 (min, max)
x <- maptools::as.im.Rasterlayer(r)
x
#real-valued pixel image 23320 x 37199 pixel array (ny, nx)
#enclosing rectangle: [341670, 342410] x [5879600, 5880100] units
plot(x)
#Error in (function (x = seq(0, 1, length.out = nrow(z)), y = seq(0, 1, :
#‘useRaster = TRUE’ can only be used with a regular grid
我已經嘗試通過 help(plot) 或其他東西找到這個錯誤,但在任何地方都沒有任何關於它的內容。
是的。 所以我的光柵看起來像這樣: 我的光柵:
class: RasterLayer dimensions: 23320, 37199, 867480680 (nrow, ncol, ncell) resolution: 0.02, 0.02 (x, y) extent: 341668.9, 342412.9, 5879602, 5880069 (xmin, xmax, ymin, ymax) crs: +proj= utm +zone=33 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 來源:r_tmp_2022-07-21_113344_507_06340.grd 名稱:層值:2.220446e-16, 0.2999999 (min,最大限度)
我使用 maptools package 中的 as.im.Rasterlayer 將其轉換為圖像。 之后我只想 plot 這個圖像。 轉換成圖片后是這樣的:
實值像素圖像 23320 x 37199 像素陣列 (ny, nx) 包圍矩形:[341670, 342410] x [5879600, 5880100] 單位
我用 raster() 加載了光柵。 我正在使用 raster、spatstat、maptools。
將來,請提供一個最小的工作示例 - 生成錯誤的實際數據和代碼。
每當您遇到錯誤時,我建議您立即輸入
traceback()
查看執行的功能序列。 (打印輸出是回溯:它以產生錯誤的 function 開頭,然后列出調用它的 function,依此類推,直到到達您最初鍵入的命令行。)這通常會告訴您在哪里查看。
Since you are plotting an object of class im
, and plot
is a generic function, the relevant help file is for the method plot.im
, ie you should type help(plot.im)
or ?plot.im
, not help(plot)
.
由於我們沒有工作示例,因此我們無法為您調試。 但是這個特殊的錯誤可能來自 R 基礎圖形 function image.default
並且它顯然抱怨數據中的x
和y
坐標似乎不是等距的。 您可以嘗試在plot
命令中設置useRaster=FALSE
,或者修復數據。
一些包以非常小的量改變圖像中像素的x
和y
坐標,使得其他包“認為”坐標不是等距的。 在spatstat
中有一個 function repair.image.xycoords
可用於修復此類數據。 因此,如果Z
是您的圖像,請使用
ZZ <- repair.image.xycoords(Z)
修復坐標,然后 plot ZZ
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.