走位走位~~
image.png
# Sun Apr 04 16:00:27 2021 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.5 for window 10
# cgh163email@163.com
# 个人笔记不负责任,拎了个梨??
.rs.restartR()
require(mapdeck)
rm(list = ls());gc()
?add_trips
# Sun Apr 04 23:17:48 2021 ----ex1--------------------------
set_token(my_mapbox_key)
sf <- city_trail
# [,1] [,2] [,3] [,4]
# [1,] 144.9998 -37.84512 21.8 1499569160
# [2,] 144.9998 -37.84508 21.8 1499569161
# [3,] 144.9998 -37.84502 21.4 1499569162
# [4,] 144.9999 -37.84501 21.2 1499569163
# [5,] 144.9999 -37.84493 20.9 1499569164
mapdeck(
location = c(145, -37.8)
, zoom = 10
, style = mapdeck_style("dark")
) %>%
add_trips(
data = sf
, animation_speed = 2000
, trail_length = 1000
# , stroke_colour = "#FFFFFF"
)
# Sun Apr 04 22:18:05 2021 --end
# Sun Apr 04 16:19:02 2021 ----手动--------------------------
require(sf)
require(sfheaders)
?sfc_LINESTRING#创建简单要素几何列表列
# 创建简单的要素几何列表列,设置类,并添加坐标参考系统和精度
# Sun Apr 04 17:42:01 2021 ----下载的轨迹制作--------------------------
#
map <- st_read('茶岩顶轨迹.geojson')
plot(map$geometry) # 预览
map.xy <- map$geometry %>% st_coordinates() # 打散为普通矩阵剥除sf属性
map.xy <- data.frame(
lon = map.xy[, 1],
lat = map.xy[, 2],
Z = map.xy[, 3]*2, # 高程
M = runif(dim(map.xy)[1], 1000, 5000) # 随机数第四维
) # 重新构建四维散点
# head(map.xy)
map.xyzm <- sf_linestring(map.xy) #转为sf线条对象
str(map.xyzm);rm(map.xy)
# Sun Apr 04 17:05:35 2021 ------------------------------
mapdeck(
# location = c(113.3057 ,23.15426)
location = st_centroid(map$geometry)[[1]] # 位置中心点
, zoom =12
, style = mapdeck_style("light")
) %>%
add_trips(
data =map.xyzm
, animation_speed = 2000
, trail_length = 1000,
stroke_width = 8 #米
# start_time = 100,
# end_time = 100
# , stroke_colour = "#FFFFFF"
)
# Sun Apr 04 23:36:36 2021 --end
#随机数模拟坐标散点:
map.sf <- data.frame(y= runif(100, 30, 80), #生成n个大于min,小于max的随机数 )
x = runif(100, 50,110),
1:100,
1:100
)
head(map.sf)
# Sun Jan 31 19:55:55 2021 --随机数模拟完毕
map.sf.xyzm <- sf_linestring(map.sf) #转为sf线条对象
plot(map.sf.xyzm |> st_zm())
# Sun Jul 11 16:46:48 2021 --
mapdeck(
location = c(60 ,33)
# location = st_centroid(map.sf)[[1]] # 位置中心点
, zoom =2
, style = mapdeck_style("light")
) %>%
add_trips(data = map.sf.xyzm
,end_time = 100 # 结束时间
,animation_speed = 20 # 刷新率
,trail_length = 50 # 拖影
,stroke_width = 8
)
参数
空格分隔符表格
1 map a mapdeck map object 一个mapdeck地图对象
2 data sf object with XYZM dimensions. 具有XYZM尺寸的sf对象。
3 stroke_colour variable of data or hex colour for the stroke. 笔画的数据变量或十六进制颜色。
4 stroke_width width of the stroke in meters. Default 1. 笔画的宽度(以米为单位)。默认值1。
5 opacity single value in [0,1] [0,1]中的单个值
6 palette "string or matrix. String will be one of colourvalues::colour_palettes(). A matrix must have at least 5 rows, and 3 or 4 columns of values between [0, 255], where the 4th column represents the alpha. You can use a named list to specify a different palette for different colour options (where available), e.g. list(fill_colour = "viridis", stroke_colour = "inferno")" “字符串或矩阵。字符串将是colourvalues :: colour_palettes()之一。矩阵必须至少包含5行,且[0,255]之间的值包含3或4列,其中第4列表示Alpha。您可以使用命名列表为不同的颜色选项(如果有)指定不同的调色板,例如list(fill_colour =“ viridis”,stroke_colour =“ inferno”)“
7 trail_length how long it takes for the trail to completely fade out (in same units as timestamps ) 足迹完全消失所需的时间(以时间戳为单位)
8 start_time the minimum timestamp 最小时间戳
9 end_time the maximum timestamp 最大时间戳
10 animation_speed speed of animation 动画速度
11 layer_id single value specifying an id for the layer. Use this value to distinguish between shape layers of the same type. Layers with the same id are likely to conflict and not plot correctly 指定图层ID的单个值。使用此值可以区分相同类型的形状图层。具有相同ID的图层可能会发生冲突并且无法正确绘制
12 legend either a logical indiciating if the legend(s) should be displayed, or a named list indicating which colour attributes should be included in the legend. 逻辑指示是否应显示图例,或者是一个命名列表,该列表指示应在图例中包括哪些颜色属性。
13 legend_options A list of options for controlling the legend. 用于控制图例的选项列表。
14 legend_format A list containing functions to apply to legend values. See section legend 包含要应用于图例值的函数的列表。参见图例
15 digits number of digits for rounding coordinates 舍入坐标的位数