Reproject Raster Image from equirectagular to latlon using R

血红的双手。 提交于 2019-12-08 08:17:23

问题


Hi i been trying to reproject a raster image from Equirectangular to EPSG:4326 (Latlon), the issue is that every time i run my code on R, i get the wrong coordinates on the new image; i don´t know where is the error in the code, also i do the same process with Qgis, and i got the same result, it´s strange, i got the opportunity to do the same reprojection process in ENVI, and the result was succesful, help please!!!

a <- raster("C:/Users/<username>/Documents/imageexample.tif")
> a
class       : RasterLayer 
dimensions  : 1800, 1800, 3240000  (nrow, ncol, ncell)
resolution  : 1100, 1100  (x, y)
extent      : -988900, 991100, 1677577, 3657577  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=eqc +lat_ts=0 +lat_0=24 +lon_0=-112 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : C:/Users/<username>/Documents/imageexample.tif
names       : imageexample

g1 <- projectRaster(a, crs="+init=epsg:4326")
> g1
class       : RasterLayer 
dimensions  : 1810, 1810, 3276100  (nrow, ncol, ncell)
resolution  : 0.00988, 0.00988  (x, y)
extent      : -120.9328, -103.05, 39.02317, 56.90597  (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:4326 +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0 
data source : in memory
names       : imageexample.tif 
values      : -5.000117, 39.87529  (min, max)

The correct coordinates should be like this:

    class       : RasterLayer 
dimensions  : 1793, 1803, 3232779  (nrow, ncol, ncell)
resolution  : 0.0108098, 0.009931556  (x, y)
extent      : -121.735, -102.245, 15.08612, 32.8934  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : C:/Users/<username>/Documents/CORRECTimageexample.tif 
names       : CORRECTimageexample

Thanks!!!


回答1:


This is a bit of a special case but generally there is not defined (by the data) extent and resolution for raster reprojection. You need to specify these. For example, you can do:

library(raster)
r <- raster(xmn=-121.735, xmx=-102.245, ymn=15.08612, ymx=32.8934, nrow=1793, ncol=1803, crs='+proj=longlat +ellps=WGS84')
g2 <- projectRaster(a, r)


来源:https://stackoverflow.com/questions/18970537/reproject-raster-image-from-equirectagular-to-latlon-using-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!