我想从Leaflet & Shiny中的绘制事件构建SpatialLine对象(对照栅格进行评估)。我正在使用leaflet.extras中的addDrawToolbar。从Leaflet/Shiny中绘制的特征构建SpatialLine
I have done this with a polygon和思想的过渡将是简单,但显然不,我使用已经尝试(和变化):
# get the coordinates of the drawn line
line_coordinates <- input$mymap_draw_new_feature$geometry$coordinates[[1]]
# transform them to an sp line
drawn_line <- Line(do.call(rbind,lapply(line_coordinates,function(x){c(x[[1]][1],x[[2]][1])})))
但与NA错误或下标出界错误的。
下的应用程序不会产生错误:
# remove the [[1]] subscript
line_coordinates <- input$rasmap_draw_new_feature$geometry$coordinates
# list to matrix of coordinates for Line
raw <- as.numeric(as.character(do.call(rbind,line_coordinates)))
raw <- do.call(rbind,lapply(line_coordinates,function(x){c(x[1],x[2])}))
但是当我陆侃到:
# make Line object
drawn_line <- Line(raw)
Warning: Error in .local: cannot derive coordinates from non-numeric matrix
# or
drawn_line <- Line(as.numeric(raw))
Warning: Error in <Anonymous>: unable to find an inherited method for function ‘coordinates’ for signature ‘"numeric"’
但我每次形成这种哪种方式,我有“不能从非派生坐标 - “数字矩阵”或“无法找到函数的继承方法'坐标'签名'”数字“'”
欢呼蒂姆,我需要看看你使用绘图工具开发什么 – Sam