我想從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