Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R传单。使用弹出功能报告线穿过生成网格单元的时间_R_Leaflet_Polygon_Sf_Sp - Fatal编程技术网

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)