在 Plotly 中绘制地理参考栅格图像 (R API)

Plot georeferenced raster images in Plotly (R API)

我想使用 Plotly in R to create 3D modells of trenches of archaeological excavations. I'm quite successful to plot point and surface data (Example: Vignette of the R package 我正在处理),但我还想添加战壕地理参考剖面图的光栅信息。

我没有找到在 Plotlys 3D 环境中绘制栅格数据的方法。到目前为止我想出的唯一解决方案(感谢 this post) was to create a 3D modell of the profile with SFM using Photoscan,将彩色网格导出为 .ply 文件,修复此文件的 header 并将其导入 R 以使用以下示例进行绘图代码:

library(geomorph)
library(plotly)

#load data
mesh <- read.ply("plotly/expply8_corr.ply", ShowSpecimen = FALSE)

# extract vertex coordinates
x <- mesh$vb["xpts",]
y <- mesh$vb["ypts",]
z <- mesh$vb["zpts",]

# plot
plot_ly(
  x = x, y = y, z = z,
  i = mesh$it[1,]-1, j = mesh$it[2,]-1, k = mesh$it[3,]-1,
  facecolor = c(mesh$material$color[1, ]),
  type = "mesh3d"
)

您将找到示例数据 here

不幸的是,这种扩展非常糟糕。如果你增加网格分辨率,一切都会变慢。我真的很想添加一个简单的地理参考栅格以保持高性能并避免创建配置文件的 3D 模型。是否有使用 Plotly 或其他绘图库实现此目的的工作流程?

我在包 rgl 中找到了一个很好的解决方案。示例:

library(rgl)
library(jpeg)

# download and load picture
download.file(
  url = 'https://upload.wikimedia.org/wikipedia/en/6/6d/Chewbacca-2-.jpg',
  destfile = "chewbacca.jpg",
  mode = 'wb'
)

chewie <- readJPEG("chewbacca.jpg", native = TRUE)

# create some sample data
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x, y)

# plot sample data
plot3d(x, y, z, col = rainbow(1000), size = 5)

# add picture
show2d(
  # plot raster
  {
    par(mar = rep(0, 4))
    plot(
      0:1, 0:1, type="n",
      ann = FALSE, axes = FALSE,
      xaxs = "i", yaxs = "i"
    )
    rasterImage(chewie, 0, 0, 1, 1)
  },
  # image position and extent
  # coordinate order: lower left, lower right, upper right and upper left
  x = c(-2,  1,  1, -2),
  y = c(-1, -1,  1,  1),
  z = c(-3, -3,  2,  2)
)

图片必须用其他软件进行地理参考(GIS/CAD 中的摄影测量)。如果你有地理参考栅格,你只需要它的角点坐标来绘制它。