地图中缺少 markers/points
Missing markers/points in map
我还是 Rshiny 和 Leaflet 包的新手,所以需要一些帮助来了解我哪里出错了。我之前问过一个非常相似的问题,之后我收到了一个我正在使用的解决方案。这是同一个问题的变体。
我有一个英国 post 代码,我有纬度和经度值,我们称其为原点 post 代码。我有一个数据框,其中包含其他 post 代码及其相应的经纬度。我有一个滑动条输入,它是从原点 postcode 开始的半径(以英里为单位),范围可达 200 英里。我可以加载该应用程序,但我看不到其他 post 代码标记出现在地图上。我也得到以下
CRS 定义中的丢弃数据 OSGB_1936
showSRID(uprojargs, format = "PROJ", multiline = "NO") 警告:
CRS 定义
中的丢弃数据 OSGB_1936
我post我的代码如下:
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)
您的数据框的两个邮政编码位于同一位置,但存在错误。如下更改
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)
)
产生这个。
我还是 Rshiny 和 Leaflet 包的新手,所以需要一些帮助来了解我哪里出错了。我之前问过一个非常相似的问题,之后我收到了一个我正在使用的解决方案。这是同一个问题的变体。
我有一个英国 post 代码,我有纬度和经度值,我们称其为原点 post 代码。我有一个数据框,其中包含其他 post 代码及其相应的经纬度。我有一个滑动条输入,它是从原点 postcode 开始的半径(以英里为单位),范围可达 200 英里。我可以加载该应用程序,但我看不到其他 post 代码标记出现在地图上。我也得到以下
CRS 定义中的丢弃数据 OSGB_1936 showSRID(uprojargs, format = "PROJ", multiline = "NO") 警告: CRS 定义
中的丢弃数据 OSGB_1936我post我的代码如下:
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)
您的数据框的两个邮政编码位于同一位置,但存在错误。如下更改
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)
)
产生这个。