3D forest height maps with ggplot2 and rayshader in R

Поделиться
HTML-код
  • Опубликовано: 7 авг 2024
  • In this tutorial, I will show you how to use ggplot2 and rayshader in R to make powerful 3D maps of forest canopy height using the ETH Global Canopy Height dataset. You will learn how to download and process the data, and how to render a crisp 3D map of forest height in Portugal. Whether you are a beginner or an expert in R, this tutorial will help you unleash your creativity and explore the beauty and diversity of forests around the world.🌲🌳🌴
    0:00 Prologue
    0:58 Intro
    01:37 Load libraries
    05:07 Twitter post on ETH data
    05:43 Grab tile links
    09:22 Download tiles
    12:36 Portugal regions polygon
    16:34 Plot Portugal regions
    16:50 Filter regions and union polygons
    20:14 Plot Portugal polygon
    20:26 Load tiles as list
    22:15 Crop tiles
    24:17 Merge tiles into mosaic
    25:10 Aggregate forest height raster
    27:06 Raster to dataframe
    28:07 Rename value column
    28:46 Legend breaks
    31:32 Color palette
    33:14 2D map with ggplot2
    43:19 Render scene
    48:44 Show scene
    49:12 Change the scene
    50:18 Show re-adjusted scene
    50:35 Render object with rayshader
    58:17 3D forest height map of Portugal
    59:11 Closing
    Check the full code in my GitHub repo:
    github.com/milos-agathon/3d-f...
    Follow my work on Instagram:
    / milos_makes_maps
    Let's connect on Twitter:
    / milos_agathon
    If you like my work, consider buying me a coffee:
    www.buymeacoffee.com/milospop...
    Video credits:
    ---------------------------------
    No Copyright Videos & Musics / @nocopyrightvideosandm...
    Music credits:
    ---------------------------------
    Song: Sappheiros - Embrace (Vlog No Copyright Music)
    Music promoted by Vlog No Copyright Music.
    Video Link: • Sappheiros - Embrace (...

Комментарии • 92

  • @vishalmishra3590
    @vishalmishra3590 5 месяцев назад +1

    Milos you are amazing! Thanks a lot for teaching all of us this

  • @AleksPopovic
    @AleksPopovic 11 месяцев назад +5

    Whoa, this looks great! Love the 3d stuff you put up every time!

    • @milos-makes-maps
      @milos-makes-maps  11 месяцев назад

      Thanks Aleks! I enjoy creating and sharing the 3d rendering tutorials

  • @daniela_rondon
    @daniela_rondon Год назад +1

    Wow, just amazing!!! Thank you for sharing

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      Hi Daniela, you’re very welcome! I’m so happy to hear that you found the tutorial amazing. You made my day with your comment. 😊

  • @cahierCanada
    @cahierCanada 7 месяцев назад +1

    Amazing! Thank you so much!

  • @mahatmaalimibrahim6631
    @mahatmaalimibrahim6631 Год назад +1

    Fantastic as usual. Thank you.

  • @brunob.7792
    @brunob.7792 Год назад +5

    i was able to reproduce this! After almost 1hour rendering on a Ryzen 5600x 326g DDR4 ram 3600mhz, i was able to achieve the portugal map.png image on the directory. Also, i was able to watch the whole rendering process. It was amazing! Do amazon rainforest buddy! We brazilians, want to know how the situation is over here with illegal harvesting happening all the time!

    • @milos-makes-maps
      @milos-makes-maps  Год назад +1

      Wow, that's incredible! I hope you didn't fry your CPU 🤯. I might give it a try with Amazon in the future! Thanks for trying out my new tutorial and happy that it worked for you!

    • @santiago_s
      @santiago_s Год назад

      @@milos-makes-maps i'm trying with a laptop :( lol!
      How works with Amazon? Could you teach us?

    • @strangerr4980
      @strangerr4980 6 месяцев назад

      @@milos-makes-mapsWhat are the your computer operating system and graphics card specifications? and what time did you create this map sir?

  • @zhengpengfei6047
    @zhengpengfei6047 Год назад +1

    What a great work!Thank you!

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      Thank you for your kind words! I’m glad you enjoyed the tutorial and found it useful. I appreciate your support and encouragement. 😊

  • @akshitgautam4206
    @akshitgautam4206 10 месяцев назад +1

    Really like your work!

  • @johneagle4384
    @johneagle4384 10 месяцев назад +1

    Wow, this is so cool!!!

  • @elisaurysuarez5927
    @elisaurysuarez5927 2 месяца назад +1

    ¡Great!

  • @jacksonkimani3336
    @jacksonkimani3336 Год назад +1

    Great work Sir Milos.. I am greatly inspired with this..

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      Thank you very much! I’m happy to hear that you are inspired by this. I hope you have fun creating your own 3D maps. 😄

  • @manivannansekar5026
    @manivannansekar5026 5 месяцев назад +1

    Amazing. make one tutorial for river please

    • @milos-makes-maps
      @milos-makes-maps  5 месяцев назад

      Hey, I've already created a tutorial on 3D river basin maps. Check it out on my channel!

  • @pallavshrestha5698
    @pallavshrestha5698 7 месяцев назад +1

    Hi Milos. I like the editor you are using in this video. Is it Sublime Text? The arguments visualising is pretty helpful, which I don’t find in Rstudio.

    • @milos-makes-maps
      @milos-makes-maps  7 месяцев назад +2

      Hi Pallav! These days I use VSCode and I have a tutorial that walks you through the process of installing and setting up R in VSCode here: ruclips.net/video/k79H8EeR5Jo/видео.html

  • @haipokung7926
    @haipokung7926 7 месяцев назад +1

    good figure❤❤❤

  • @elisaurysuarez5927
    @elisaurysuarez5927 2 месяца назад +1

    My computer literally explodes with that render

  • @christostheocharidis2037
    @christostheocharidis2037 Год назад +1

    Great turotial thank you very much. I have also an issue, when I run the classInt: classIntervals, It takes ages to run and never run it. I chose a different study area and I put n = 5 so the dimensions are 1149, 2893 (smaller than the video) but it still do nothing. Is it normal? should I leave it to run ?

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      Thanks! Really sorry to hear that you have such serious optimization issues with classInt. What is the style that you use? Can you try quantile or equal? Also, if it doesn't work you could also skip that part

    • @christostheocharidis2037
      @christostheocharidis2037 Год назад +1

      @@milos-makes-maps It ran eventually with the fisher method but after one hour approximately.

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      @@christostheocharidis2037 wow 😨, that doesn't sound good!

  • @MrMaubitch
    @MrMaubitch 7 месяцев назад +1

    Very nice video! Unfortunately, the link to download the cloud optimized geotiffs seems to be offline/not working. Waiting for it to work and try out your awesome tutorial!

    • @milos-makes-maps
      @milos-makes-maps  7 месяцев назад +2

      Thank you! They messed up something with the page 😔. But I found the solution. You should download this html file and open it via your browser: libdrive.ethz.ch/index.php/s/cO8or7iOe5dT2Rt/download?path=%2F&files=tile_index.html

  • @mirkodelfinsoruco8686
    @mirkodelfinsoruco8686 Год назад +1

    I generated a mosaic based on an image from ggogle earth and saved it as a png, but I get the following error (Error in rayrender::obj_model(cache_filename, x = -bbox_center[1], y = -bbox_center[2], :
    unused argument (texture = TRUE)

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      Could you please install the latest newest version of rayshader using devtools::install_github("tylermorganwall/rayshader")

  • @imranhossain934
    @imranhossain934 2 месяца назад +1

    First of all thenk you for the wonderful tutorial. But I didn't find any map with tiles from where I can download geotiffs. The linh "cloud optimized geotiffs here" is taking me in the another page. So, it would be very nice if you can help me regarding this matter.

    • @milos-makes-maps
      @milos-makes-maps  2 месяца назад +1

      Hello! Firstly, a huge thank you for the positive feedback on the tutorial-it's fantastic to know it resonated with you! I'm sorry for any trouble caused by the link issue. It appears the files have been relocated.
      Good news, though! You can access the interactive tile map by downloading the HTML file from this link:
      libdrive.ethz.ch/index.php/s/cO8or7iOe5dT2Rt/download?path=%2F&files=tile_index.html
      Once downloaded, simply open the file in a web browser, and you'll be all set!

    • @imranhossain934
      @imranhossain934 2 месяца назад +1

      Hello Sir.. Thank you very very much for your kind help.. I successfully made the forest height map of Sundarbans Mangrove Forest in Bangladesh. It was a wonderful experience for me.. Thank you angain..

  • @h.rainakkhanreal3090
    @h.rainakkhanreal3090 5 месяцев назад

    Hi Milos, amazing tutorial. However, I am getting stuck in Section 5. Breaks classInt: classIntervals. This part of the code in Rstudio keeps on running forever, with no output. I left it running for 8 hours and finally had to interrupt and close R. This happened both for Portugal and Bangladesh. Is there any solution to this? I am using an intel i9 RTX 4080 laptop.
    I would like to add:
    - when trying 'equal' and 'quantile', the output is immediate. It is the style = 'fisher' that's causing this issue. Equal/quantile style maps look pretty bad for Bangladesh, with canopy height of 1m covering majority of the country.

  • @sohom-
    @sohom- 8 месяцев назад +1

    I am getting this error in the last step of "rendering object". Can you help me with this please.
    Error in if (id) rgl.attrib.count(id, "colors") else rgl.getcolorcount() :
    argument is not interpretable as logical

    • @milos-makes-maps
      @milos-makes-maps  8 месяцев назад

      Hey, it seems that you are getting an error when using the `plot_gg()` function from the `rayshader` package in R. This error is caused by an incompatibility between the `rayshader` and `scales` packages, which are used to create the hillshade and shadow effects on the plot.
      There are a few possible solutions to this problem:
      - You can try to install the latest development versions of the `rayshader` and `rayrender` packages from GitHub, which may have fixed this issue. To do this, you need to run the following commands in R:
      ```r
      # if package is missing, run `install.packages("remotes")` first
      remotes::install_github("tylermorganwall/rayshader")
      remotes::install_github("tylermorganwall/rayrender")
      ```
      - You can try to adjust the `width` and `height` parameters of the `plot_gg()` function to match the aspect ratio of your plot. For example, if your plot is square, you can use `width = 4000` and `height = 4000`.
      - You can try to remove and reinstall the `rayshader` package from CRAN, and restart your session

  • @Aztech501
    @Aztech501 5 месяцев назад +1

    Hi, Milos.
    I am geting stuck in section 3 (cropping tiles). This part of the code stops showing the next error: Error: [crop] file exists. You can use 'overwrite=TRUE' to overwrite it. If I add this statement to crop function, it works correctly but it doesn't crop properly. Is there any solution to this? The .tiff files are already in the same working folder

    • @milos-makes-maps
      @milos-makes-maps  5 месяцев назад +1

      Hi, this is the problem with the terra package. The owner of terra suggests to install the latest development (GitHub) version of the package. If the problem persists please reach to the owner of terra

  • @mirkodelfinsoruco8686
    @mirkodelfinsoruco8686 Год назад +1

    from where you get the png map of "portugal-forest-height-2020.png)

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      Hey, you can find it on the project's website that I showed in the tutorial before you load the data part

  • @user-tm8ck3qx2b
    @user-tm8ck3qx2b 8 месяцев назад

    Hello sir, If I've already download the raster with the download code and want to do rest of the process later. is it possible to run the the rest of the code? or need to download again?

    • @milos-makes-maps
      @milos-makes-maps  8 месяцев назад

      Hi, can you, please, run one code chunk at a time so that we can determine where the code breaks first? Also, please make sure that the downloaded files are in your working directory

  • @avirals_space2917
    @avirals_space2917 6 месяцев назад +1

    Sir am getting constant error of "libs' file not found..what can i do?

    • @milos-makes-maps
      @milos-makes-maps  6 месяцев назад

      Please make sure that you create the libs object by running the code lines 6-9

  • @codeessentialske
    @codeessentialske Год назад

    Nice work. Which code editor is this?

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      Thanks! This is VSCode

    • @strangerr4980
      @strangerr4980 7 месяцев назад

      @@milos-makes-maps also we have created this in r- stusio?

  • @user-nc1xm6nm6x
    @user-nc1xm6nm6x 4 месяца назад

    m just little confused ,is the commands used directly in r studio or did in vscode

  • @boi_ratie
    @boi_ratie 9 месяцев назад +1

    This is a lovely tutorial. I tried to replicate it on my own but i kept encountering this error (/Forests/ETH_GlobalCanopyHeight_10m_2020_N36W009_Map.tif' not recognized as a supported file format. (GDAL error 4) ) the workig directory if the same as the script and the files and i tried to reload the packages but its stil not working. Your assistance wil be highly appreciated.

    • @milos-makes-maps
      @milos-makes-maps  9 месяцев назад

      Thank you so much! I'm sad to hear that my code doesn't work for you. Can you tell me if this error occurs on Mac or Windows? Also, what is the part of the code that triggers the error?

    • @Gomey.
      @Gomey. 9 месяцев назад +1

      @@milos-makes-maps Hi Milos Awesome tutoring. I am running into the same issue.I am running the code on windows. If you don't mind helping out this is the exact error I get Error: [rast] cannot open this file as a SpatRaster: C:/Users/pathtofolder/ETH_GlobalCanopyHeight_10m_2020_N36W009_Map.tif.

    • @milos-makes-maps
      @milos-makes-maps  9 месяцев назад

      @@Gomey. Hey, what is the part of my script that returns this error?

    • @Gomey.
      @Gomey. 9 месяцев назад +1

      @@milos-makes-maps Hi Milos,
      its this part I think it has something to do with the terra::rast part.
      I also tried it by setting the full.names = F when defining he raster_files to see if without the folder directory and only the file name it would reader but that had no impact.
      forest_height_list

    • @milos-makes-maps
      @milos-makes-maps  9 месяцев назад

      @@Gomey. Hmmm, can you confirm that you have raster files in your working directory? Also, if you are working with a single raster file you shouldn't be using `lapply`. It's sufficient to use terra::rast("raster.tif"), where "raster.tif" is the name of your raster file

  • @technoplus6895
    @technoplus6895 7 месяцев назад +1

    after rendering i got totally pink png,why is that

    • @milos-makes-maps
      @milos-makes-maps  7 месяцев назад

      That's not good. Can you check if you downloaded the tiles and loaded them into R?

  • @johanesmachela
    @johanesmachela Год назад +1

    Greetings, and thank you for your incredible efforts! I am highly interested by this project, and I made an attempt to replicate the work by utilizing your provided code. unfortunately, I encountered an issue when attempting to run it. especially at this function
    forest_height_mosaic

    • @milos-makes-maps
      @milos-makes-maps  Год назад +1

      Greetings! Thanks for your kind words and for your interest in my tutorial! Your message tells me that a missing object rather than SpatRaster was passed to terra. This would suggest that forest_height_rasters could be empty. If this is true, then you need to check if you are loading the raster files from your designated working directory. Can you, please, check if this is the case?

    • @johanesmachela
      @johanesmachela Год назад +1

      @@milos-makes-maps Yes its, some place there is empty.

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      @@johanesmachela Ok, so the next step is to make sure that the place where you downloaded your raster files is the same as your working directory in R. Can you check if they match? getwd() is the command in R to print your current working directory

  • @jdaking7648
    @jdaking7648 6 месяцев назад +1

    Where are these packages installed from?

    • @milos-makes-maps
      @milos-makes-maps  6 месяцев назад +1

      CRAN if it's a released version, or a GitHub repo if it's a development version

    • @jdaking7648
      @jdaking7648 6 месяцев назад +1

      Great, thank you sir

  • @shynei6601
    @shynei6601 5 месяцев назад +1

    Hi Milos, very nice tutorial. Unfortunately, I have weird things happening.. If you, or someone else can help me please
    I've taken the data from France.
    At the step of plotting the map with ggplot, it only renders a part of the map (I have downloaded all the data I need) and shows me this warning message:
    "
    Warning message:
    Raster pixels are placed at uneven horizontal intervals and will be shifted
    Consider using `geom_tile()` instead.
    "
    I tried to use geom_tile() but it didn't work.
    Also, in the next step (yes, I tried even though the one before was weird), it didn't render anything (I got a white window), and gave me some weird errors/warnings:
    "
    Error: '\U' used wError: '\U' used without hex digiError: '\U' used without hex digits in character string (:4:36)
    Error: '\U' used without hex digits in character string (:4:36)
    Errorror: '\U' using (:4:36)Execution halted
    Executi: '\U' useded without hex digits without hex digits in character string (:4:36)
    in cExecution halted
    on halted
    Execution halt
    Execution halted
    iExecution halted
    ts in characteng (:r string 4:36)
    haract(Eer strinxecution hg (:4:36:4:36)
    d
    Execution halted
    Error in makePSOCKcluster(names = spec, ...) :
    Cluster setup failed. 12 of 12 workers failed to connect.
    In addition: Warning messages:
    1: Raster pixels are placed at uneven horizontal intervals and will be shifted
    Consider using `geom_tile()` instead.
    2: Raster pixels are placed at uneven horizontal intervals and will be shifted
    Consider using `geom_tile()` instead.
    "
    Thanks

    • @milos-makes-maps
      @milos-makes-maps  5 месяцев назад

      Hey, it's a pity that you can't replicate my code. You can ignore the warning message. About the long and obscure error: please update rayshader with all it's dependencies

    • @shynei6601
      @shynei6601 5 месяцев назад +1

      @@milos-makes-maps ​Thank you for your help, updating rayshader and all it's dependencies didn't help. However, I found that making the multicore parameter to false fixed the error for me.

  • @camilaberger2980
    @camilaberger2980 Год назад +1

    For me it shows this error when try to create the forest hight rasters
    Error in (function (classes, fdef, mtable) :
    unable to find an inherited method for function ‘mosaic’ for signature ‘"SpatRaster", "missing"’

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      Hey, this error suggests that no raster files were passed to terra::mosaic so I wonder if you set the working directory to the same place where you downloaded the raster files. Does that help?

    • @camilaberger2980
      @camilaberger2980 Год назад +1

      ​@@milos-makes-maps ahh did not clarify, i am sorry, with portugal it worked, but i am doing with another country (Paraguay) with one raster only, and it show the messege i sent. I already check and it is the same with portugal archives, same directory. The "forest_height_rasters" is loaded, but when i run the "forest_height_mosaic" which is the next code it didnt and shows me the that msg. I also loaded this raster in qgis and it worked fine. Do you know a code that i just use an already download raster? besides when i closed and loaded de portugal project it does not load well, it seems i have to erase the download rasters from the directory and start all again.

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      @@camilaberger2980 thanks for clarifying the example! If you are working with a single raster file you don't have to turn it into a mosaic. In fact, you can just load it into terra with terra::rast.

    • @camilaberger2980
      @camilaberger2980 Год назад +1

      Thank you very much @@milos-makes-maps. Now it shows "Error: memory exhausted (limit reached?)" can I just cut this raster in qgis to exacly the area that i wanted bc i want just a tiny area. I unior in R, thats why the basic cuestions, i apoligize.

    • @milos-makes-maps
      @milos-makes-maps  Год назад

      @@camilaberger2980 ahh that's annoying, I had that error popping up on MacBook frequently. You can definitely cut the area in QGIS and use terra::rast to load it into R

  • @Rohit-tx7bm
    @Rohit-tx7bm 7 месяцев назад +1

    Which programming language use hare?