在R中使用SRTM tif文件 [英] Using SRTM tif file in R

查看:848
本文介绍了在R中使用SRTM tif文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将SRTM数据集导入R.我已经将数据下载到tif文件中,但是在R中读取它时遇到了问题。
我尝试使用以下代码:

I'm trying to import a SRTM dataset into R. I've downloaded the data in a tif file however am having trouble reading it in "R". Ive tried using the following code:

t = readTIFF("srtm_56_06/srtm_56_06.tif", as.is=TRUE)
load('srtm_56_06/srtm_56_06.tif')
read_file<-as.matrix(raster("srtm_56_06/srtm_56_06.tif")

但是我仍然收到错误消息:

However I am still getting error messages:

load('srtm_56_06/srtm_56_06.tif')
# Error: bad restore file magic number (file may be corrupted) -- no data loaded
# In addition: Warning message:
# file ‘srtm_56_06.tif’ has magic number 'II*'
#   Use of save versions prior to 2 is deprecated 

library(raster)
t = readTIFF("srtm_56_06/srtm_56_06.tif", as.is=TRUE)
# Error: could not find function "readTIFF"

read_file<-as.matrix(raster("srtm_56_06/srtm_56_06.tif") + min(read_file)
# Error: unexpected symbol in:
# "read_file<-as.matrix(raster("srtm_56_06/srtm_56_06.tif")
# min"

任何人都可以提供帮助我用命令导入这些数据。我是R的新手,有点迷失。

Can anyone help me with the commands to import this data. I'm a novice at "R" and a little lost.

推荐答案

只需用光栅阅读,但请注意,您还要依赖 rgdal 来阅读.tif。

Just read it with raster, but note you depend on rgdal being installed as well to read a .tif.

library(raster)
library(rgdal)
r <- raster("srtm_56_06/srtm_56_06.tif")

如果有效,请尝试

plot(r)
r

如果是真的是一个TIFF然后应该没问题,如果它真的是一个GeoTIFF那么你也会有一个合理的地图。 (如果它是GDAL可以读取的其他东西,你可能会得到一个好结果,记住文件的扩展名不是其内容的可靠指标)。

If it's really a "TIFF" then that should be fine, if it's really a GeoTIFF then you'll have a sensible map as well. (If it's something else that GDAL can read you might get a good result anyway, remember the extension of a file is not a reliable indicator of its contents).

SRTM线索表明这是来自平铺全局SRTM数据集的单频段DEM文件。如果它以某种方式是多波段图像,那么你可以用 brick 读取它并用 plotRGB 绘图(但我真的怀疑这是这种情况)。请注意,SRTM有一个本机二进制格式,raster / rgdal也可以读取它,但它们也分布.tif或其他人转换它。

The SRTM clue suggests that this is a single band DEM file from the tiled global SRTM data set. If it's somehow a "multi-band image" then you could read that with brick and plot with plotRGB (but I really doubt that is the case here). Note that there is a native binary format for SRTM that raster/rgdal could read as well but either they distributed .tif as well or someone else converted it.

您的代码中存在许多误解:

There are a number of misconceptions in your code:


  • load 是针对从R创建的特定文件类型(不是这些.tifs)

  • readTIFF 不在包 raster

  • read_file 将是一个合理的矩阵,如果您安装了 rgdal raster 必须用来加载.tif),但为什么要扔掉空间元数据?

  • load is for a particular file type created from R (not these .tifs)
  • readTIFF is not in package raster
  • read_file would be a sensible matrix, if you have rgdal installed (which raster must use to load a .tif), but why throw away the spatial metadata?

这篇关于在R中使用SRTM tif文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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