在Plotly(R API)中绘制地理参考栅格图像 [英] Plot georeferenced raster images in Plotly (R API)
问题描述
我想在R中使用 Plotly 创建考古发掘战壕的三维模型。我很成功地绘制点和曲面数据(例如: Vignette R包我正在研究),但我还想添加地理参考配置文件图片的栅格信息。
我没有找到任何方法在Plotlys 3D环境中绘制栅格数据。到目前为止我唯一的解决方案(感谢这个 post)用 SFM 使用 Photoscan ,将彩色网格导出为.ply文件,修复此文件的标题并将其导入到R中,以绘制以下示例代码:
library(geomorph)
pre>
library(plotly)
#load data
mesh< - read.ply(plotly / expply8_corr.ply,ShowSpecimen = FALSE)
#提取顶点坐标
x< - mesh $ vb [xpts, ]
y< - mesh $ vb [ypts,]
z< - 网格$ 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
)
您可以找到示例数据此处。
不幸的是,这个缩放比例非常糟糕。如果增加网格分辨率,一切都会变慢。我真的很想添加一个简单的地理参考栅格来保持高性能,并避免创建配置文件的3D模型。有没有一个工作流,以实现这与Plotly或其他绘图库?
解决方案我找到了一个很好的解决方案 rgl 。示例:
库(rgl)
库(jpeg)
#下载和加载图片
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)
(1000))$ b $< - rnorm(1000)
z< - rnorm(1000)+ atan2(x,y)
#绘制样本数据
plot3d(x,y,z,col = rainbow(1000),size = 5)
#添加图片
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)
},
#图像位置和范围
#坐标顺序:左下,右下,右上和左上
x = c(-2,1,1,-2) ,
y = c(-1,-1,1 ,1),
z = c(-3,-3,2,2)
)
图片必须与其他软件(GIS / CAD中的摄影测量)进行地理参考。如果你有地理参考光栅,你只需要它的角点坐标来绘制它。
I would like to use 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 I'm working on), but I would also like to add raster information of the georeferenced profile pictures of the trenches.
I didn't find any way to plot raster data in Plotlys 3D environment. The only solution I came up with so far (thanks to this post) was to create a 3D modell of the profile with SFM using Photoscan, export the coloured mesh as .ply file, fix the header of this file and import it into R to do the plotting with the following example code:
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" )
You'll find the example data here.
Unfortunately this scales really badly. If you increase the mesh resolution everything becomes to slow. I would really like to just add a simple georeferenced raster to keep the performance high and avoid the necessity to create 3D modells of the profiles. Is there a workflow to achieve this with Plotly or an other plotting library?
解决方案I found a nice solution with the package rgl. Example:
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) )
The pictures have to be georeferenced with other software (photogrammetry in GIS/CAD). If you have the georeferenced raster you just need the coordinates of its corner points to plot it.
这篇关于在Plotly(R API)中绘制地理参考栅格图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!