rDGAL,Tiff文件和WorldFile [英] rDGAL, Tiff Files, and WorldFile

查看:166
本文介绍了rDGAL,Tiff文件和WorldFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组tiff文件,这些文件在解决方案

通常,如果您知道数据已投影,但是此投影不是tif文件的一部分,则只需将其添加到R对象中导入后:

proj4string(imageData) <- CRS("your projection")

例如,如果您的tif位于GoogleEarth投影中,我会使用EPSG:

proj4string(imageData) <- CRS("+init=EPSG:4326")

只需找到您NAD83的确切投影即可(此网站可以帮助 http://spatialreference.org/)

然后您可以根据自己的选择重新投影它:

imageDataProj <- spTransform(imageDataProj, CRS("your new projection"))

作为旁注,我总是更喜欢使用raster包来处理栅格格式.但是,用R更改大栅格文件的投影可能很费力,因此现在我直接使用GDAL(通过gdalwarp).您可以使用gdalUtils包在R中轻松调用所有gdal选项,但必须手动将结果导入回R.

根据OP的评论进行

使用栅格数据包:

library(raster)

加载tif:

rr <- raster("C:\\temp\\n0r_201601011100.tif")

在函数中保存像素坐标方程式.注意,我更改了Lat函数(删除了负号,它不起作用,您必须对此进行验证)

Lon = function(JJ) 0.01 * JJ + 162
Lat = function(II) 0.01 * II + 50.0

以像素坐标获取原始栅格的范围:

ext.rr <- extent(rr)

准备一个新的空栅格,将其投影,并具有良好的分辨率和范围:

rr2 <- raster(nrows=nrow(rr), ncols=ncol(rr), xmn=Lon(ext.rr@xmin), xmx=Lon(ext.rr@xmax), ymn=Lat(ext.rr@ymin), ymx=Lat(ext.rr@ymax))

使用修改后的值填充此新栅格(按照注释中给出的方程式进行操作):

values(rr2) <- (values(rr) - 7) * 5

您将得到:

rr2
   class       : RasterLayer 
   dimensions  : 2600, 6000, 15600000  (nrow, ncol, ncell)
   resolution  : 0.01, 0.01  (x, y)
   extent      : 162, 222, 50, 76  (xmin, xmax, ymin, ymax)
   coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
   data source : in memory
   names       : layer 
   values      : -35, 50  (min, max)

请注意,光栅功能会自动拾取经纬度投影.希望这就是您要寻找的.

I have a set of tiff files that display convective weather across the continental US (NAD83 projection) in pixel locations from Iowa State University. My goal is the transformation of the pixel locations to lat/lon data. I read in the tiff file data as a SpatialGridDataFrame with...

imageData   = readGDAL( fileNameDir, silent = TRUE )

I read somewhere that readGDAL will seek a World File if no projection data exist in the tiff file, so I created such a file (nad83WorldFile.wld) with the requisite information, see info at ESRI. I put the wld file in the same directory as my R scripts. The coefficients for the wld file are:

A = 0.01 
B = 0.0 
C = 0.0 
D = -0.01 
E = -126.0 
F = 50.0

I seek advice and guidance on the pixel-to-lat/lon projection. A data file for the readGDAL example of fileNameDir and documentation on the World File format are provided in the hypertext links above. I had to change the file extension from *.png to *.tiff.

解决方案

Normally, if you know that your data are projected, but that this projection isn't part of your tif file, your can simply add it in your R object after the import:

proj4string(imageData) <- CRS("your projection")

I like using EPSG for that, if your tif was in GoogleEarth projection for example I would do:

proj4string(imageData) <- CRS("+init=EPSG:4326")

Just find what you NAD83 exact projection is (this site can help http://spatialreference.org/).

Then you can reproject it in the your choice of projection:

imageDataProj <- spTransform(imageDataProj, CRS("your new projection"))

As a side note, I always prefer using the raster package for handling raster formats. However, changing the projection of a big raster file with R can be fastidious, so now I use GDAL directly (through gdalwarp). You can call all gdal options quite easily in R with the gdalUtils package but you'll have to import the results back into R after hand.

EDITS following comment from OP:

Using the raster package:

library(raster)

Loading the tif:

rr <- raster("C:\\temp\\n0r_201601011100.tif")

Save you pixel coordinates equations in functions. Noticed I changed the Lat function (removed the negative sign, it didn't work with it, you'll have to validate that)

Lon = function(JJ) 0.01 * JJ + 162
Lat = function(II) 0.01 * II + 50.0

Get the extent of your raw raster in pixel coordinates:

ext.rr <- extent(rr)

Prepare a new empty raster which will be projected, have the good resolution and extent:

rr2 <- raster(nrows=nrow(rr), ncols=ncol(rr), xmn=Lon(ext.rr@xmin), xmx=Lon(ext.rr@xmax), ymn=Lat(ext.rr@ymin), ymx=Lat(ext.rr@ymax))

Fill this new raster with your modified values (following the equation you gave in the comments):

values(rr2) <- (values(rr) - 7) * 5

And you get:

rr2
   class       : RasterLayer 
   dimensions  : 2600, 6000, 15600000  (nrow, ncol, ncell)
   resolution  : 0.01, 0.01  (x, y)
   extent      : 162, 222, 50, 76  (xmin, xmax, ymin, ymax)
   coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
   data source : in memory
   names       : layer 
   values      : -35, 50  (min, max)

Notice that the lat-long projection was automatically pick-up by the raster function. Hopefully it's what you are looking for.

这篇关于rDGAL,Tiff文件和WorldFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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