Overlay a map on top of a 3d surface map in r

前端 未结 1 1844
失恋的感觉
失恋的感觉 2021-01-30 09:41

I have created a 3d map using rgl.surface(), mainly following Shane\'s answer in this post. Using my own data, I get this map

相关标签:
1条回答
  • 2021-01-30 09:55

    Modified above code to give an answer. Note that terrain should be a matrix in the same format as the elevation matrix. And I added a ,color argument to your function call so it actually uses the color matrix you created.

    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 讨论(0)
提交回复
热议问题