2

I'm trying to render a text using the rayshader package function render_label.

My raster in WGS84 UTM:

localtif = raster::raster("G:\\My Drive\\Dem_12m.tif")

Link to download the raster.

The elevation matrix:

elmat = matrix(raster::extract(localtif,raster::extent(localtif),buffer=1000),
               nrow=ncol(localtif),ncol=nrow(localtif))

My rgl render:

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color="desert") %>%
  add_shadow(ray_shade(elmat,zscale=3,maxsearch = 300),0.5) %>%
  add_shadow(ambmat,0.5) %>%
  plot_3d(elmat,zscale=10,fov=0,theta=135,zoom=0.75,phi=45, windowsize = c(1000,800))

Getting row and col number from x and y utm cordinates:

  xy<-rowColFromCell(localtif, extract(localtif,SpatialPoints(cbind( 678349.471, 9197957.733)), cellnumbers=TRUE)[1])

Render text:

  render_label(elmat,x=xy[2],y=xy[1], z=4000,zscale=50,
             text = "El Pico del Diablo",textsize = 10,linewidth = 5, freetype = F)

The text apeear in the wrong place in the DEM model. I got these xy values:

> xy
     row col
[1,] 611 278 

Using try-and-error I found the correct values are row = 180 and col = 278. I also receive this warning:

Warning message:
In rgl.texts(x = 278L, y = 103.72, z = -611L, text = "El Pico del Diablo",  :
  "bitmap" family only supports cex = 1
zx8754
  • 52,746
  • 12
  • 114
  • 209
Artur_Indio
  • 736
  • 18
  • 35

1 Answers1

0

I had the same issue and found a solution.

I have adapted your code as follows:

El_Pico_del_Diablo <- data.frame(lat= X.XX, long= -XX.XX) ###latitude and longitude in decimals. 

In my case my longitude location was negative.

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color="desert") %>%
  add_shadow(ray_shade(elmat,zscale=3,maxsearch = 300),0.5) %>%
  add_shadow(ambmat,0.5) %>%
  plot_3d(elmat,zscale=10,fov=0,theta=135,zoom=0.75,phi=45, windowsize = c(1000,800))

render_label(elmat, lat = El_Pico_del_Diablo$lat, long = El_Pico_del_Diablo$long,
             extent = attr(localtif, "extent"),
             altitude=100, zscale=10, text = "El Pico del Diablo",freetype=F, textsize = 5)
Dharman
  • 30,962
  • 25
  • 85
  • 135
EstebanG
  • 3
  • 1