【问题标题】:Missing markers/points in map地图中缺少标记/点
【发布时间】:2021-09-22 15:43:28
【问题描述】:

我还是 Rshiny 和 Leaflet 包的新手,所以需要一些帮助来看看我哪里出错了。我之前曾问过一个非常相似的问题,之后我收到了我正在使用的解决方案。这是同一问题的变体。

我有一个英国邮政编码,我有它的纬度和经度值,我们称之为原产地邮政编码。我有一个数据框,其中包含其他邮政编码及其相应的纬度和经度。我有一个滑动条输入,它是以英里为单位的原始邮政编码的半径,其范围可达 200 英里。我可以加载应用程序,但在地图上看不到其他邮政编码标记。我也得到了以下

CRS 定义中的废弃数据 OSGB_1936 showSRID(uprojargs, format = "PROJ", multiline = "NO") 中的警告: CRS定义中丢弃的数据OSGB_1936

我在下面发布我的代码:

library(shiny)
library(leaflet)
library(shinyjs)
library(rgeos)
library(tidyverse)

crime_df <-
data.frame(Postcode = 
"WN1 3LU",box =2,
Latitude = 
53.546367,
Longitude = 
-2.620909)

crime <-
  data.frame(Postcode = 
               c("BL7 9YH","BT36 7WE"),box =c(7,1),
             Latitude = 
               c(53.613982,53.613982),
             Longitude = 
               -2.406439,-2.406439)
coordinates(crime) = ~Longitude+Latitude
proj4string(crime) = CRS("+init=epsg:4326")
crime <- spTransform(x = crime, CRS = CRS("+init=epsg:27700"))


ui <- fluidPage(shinyjs::useShinyjs(),
fluidPage(
# Give the page a title
titlePanel("Crime Map"),
mainPanel(leafletOutput("map")),

fluidRow(column(
3,
sliderInput(
"miles",
"Miles from location",
min = 1,
max = 200,
value = 100,
width = '120px'
)))))


server <- function (input, output, session) {
  output$map <- renderLeaflet({
    inside_df <- inside_df()
    leaflet(crime_df) %>%
      addTiles() %>%
      setView(lng = -1.525,
              lat = 55,
              zoom = 5) %>%
      addMarkers(
        lng = inside_df$Longitude,
        lat = inside_df$Latitude,
        popup = inside_df$Postcode
      )
  })


circle <- reactive({
location <- crime_df  %>%dplyr::select(Latitude, Longitude)
coordinates(location) <- ~Longitude+Latitude
proj4string(location) = CRS("+init=epsg:4326")
location <- spTransform(location, CRS = CRS("+init=epsg:27700"))
circle <- gBuffer(location, width = input$miles * 1609.34)
circle
})

inside_df <- reactive({
circle = circle()
inside = crime[circle,]  # find points inside the circle
inside = spTransform(inside,  CRS("+init=epsg:4326"))
inside_df = as.data.frame(inside)
inside_df
})
}

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny leaflet


    【解决方案1】:

    您的数据框的两个邮政编码位于同一位置并包含错误。如下改变它

    crime <-
        data.frame(
            Postcode = c("BL7 9YH", "BT36 7WE"),
            box = c(7, 1),
            Latitude =  c(53.613982, 54.66653),
            Longitude = c(-2.406439,-5.981969)
        )
    

    产生这个。

    【讨论】:

      猜你喜欢
      • 2015-03-03
      • 2013-08-11
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 2012-05-16
      相关资源
      最近更新 更多