用于读取GDAL的plot3d?

发布于 2024-12-04 04:34:58 字数 217 浏览 1 评论 0原文

我想在 R 中准备 3D 图表!使用栅格数据。 我听说过光栅包中的命令plot3d。 不幸的是,我有 GeoTiff 格式的数据,因此不可能直接通过栅格包读取它(相反,为了加载此文件,我使用 readGDAL 命令)。

是否有机会使用此类数据准备 3D 图表? 我如何检索坐标?我知道如何使用 as.matrix 命令获取栅格值,但因为它是 GeoTiff 格式,所以我无法使用 xmin 或 xmax。

I would like to prepare 3D graph in R! using raster data.
I heard about command plot3d in raster package.
Unfortunately I have data in GeoTiff format, so it is impossible to read it directly through raster package (instead of it, to load this file, I am using readGDAL command).

Is there any opportunity to prepare 3D graph using such data?
How I can retrieve coordinates? I know how to get values of raster using as.matrix command, but because it is in GeoTiff format, I am unable to use xmin or xmax.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑叹一世浮沉 2024-12-11 04:34:58

我不明白为什么你不能用raster读取geotiff,但无论如何,readGDAL(包rgdal)提供的SpatialGridDataFrame(包sp) ) 可以直接传递给raster()

以下是 rgdal 包中的 GeoTIFF 示例。请注意,rasterVis 函数位于单独的包中,名为 plot3D (不是 rgl 包中的plot3d):

library(rgdal)
library(rasterVis)

r <- raster(system.file("pictures/cea.tif", package = "rgdal")[1])
plot3D(r)

dumb default 3Dplot

rasterVis 包处理所有缩放和颜色,并提供一个很好的默认值。

如果您想进一步深入研究支持包,这里有一个简单的示例。

library(rgdal)
library(raster)
library(rgl)

## read the file with raster 

r <- raster(system.file("external/test.ag", package="sp")[1])

## just use simple persp plot
persp(r)

## convert to sp's SpatialGridDataFrame (or use readGDAL directly)
## (for very large rasters this could be prohibitive in terms of memory)
sgdf <- as(r, "SpatialGridDataFrame")

## convert to R's image() format, a list with x,y vector and z matrix

x <- as.image.SpatialGridDataFrame(sgdf)

## plot with rgl, ugly but see ?surface3d for colour options etc.
surface3d(x$x, x$y, x$z)

简单透视图

I do not see why you cannot read a geotiff with raster, but at any rate the SpatialGridDataFrame (package sp) provided by readGDAL (package rgdal) can be passed directly to raster().

Here's an example with a GeoTIFF from the rgdal package. Note that the rasterVis function is in a separate package and is called plot3D (not plot3d which is in the rgl package):

library(rgdal)
library(rasterVis)

r <- raster(system.file("pictures/cea.tif", package = "rgdal")[1])
plot3D(r)

dumb default 3D plot

The rasterVis package handles all the scaling and colours and provides a nice default.

If you want to delve further into the supporting packages, here's a simple example.

library(rgdal)
library(raster)
library(rgl)

## read the file with raster 

r <- raster(system.file("external/test.ag", package="sp")[1])

## just use simple persp plot
persp(r)

## convert to sp's SpatialGridDataFrame (or use readGDAL directly)
## (for very large rasters this could be prohibitive in terms of memory)
sgdf <- as(r, "SpatialGridDataFrame")

## convert to R's image() format, a list with x,y vector and z matrix

x <- as.image.SpatialGridDataFrame(sgdf)

## plot with rgl, ugly but see ?surface3d for colour options etc.
surface3d(x$x, x$y, x$z)

easy persp plot

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文