使用 mapdeck 的 add_trips 函数创建数据层时出错
Error creating data layer using the add_trips function of mapdeck
正在尝试为 mapdeck 使用新的 add_trips 图层。下面的示例代码和错误。感谢您的帮助。谢谢
我正在使用的数据:
> class(msi)
[1] "sf" "tbl_df" "tbl" "data.frame"
> head(msi$geometry)
Geometry set for 6 features
geometry type: POINT
dimension: XYZ
bbox: xmin: 2.94486 ymin: 51.34172 xmax: 3.21298 ymax: 51.42742
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 5 geometries:
POINT Z (2.94486 51.42742 1573824004)
POINT Z (3.2062 51.35052 1573827317)
POINT Z (3.21298 51.34172 1573830334)
POINT Z (3.21298 51.34175 1573834830)
POINT Z (3.21297 51.34173 1573838433)
mapdeck代码:
key = "mykeyhere"
plot <- mapdeck( token = key, style = 'mapbox://styles/mapbox/dark-v9',
pitch = 30,
width="100%",
zoom=15) %>%
add_trips(
data = msi
)
我遇到的错误:
Error in rcpp_path_geojson(data, l, geometry_column, digits, "trips") : Error creating data layer
关于你的例子的注释
- 行程图层需要 LINESTRING,而不是 POINT
- 它还需要 Z(海拔)和 M(时间)属性(线条在 space 和时间中呈现)
其他详情
我把带this pull-request的行程层写到sf
库里,所以我设计它自动读取z_range
和m_range
sfc
对象。
我还有 sfheaders
库,它可以构建包含这些属性的 sf 对象。
我正在使用 github 版本的 sf 和 mapdeck
remotes::install_github("r-spatial/sf")
remotes::install_github("SymbolixAU/mapdeck")
工作示例
你的问题中没有包含可重现的数据集,所以我将使用我自己的数据集。
在这个例子中我
- 取一个sf LINESTRING对象
- 转换成
data.table
坐标
- 附加 Z 和 M 列
- 转换回 sf LINESTRING 对象
- 情节旅行
library(mapdeck)
library(sf)
library(sfheaders)
library(data.table)
## 'roads' is an sf object included in mapdeck
sf_roads <- mapdeck::roads
## you don't need this, I only use it later in the plot so I can subset only 'long'
## roads, so the gif is below 2mb!
sf_roads$length <- as.numeric( sf::st_length( sf_roads ) )
sf_roads$id <- 1:nrow( sf_roads ) ## for joining the 'length' back on
## grab the road coordinates
dt <- sf::st_coordinates( sf_roads )
dt <- as.data.table( dt )
## st_coordinates returns a L1 'id', which is equivalent to our 'id' above
## Need Z and M attributes
dt[, Z := 0 ] ## can be actual elevation if you have it
dt[, M := 1:.N, by = .(L1)] ## this 'M' is your timestamp
## convert back to sf LINESTRING
sf_trips <- sfheaders::sf_linestring(
obj = dt
, x = "X"
, y = "Y"
, z = "Z"
, m = "M"
, linestring_id = "L1"
)
## You don't need this bit, where I join the 'length' back on.
sf_roads$geometry <- NULL
sf_trips <- merge(
x = sf_trips
, y = sf_roads
, by.x = "L1"
, by.y = "id"
)
mapdeck(
style = mapdeck_style("dark")
) %>%
add_trips(
data = sf_trips[ sf_trips$length > 500, ] ## only showing 'long' roads
, stroke_colour = "L1"
, stroke_width = 100
, opacity = 0.8
, animation_speed = 10
, trail_length = 50
, palette =
)
正在尝试为 mapdeck 使用新的 add_trips 图层。下面的示例代码和错误。感谢您的帮助。谢谢
我正在使用的数据:
> class(msi)
[1] "sf" "tbl_df" "tbl" "data.frame"
> head(msi$geometry)
Geometry set for 6 features
geometry type: POINT
dimension: XYZ
bbox: xmin: 2.94486 ymin: 51.34172 xmax: 3.21298 ymax: 51.42742
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 5 geometries:
POINT Z (2.94486 51.42742 1573824004)
POINT Z (3.2062 51.35052 1573827317)
POINT Z (3.21298 51.34172 1573830334)
POINT Z (3.21298 51.34175 1573834830)
POINT Z (3.21297 51.34173 1573838433)
mapdeck代码:
key = "mykeyhere"
plot <- mapdeck( token = key, style = 'mapbox://styles/mapbox/dark-v9',
pitch = 30,
width="100%",
zoom=15) %>%
add_trips(
data = msi
)
我遇到的错误:
Error in rcpp_path_geojson(data, l, geometry_column, digits, "trips") : Error creating data layer
关于你的例子的注释
- 行程图层需要 LINESTRING,而不是 POINT
- 它还需要 Z(海拔)和 M(时间)属性(线条在 space 和时间中呈现)
其他详情
我把带this pull-request的行程层写到sf
库里,所以我设计它自动读取z_range
和m_range
sfc
对象。
我还有 sfheaders
库,它可以构建包含这些属性的 sf 对象。
我正在使用 github 版本的 sf 和 mapdeck
remotes::install_github("r-spatial/sf")
remotes::install_github("SymbolixAU/mapdeck")
工作示例
你的问题中没有包含可重现的数据集,所以我将使用我自己的数据集。
在这个例子中我
- 取一个sf LINESTRING对象
- 转换成
data.table
坐标 - 附加 Z 和 M 列
- 转换回 sf LINESTRING 对象
- 情节旅行
library(mapdeck)
library(sf)
library(sfheaders)
library(data.table)
## 'roads' is an sf object included in mapdeck
sf_roads <- mapdeck::roads
## you don't need this, I only use it later in the plot so I can subset only 'long'
## roads, so the gif is below 2mb!
sf_roads$length <- as.numeric( sf::st_length( sf_roads ) )
sf_roads$id <- 1:nrow( sf_roads ) ## for joining the 'length' back on
## grab the road coordinates
dt <- sf::st_coordinates( sf_roads )
dt <- as.data.table( dt )
## st_coordinates returns a L1 'id', which is equivalent to our 'id' above
## Need Z and M attributes
dt[, Z := 0 ] ## can be actual elevation if you have it
dt[, M := 1:.N, by = .(L1)] ## this 'M' is your timestamp
## convert back to sf LINESTRING
sf_trips <- sfheaders::sf_linestring(
obj = dt
, x = "X"
, y = "Y"
, z = "Z"
, m = "M"
, linestring_id = "L1"
)
## You don't need this bit, where I join the 'length' back on.
sf_roads$geometry <- NULL
sf_trips <- merge(
x = sf_trips
, y = sf_roads
, by.x = "L1"
, by.y = "id"
)
mapdeck(
style = mapdeck_style("dark")
) %>%
add_trips(
data = sf_trips[ sf_trips$length > 500, ] ## only showing 'long' roads
, stroke_colour = "L1"
, stroke_width = 100
, opacity = 0.8
, animation_speed = 10
, trail_length = 50
, palette =
)