R传单。使用弹出功能报告线穿过生成网格单元的时间
上午、下午或晚上 我有以下数据(船舶横断面): 我意识到这是一个相当大的要求,所以即使是指针都是受欢迎的 创建地图的代码R传单。使用弹出功能报告线穿过生成网格单元的时间,r,leaflet,polygon,sf,sp,R,Leaflet,Polygon,Sf,Sp,上午、下午或晚上 我有以下数据(船舶横断面): 我意识到这是一个相当大的要求,所以即使是指针都是受欢迎的 创建地图的代码 library( sf ) library( sp ) coordinates(df) <- c("lngs","lats") proj4string(df) <- CRS("+proj=longlat") grd <- GridTopology(cellcentre.offset=bbox(df
library( sf )
library( sp )
coordinates(df) <- c("lngs","lats")
proj4string(df) <- CRS("+proj=longlat")
grd <- GridTopology(cellcentre.offset=bbox(df)[,1],
cellsize=c(0.05,0.05), cells.dim=c(200,130))
polys <- as.SpatialPolygons.GridTopology(grd)
proj4string(polys) <- CRS("+proj=longlat")
meantime <- rep(0, length(polys))
numofimg <- rep(0, length(polys))
for(i in 1:length(polys)) {
meantime[i] = mean(df$times[which(!is.na(over(x=df,y=polys[i])))])
}
for(i in 1:length(polys)) {
numofimg[i] = length(df$value[which(!is.na(over(x=df,y=polys[i])))])
}
times <- as.list(meantime)
convertback <- function(x){
as.POSIXct(x, origin="1970-01-01")
}
times <- lapply(times, convertback)
times <- do.call("c", times)
polys$meantime <- times
polys$numofimg <- numofimg
library(leaflet)
library(htmlwidgets)
library(htmltools)
library(colourvalues)
library(leafgl)
pal <- colorNumeric(
palette = "viridis",
domain = polys$numofimg)
clipped <- polys[polys@data$numofimg > 0, ]
leaflet() %>%
addProviderTiles('Esri.WorldGrayCanvas') %>%
leafgl::addGlPolygons(data = clipped,
weight = 1,
fillColor = ~pal(numofimg),
fillOpacity = 0.8,popup = ~paste("<h3>Cell Info:</h3>",
"<b>Mean Cell time: </b>",
as.character(meantime),
"<br>",
"<b>Number of datapoints: </b>",
value)
) %>%
addPolylines(group = "Ships Path",
data = df,
lng = ~lngs,
lat = ~lats,
color = "black",
weight = 1)
库(sf)
图书馆(sp)
坐标(df)
for(i in 1:length(polys)) {
numofimg[i] = length(df$value[which(!is.na(over(x=df,y=polys[i])))])
}
library( sf )
library( sp )
coordinates(df) <- c("lngs","lats")
proj4string(df) <- CRS("+proj=longlat")
grd <- GridTopology(cellcentre.offset=bbox(df)[,1],
cellsize=c(0.05,0.05), cells.dim=c(200,130))
polys <- as.SpatialPolygons.GridTopology(grd)
proj4string(polys) <- CRS("+proj=longlat")
meantime <- rep(0, length(polys))
numofimg <- rep(0, length(polys))
for(i in 1:length(polys)) {
meantime[i] = mean(df$times[which(!is.na(over(x=df,y=polys[i])))])
}
for(i in 1:length(polys)) {
numofimg[i] = length(df$value[which(!is.na(over(x=df,y=polys[i])))])
}
times <- as.list(meantime)
convertback <- function(x){
as.POSIXct(x, origin="1970-01-01")
}
times <- lapply(times, convertback)
times <- do.call("c", times)
polys$meantime <- times
polys$numofimg <- numofimg
library(leaflet)
library(htmlwidgets)
library(htmltools)
library(colourvalues)
library(leafgl)
pal <- colorNumeric(
palette = "viridis",
domain = polys$numofimg)
clipped <- polys[polys@data$numofimg > 0, ]
leaflet() %>%
addProviderTiles('Esri.WorldGrayCanvas') %>%
leafgl::addGlPolygons(data = clipped,
weight = 1,
fillColor = ~pal(numofimg),
fillOpacity = 0.8,popup = ~paste("<h3>Cell Info:</h3>",
"<b>Mean Cell time: </b>",
as.character(meantime),
"<br>",
"<b>Number of datapoints: </b>",
value)
) %>%
addPolylines(group = "Ships Path",
data = df,
lng = ~lngs,
lat = ~lats,
color = "black",
weight = 1)