我已經使用rgl.surface()創建了一個3d地圖,主要是在Shane的this後的回答中。用我自己的數據,我得到這個地圖將地圖覆蓋在r表面上的地圖
在此表面上圖的頂部,我想補充地圖植被密度,使得我獲得這樣的事情(用軟件衝浪獲得):
是否有可能在r中與RGL要做到這一點,或與此有關的任何其他包,或有兩個地圖就像巴蒂爾的答案是唯一的解決辦法?
謝謝。
編輯:
繼@ GSK3的要求,這裏是這個地圖的代碼:
library(rgl)
# Read the z (i.e. elevation) dimension from file
z1 = matrix(scan("myfile.txt"),nrow=256, ncol=256, byrow=TRUE)
#create/open x y (i.e. easting and northing coordinates) dimensions
y=8*(1:ncol(z)) # Each point is 8 m^2
x=8*(1:nrow(z))
# See https://stackoverflow.com/questions/1896419/plotting-a-3d-surface-plot-with-contour-map-overlay-using-r for details of code below
zlim <- range(z)
zlen <- zlim[2] - zlim[1] + 1
colorlut <- terrain.colors(zlen,alpha=0) # height color lookup table
col <- colorlut[ z-zlim[1]+1 ] # assign colors to heights for each point
open3d()
rgl.surface(x,y,z)
因爲有65536我不能發佈高程代碼(即X * Y = 256 * 256)點,但它是一個看起來像這樣的矩陣
[,1] [,2] [,3] [,4] [,5]
[1,] 1513.708 1513.971 1514.067 1513.971 1513.875
[2,] 1513.622 1513.524 1513.578 1513.577 1513.481
等等。 相同的植被密度地圖,這是完全相同的格式,我有一個單一的值爲每個x * y點。我希望這能讓事情變得更清楚一點......?
編輯2,最終版本
這是我與R.產生的地圖我沒有傳說它尚未但這是東西,我會在以後的階段做。
這個最後的代碼是
library(rgl)
z1 = matrix(scan("myfile.txt"),nrow=256, ncol=256, byrow=TRUE)
# Multiply z by 2 to accentuate the relief otherwise it looks a little bit flat.
z= z1*2
#create/open x y dimensions
y=8*(1:ncol(z))
x=8*(1:nrow(z))
trn = matrix(scan("myfile.txt"),nrow=256, ncol=256, byrow=TRUE)
fv = trn*100
trnlim = range(fv)
fv.colors = colorRampPalette(c("white","tan4","darkseagreen1","chartreuse4")) ## define the color ramp
colorlut =fv.colors(100)c(1,seq(35,35,length.out=9),seq(35,75,length.out=30),seq(75,100,length.out=61))]
# Assign colors to fv for each point
col = colorlut[fv-trnlim[1]+1 ]
open3d()
rgl.surface(x,y,z,color=col)
非常感謝你對@ GSK3和@nullglob在this後對他們的幫助。希望這篇文章能夠幫助很多人!
有趣的問題,但很難回答,沒有更多的信息。請張貼您的代碼,如果您可以在某處使用您的地圖,或者至少可以描述它。一種可能性是將植被分數作爲彩色地圖,我非常確定'rgl.surface()'會支持....但是,如果沒有更多的信息,很難說。 –
有關信息,我不知道如何將植被分數作爲@ gsk3建議的顏色映射表,所以如果我能得到一個如何做到這一點的例子,那將是非常好的。謝謝。 – SnowFrog
只需更改所使用的所有顏色線,以使用地形矩陣而不是z矩陣.... –