具有空间数据的3D交互式曲面图 [英] 3D interactive surface plot with spatial data

查看:73
本文介绍了具有空间数据的3D交互式曲面图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个交互式的3D湖泊深度图,最好使用plotlyrgl库.我已从高斯-克鲁格/EPSG:31468 CRS等高线的SpatialLinesDataFrame中提取了我的数据,即公制单位.现在,每条轮廓线都会产生一组具有相同深度值的坐标.产生的数据帧相当大,但看起来像这样:

I would like to create an interactive 3D surface plot of depths in a lake, ideally using the plotly or rgl libraries. I have extracted my data from a SpatialLinesDataFrame of contour lines in Gauss-Krueger/EPSG:31468 CRS, i.e. metric units. Now each contour line produces a set of coordinates with the same depth value. The resulting data frame is rather large, but looks something like this:

set.seed(41)
xx <- rnorm(100,4448929,100)
yy <- rnorm(100,5308097,100)
zz <- c(rep(-10,10),rep(-20,10),rep(-30,10),rep(-40,10),rep(-50,10),rep(-60,10),rep(-70,10),rep(-80,10),rep(-90,10),rep(-100,10))
df <- data.frame(xx,yy,zz)

我已尝试使用plotly绘制数据,如示例并使用rgl,如帖子.在这两种情况下,我都会收到与数据不是矩阵格式有关的错误消息,即x和y值分别表示为行号和列号.

I have tried plotting the data with plotly as in this example and with rgl as in this post. In both cases I get error messages relating to my data not being in a matrix format, i.e. where x- and y-values are represented as row- and column-numbers.

有效的方法是在plotly中使用add_trace命令:

What does work, is using the add_trace command in plotly:

plot_ly() %>% add_trace(df,x = ~df$xx, y = ~df$yy, z = ~df$zz,type="mesh3d")

但是,生成的图形不仅缺少add_surface命令的精美颜色图例,而且更重要的是,相对于z值扭曲了x和y值.尽管z值具有相同的度量单位,但显示的z值太大.

However, the resulting graph not only lacks the fancy colour legend of the add_surface command, but more importantly, warps the x- and y-values in relation to the z-values. The z-values are shown much too large, although all have the same metric unit.

我也尝试过将数据框重塑为矩阵,如

I have also tried reshaping the data frame to a matrix as in this post, but it either doesn't work at all, or gives me a matrix consisting almost entirely of NAs. I can only speculate that the number of coordinates that have depth values attached is very small in comparison to all x-y-combinations of coordinates in that range?

任何建议将不胜感激-谢谢!

Any suggestions will be much appreciated - thanks!

推荐答案

这些都是随机定位的点,因此rgl::persp3d无法直接处理它们.但是,您可以按照?rgl::persp3d.deldir中的示例对它们进行三角剖分,然后进行绘制.例如,

Those are randomly located points, so rgl::persp3d can't handle them directly. However, you can follow the example in ?rgl::persp3d.deldir to triangulate them and then plot. For example,

dxyz <- deldir::deldir(df$xx, df$yy, z = df$zz, suppressMsgs=TRUE)
persp3d(dxyz, col = "lightblue")

这会导致图片看起来很丑陋,但是通过一些工作(例如,固定轴标签,使用真实数据),您应该会得到一些合理的信息.

This results in a pretty ugly picture, but with some work (e.g. fixing the axis labels, using real data) you should get something reasonable.

这篇关于具有空间数据的3D交互式曲面图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆