奇怪的问题改变范围从UTM到latlon(WGS84)并再次回到UTM

时间:2017-09-06 15:33:59

标签: r gis r-raster rgdal map-projections

我正在尝试以下程序(我为错误道歉,但这是第一次在这里)。我的光栅dtm.temp表示如下:

> dtm.temp
class       : RasterLayer 
dimensions  : 668, 965, 644620  (nrow, ncol, ncell)
resolution  : 64.9, 92.6  (x, y)
extent      : 437230.1, 499858.6, 5138842, 5200699  (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:32632 +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : elev 
values      : 362.8404, 3584.865  (min, max)

使用此范围我可以通过以下方式将其转换为longlat

# I build a spatial dataframe with extent data from dtm.temp
df <- data.frame(ID = 1:2, X = c(dtm.temp@extent@xmin, dtm.temp@extent@xmax),
                           Y = c(dtm.temp@extent@ymin, dtm.temp@extent@ymax))
coordinates(df) <- c("X", "Y")
crs_text <- crs(dtm.temp, asText=TRUE) # extracting crs from dtm.temp 
proj4string(df) <- CRS(crs_text) 
ext.lonlat <- spTransform(df, CRS("+proj=longlat +datum=WGS84"))
ext.lonlat

> ext.lonlat
class       : SpatialPointsDataFrame 
features    : 2 
extent      : 8.183449, 8.998142, 46.40024, 46.95982  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
variables   : 1
names       : ID 
min values  :  1 
max values  :  2 

此时我使用范围(表示为longlat)来裁剪以下栅格dtm.temp1(总是在longlat但具有不同的初始范围和更高的分辨率)

> dtm.temp1
class       : RasterLayer 
dimensions  : 9956, 14656, 145915136  (nrow, ncol, ncell)
resolution  : 0.0002777778, 0.0002777778  (x, y)
extent      : 7.857917, 11.92903, 44.27042, 47.03597  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory 
names       : elev
values      : -18, 4543  (min, max)

然后

dtm.temp1.crop <- crop(dtm.temp1, ext.lonlat)

> dtm.temp1.crop
class       : RasterLayer 
dimensions  : 2015, 2933, 5909995  (nrow, ncol, ncell)
resolution  : 0.0002777779, 0.0002777772  (x, y)
extent      : 8.183473, 8.998195, 46.40014, 46.95986  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 

然后我再次在UTM投影光栅在相同程度上裁剪(或至少,所以我相信..)

 # crs_text as defined above 
  dtm.temp1.crop.proj <- projectRaster(dtm.temp1.crop, crs=crs_text)

>dtm.temp1.crop.proj
class       : RasterLayer 
dimensions  : 2033, 2968, 6033944  (nrow, ncol, ncell)
resolution  : 21.2, 30.9  (x, y)
extent      : 437083.4, 500005, 5138362, 5201182  (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:32632 +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : elev 
values      : 360, 3603.655  (min, max)

你可以看到两个范围dtm.temp(起始的一个)e最后的dtm.temp1.crop.proj似乎有太大的不同。

extent dtm.temp           : 437230.1, 499858.6, 5138842, 5200699
extent dtm.temp1.crop.proj: 437083.4, 500005,   5138362, 5201182 

错误(以米为单位)为:

> 437230.1 - 437083.4
[1] 146.7
> 499858.6-500005
[1] -146.4
> 5138842 - 5138362
[1] 480
> 5200699-5201182
[1] -483

我确定我做错了什么但是我疯狂地想要明白什么......

有人耐心帮助我吗?提前谢谢!

我根据Mike的评论添加了一些更多信息,试图澄清。 使用不同的方法(更容易但计算耗时)我按照以下步骤操作:

    > dtm.temp.extent <- extent(dtm.temp) # is the extent fixed
    > dtm.temp.extent
    class       : Extent 
    xmin        : 437230.1 
    xmax        : 499858.6 
    ymin        : 5138842 
    ymax        : 5200699 
# then I project directly the second raster dtm.temp1 using the crs 
# with projectRaster (very slow)
    > dtm.temp1.proj <- projectRaster(dtm.temp1,crs=crs_text)
# then I crop to the fixed extent
    > dtm.temp1.proj.crop <- crop(dtm.temp1.proj, dtm.temp.extent)
# this is what I obtain        
    > extent(dtm.temp)
    class       : Extent 
    xmin        : 437230.1 
    xmax        : 499858.6 
    ymin        : 5138842 
    ymax        : 5200699 
    > extent(dtm.temp1.proj.crop)
    class       : Extent 
    xmin        : 437233.6 
    xmax        : 499852 
    ymin        : 5138857 
    ymax        : 5200688 

错误现在在我看来非常合理:

> 437230.1 - 437233.6 
[1] -3.5
> 499858.6 - 499852
[1] 6.6
> 5138842 - 5138857 
[1] -15
> 5200699 - 5200688 
[1] 11

第一种方法的原因仅仅是因为我试图加速代码(在第二种方法中非常耗时)。

已编辑 )我添加,它可能对某人有用,是第一个工作流程中问题的图像(范围的两个点 - LL和UR - 远离光栅,即使在与问题中上面的光栅不同的光栅上),并且Mkennedy建议的解决方案工作正常(使用四点未投影光栅的所有四个角,LL,UL,UR,LR然后采取8个值的最小值/最大值)。我没有捕获仅使用LL和UR坐标进行lat / lon注入时发生的旋转。取真正的最小/最大值,结果更紧密(如在第二工作流程中)

Position of the raster vertex following a different approach

0 个答案:

没有答案
相关问题