Skip to content

Instantly share code, notes, and snippets.

@SimonCoulombe
Created June 18, 2019 00:49
Show Gist options
  • Save SimonCoulombe/b1b6394c623eeb4c92520392dc4f5b2d to your computer and use it in GitHub Desktop.
Save SimonCoulombe/b1b6394c623eeb4c92520392dc4f5b2d to your computer and use it in GitHub Desktop.
cant detect water
require(tidyverse)
ex.df <- data.frame(x=seq(from= -70.5813 , to= -70.36120, length.out=100),
y=seq(from= 47.80355 , to= 47.96210, length.out=100))
elev_raster <- elevatr::get_elev_raster(
ex.df,
prj = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",
z = 10,
clip = "bbox")
rayshader::detect_water(raster::as.matrix(elev_raster) ) %>%
raster::raster() %>%
raster::plot()
#no water except on the edge according to the plot
# satellite images show a rive going through the box
# 47.884566, -70.479631
https://www.google.com/maps/place/47%C2%B053'04.4%22N+70%C2%B028'46.7%22W/@47.8886556,-70.4874518,14z/data=!4m5!3m4!1s0x0:0x0!8m2!3d47.884566!4d-70.479631
@tylermorganwall
Copy link

The resolution of your map is too low. detect_water() looks for continuously flat areas of minimum size, but if the map is too low resolution and the bodies of water are small (e.g. rivers and streams) it can't detect them. Here, I upped the resolution of the map and ran detect_water with some slightly different arguments and successfully detected some of the water. Try adjusting min_area and cutoff around until you get a reasonable performance.

ex.df <- data.frame(x=seq(from= -70.5813  , to= -70.36120, length.out=100), 
                    y=seq(from=  47.80355 , to=  47.96210, length.out=100))
elev_raster <- elevatr::get_elev_raster(
  ex.df, 
  prj = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", 
  z = 14,
  clip = "bbox")
mat = raster::as.matrix(elev_raster)

normal_vectors = rayshader::calculate_normal(mat)

mat %>%
  sphere_shade(normalvectors = normal_vectors) %>% 
  add_water(detect_water(mat,zscale=10, cutoff=0.999,min_area = 10000,normalvectors = normal_vectors)) %>%
  plot_map()

Rplot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment