使用光栅包下载 SRTM 数据? [英] Downloading SRTM data with raster package?

查看:67
本文介绍了使用光栅包下载 SRTM 数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 R 中的raster"包获取 SRTM 数据,但是只要我在 getData 命令中选择 SRTM,我就会得到以下错误:

I'm trying to get SRTM data with "raster" package in R, but as soon as I'm choosing SRTM in getData command, I would get the following error:

library(raster)

srtm <- getData('SRTM', lon=16, lat=48)
trying URL 'ftp://xftp.jrc.it/pub/srtmV4/tiff/srtm_40_03.zip'
trying URL 'http://hypersphere.telascience.org/elevation/cgiar_srtm_v4/tiff/zip/srtm_40_03.ZIP'
downloaded 572 bytes

Error in .SRTM(..., download = download, path = path) : file not found
In addition: Warning messages:
1: In utils::download.file(url = aurl, destfile = fn, method = "auto",  :
  URL 'ftp://xftp.jrc.it/pub/srtmV4/tiff/srtm_40_03.zip': status was 'Couldn't resolve host name'
2: In utils::unzip(zipfilename, exdir = dirname(zipfilename)) :
  error 1 in extracting from zip file

知道这是什么错误吗?

推荐答案

我也遇到了同样的问题,好像是个bug.raster 包中的 getData 函数在三个不同的 url 中检查光栅文件的可用性.

I have the same problem, it seems to be a bug. The getData function in raster package checks for availability of the raster file in three different url's.

1. ftp://xftp.jrc.it/pub/srtmV4/tiff/FILENAME
2. http://hypersphere.telascience.org/elevation/cgiar_srtm_v4/tiff/zip/FILENAME
3. http://srtm.csi.cgiar.org/SRT-ZIP/SRTM_V41/SRTM_Data_GeoTiff/FILENAME

前两个(截至今天)不起作用或无法访问.然而,由于某种原因,一小部分数据正在跨服务器传输,因此该包假定它是一个可用文件,但 utils 却遇到了错误.然而,第三个 url 是三个中最受信任的一个.

The first two of them (as of today) are not working or cannot be accessible. However for some reason a small bit data is getting transferred across the server, so the package assumes it to be a available file only to reach an error by utils. The third url however is most trusted one among the three.

在稍微修改 raster 包本身后,我做了一些挖掘并想出了以下函数,以便它使用第三个 url.您可以在此处输入LongitudeLatitude 值.请注意,这仅在您想下载基于 Latitude & 的文件时有用.经度.

I did some digging and came up with the following function after slightly modifying the raster package itself so that it uses the third url. You can input Longitude and Latitude values here. Note that this is only useful if you want to download the files based on Latitude & Longitude.

SRTM<-function(lon, lat) {
  stopifnot(lon >= -180 & lon <= 180)
  stopifnot(lat >= -60 & lat <= 60)
  rs <- raster(nrows=24, ncols=72, xmn=-180, xmx=180, ymn=-60, ymx=60 )
  rowTile <- rowFromY(rs, lat)
  colTile <- colFromX(rs, lon)
  if (rowTile < 10) { rowTile <- paste('0', rowTile, sep='') }
  if (colTile < 10) { colTile <- paste('0', colTile, sep='') }

  f <- paste('srtm_', colTile, '_', rowTile, sep="")
  theurl <- paste("http://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF/", f, ".ZIP", sep="")
  utils::download.file(url=theurl, destfile='srtm_40_0.zip', method="auto", quiet = FALSE, mode = "wb", cacheOK = TRUE)
}

示例:

SRTM(lon=16, lat=48)

这将在您的文件夹中生成一个名为 srtm_40_03.zip 的文件,该文件通常包含一个 tif、一个 hdr 和一个 tfw 同名文件.照常使用它们进行进一步的处理.

This will result in a file named srtm_40_03.zip in your folder which would normally contain a tif, a hdr and a tfw file of the same name. Use them for further process as usual.

编辑日期 19 年 1 月 22 日:srtm 链接已更改(也已更改),已对上述代码进行了调整以反映这一点.

EDIT DATE 22-JAN-19: The srtm link as changed (as well), the above code has been adapted to reflect this.

这篇关于使用光栅包下载 SRTM 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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