milos-agathon / tree-height-maps-meta

In this repo, I'll guide you through the process of downloading the latest tree canopy height data from Meta and the World Resources Institute, with a detailed resolution of 1 meter. You'll learn how to create clear static maps using ggplot2 in both light and dark themes, as well as interactive maps with leaflet
10 stars 2 forks source link

Error in main.r code: object 'city_chm_new' not found before plotting #1

Open amanjayedi opened 4 months ago

amanjayedi commented 4 months ago

I encountered an error when running the example code provided for plotting tree height data. The error message was:

"Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'city_chm_new' not found"

This occurs because city_chm_new is being used in terra::plot() before it is defined.

Suggested Fix:

Reorder the operations in the script to define city_chm_new before it is used in the terra::plot() function. Here is the corrected sequence:

3. GET TREE HEIGHT DATA

------------------------

city_chm <- chmloader::download_chm( city_coords, filename = "oslo-chm.tif" )

Handle zero values

city_chm_new <- terra::ifel( city_chm == 0, NA, city_chm )

Now plot city_chm_new

terra::plot( city_chm_new, col = hcl.colors( 64, "viridis" ) )

milos-agathon commented 4 months ago

Thank you for spotting and letting me know of the error! I'll add the changes you suggested