传单需要投影以显示栅格

我正在尝试创建一个闪亮的应用程序,以在世界地图上显示栅格。用户将与输入进行交互,应用程序将生成栅格以及直方图。下面的代码生成直方图,但不生成地图,我需要帮助以进行排序。这是到目前为止的数据和我的进度。我收到的错误如下所示:input projection is NA

传单需要投影以显示栅格

    library(shiny)
    library(tmap)
    library(tmaptools)
    library(raster)
    library(leaflet)
    library(dplyr)

    coords <- structure(list(cell.lon = c(80,78.25,78.75,72.75,73,78.5,79.5,79.25,78.25),cell.lat = c(15.25,14.25,12.75,26.75,22,23.5,25,22.25,15.25,24)),class = c("tbl_df","tbl","data.frame"),row.names = c(NA,-10L))

    dat.df <- expand.grid(cell.lon = coords$cell.lon,seasonID = c('winter','summer'),business = c('train','bus','taxi'),variable = c('modP','modT'),YearRef = 2001:2003)

    dat.df1 <- coords %>% dplyr::left_join(dat.df) %>% dplyr::mutate(value = rnorm(n()))


    ui <- fluidPage(

        titlePanel('My shiny'),sidebarLayout(position = 'left',sidebarPanel(
                      selectInput(inputId = 'seasonRef',label = 'Select season',choices = c('winter',selected = 'summer'),selectInput(inputId = 'businessRef',label = 'Select business',choices = c('train',selected = 'train'),radioButtons(inputId = 'var',label = NULL,choiceNames = c('modP',choiceValues = c('modP',width = '400px',selected = 'modP'),sliderInput('yearRef','Select Year',min=2001,max=2003,value=1)
                  ),mainPanel(
                    tabsetPanel(
                    tabPanel('Map',leafletOutput("map")),tabPanel('Histogram',plotOutput(outputId = 'hist'))
                ))))


    server <- function(input,output) {

      tempI <- reactive({

        temp <- dat.df1 %>% dplyr::filter(business == input$businessRef & 
                                          seasonID == input$seasonRef & 
                                          YearRef == input$yearRef & 
                                          variable == input$var)
       temp.raster <- rasterFromXYZ(temp[,c('cell.lon','cell.lat','value')])
        })

      output$map <- renderLeaflet({

        leaflet() %>% addTiles() %>% addRasterImage(tempI()) 
        })

        output$hist <- renderPlot({
        hist(tempI())
        })
      }

      shinyApp(ui,server)
caosh666666 回答:传单需要投影以显示栅格

作为一种快速解决方案,由于您的数据采用经度纬度投影,因此您可以尝试将其添加到您的rasterFromXYZ通话中:

rasterFromXYZ(temp[,c('cell.lon','cell.lat','value')],crs = crs('+proj=longlat +datum=WGS84'))

这样,您的栅格将具有项目信息供传单使用。

如果您不使用经纬投影,则必须使crs调用适应您所使用的投影。

希望这对您有帮助!

本文链接:https://www.f2er.com/3142733.html

大家都在问