首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Plotly中打印地理参考光栅图像(R API)

在Plotly中打印地理参考光栅图像(R API)
EN

Stack Overflow用户
提问于 2016-08-25 17:53:50
回答 1查看 819关注 0票数 1

我想用R中的Plotly来创建考古挖掘战沟的3D模型。我非常成功地绘制点和表面数据(例如:我正在处理的R packageVignette ),但我也想添加战沟的地理参考剖面图片的栅格信息。

我没有找到在Plotlys 3D环境中绘制栅格数据的任何方法。到目前为止,我想出的唯一解决方案(感谢this post)是使用PhotoscanSFM创建轮廓的3D模型,将彩色网格导出为.ply文件,修复该文件的头部并将其导入R中,使用以下示例代码进行绘制:

代码语言:javascript
复制
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或其他绘图库实现这一点的工作流程?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-01 18:44:29

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

代码语言:javascript
复制
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中的摄影测量)进行地理参考。如果你有地理参考栅格,你只需要它的角点的坐标来绘制它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39142040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档