Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot fails with lasmetrics3d objects and boolean attribute #289

Closed
TedwardErker opened this issue Oct 17, 2019 · 5 comments
Closed

plot fails with lasmetrics3d objects and boolean attribute #289

TedwardErker opened this issue Oct 17, 2019 · 5 comments
Assignees
Labels
Bug A bug in the package Documentation Issue related to the documentation of the package

Comments

@TedwardErker
Copy link

TedwardErker commented Oct 17, 2019

Thank you for creating this package. It's truly incredible.

I found a small issue with plotting lasmetrics3d objects. I ran the example from "grid_metrics3d", the part that is not run fails to plot the colors.

## Not run:

# Define your own metric function
myMetrics = function(i)
{
   ret = list(
      npoints = length(i),
      imean   = mean(i))
   
   return(ret)
}
     
voxels = grid_metrics3d(las, ~myMetrics(Intensity), 3)
     
plot(voxels, color = "imean")
#etc.
## End(Not run) 

When I run the code above I get no error, but I also don't get any color. When I run with my own function I get this error: Error in col2rgb(colors) : invalid color name 'tree'.

Not a big deal I think I'll be able to find a work around, but wanted to put it up there. Thanks again for this amazing tool. I've only just started using it and I'm excited to find all it can do.

@Jean-Romain
Copy link
Collaborator

Could you please make a fully reproducible example. It works for me. You don't have any color because the color palette is broken by outliers. You can use trim = 100. The following do works as expected. I will update the doc to add trim = 100. However I'm not able to reproduce the error you mentionned.

library(lidR)

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las = readLAS(LASfile)

myMetrics = function(i) {
  ret = list(
    npoints = length(i),
    imean   = mean(i)
  )
  
  return(ret)
}

voxels = grid_metrics3d(las, ~myMetrics(Intensity), 3)
plot(voxels, color = "imean", trim = 100)

@Jean-Romain Jean-Romain self-assigned this Oct 17, 2019
@Jean-Romain Jean-Romain added the Documentation Issue related to the documentation of the package label Oct 17, 2019
@TedwardErker
Copy link
Author

TedwardErker commented Oct 17, 2019

Thank you. Setting trim fixed my visualization problem. I tracked down my error and think it was from my function not returning numeric (it was boolean).

For posterity, here's the reproducible example:

library(lidR)
Modes <- function(x) {
  ux <- unique(x)
  tab <- tabulate(match(x, ux))
  return(list(mode = ux[tab == max(tab)]))
}

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las = readLAS(LASfile)

# works great
gmclass <- grid_metrics3d(las, ~Modes(Classification), 3)
plot(gmclass, color = "mode", trim = 3)


lp <- lasdetectshape(las, shp_plane(th1 = 15, th2 = 4, k = 20), "Coplanar")
plot(lp, color = "Coplanar")

gmcoplanar <- grid_metrics3d(lp, ~Modes(Coplanar), 3)
# doesn't work
plot(gmcoplanar, color = "mode")


Modes_numeric<- function(x) {
  ux <- unique(x)
  tab <- tabulate(match(x, ux))
  return(list(mode = as.numeric(ux[tab == max(tab)])))
}

gmcoplanar <- grid_metrics3d(lp, ~Modes_numeric(Coplanar), 3)
# works now
plot(gmcoplanar, color = "mode", trim = 3)

@Jean-Romain
Copy link
Collaborator

Ok this is a bug. Boolean data should be displayed. They are displayed for LAS objects.

@Jean-Romain Jean-Romain added the Bug A bug in the package label Oct 17, 2019
@Jean-Romain
Copy link
Collaborator

TODO

  • add trim = 100 in the example of the documentation of grid_metrics3d()
  • fix plot.lasmetrics3d() with boolean

@TedwardErker
Copy link
Author

Great, thanks for addressing this. Sorry for closing too soon. :)

@Jean-Romain Jean-Romain changed the title plot doesn't show color for lasmetrics3d objects plot fails with lasmetrics3d objects and boolean attribute Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in the package Documentation Issue related to the documentation of the package
Projects
None yet
Development

No branches or pull requests

2 participants