2011-08-01 47 views
21

我已經使用rgl.surface()創建了一個3d地圖,主要是在Shane的this後的回答中。用我自己的數據,我得到這個地圖將地圖覆蓋在r表面上的地圖

enter image description here

在此表面上圖的頂部,我想補充地圖植被密度,使得我獲得這樣的事情(用軟件衝浪獲得):

enter image description here

是否有可能在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.產生的地圖我沒有傳說它尚未但這是東西,我會在以後的階段做。

enter image description here

這個最後的代碼是

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後對他們的幫助。希望這篇文章能夠幫助很多人!

+0

有趣的問題,但很難回答,沒有更多的信息。請張貼您的代碼,如果您可以在某處使用您的地圖,或者至少可以描述它。一種可能性是將植被分數作爲彩色地圖,我非常確定'rgl.surface()'會支持....但是,如果沒有更多的信息,很難說。 –

+0

有關信息,我不知道如何將植被分數作爲@ gsk3建議的顏色映射表,所以如果我能得到一個如何做到這一點的例子,那將是非常好的。謝謝。 – SnowFrog

+0

只需更改所使用的所有顏色線,以使用地形矩陣而不是z矩陣.... –

回答

8

修改上面的代碼給出答案。請注意,地形應該是與高程矩陣格式相同的矩陣。我在你的函數調用中添加了一個參數,color,所以它實際上使用了你創建的顏色矩陣。

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)) 

# Read the terrain types from a file 
trn = matrix(scan("terrain.txt"),nrow=256, ncol=256, byrow=TRUE) 

# See http://stackoverflow.com/questions/1896419/plotting-a-3d-surface-plot-with-contour-map-overlay-using-r for details of code below 
trnlim <- range(trn) 
trnlen <- trnlim[2] - trnlim[1] + 1 
colorlut <- terrain.colors(trnlen,alpha=0) # height color lookup table 
col <- colorlut[ trn-trnlim[1]+1 ] # assign colors to heights for each point 
open3d() 
rgl.surface(x,y,z,color=col) 
+0

非常感謝。我仍然沒有得到我想要的,但我認爲這是因爲我給你的顏色代碼不適合我想要的。我會解決您的建議,並在完成後發佈我的最終代碼和地圖。 – SnowFrog

+0

當然。感謝承諾在這裏跟進:-)。希望這些建議有幫助。 –