【发布时间】:2013-12-03 17:27:46
【问题描述】:
我的“长期目标”是绘制一个瑞士的免费地形数据集 (http://www.toposhop.admin.ch/de/shop/products/height/dhm25200_1),并使用包含瑞士边界和代表 R 中气象站的数据点的 shapefile 创建一个叠加层。
绘制带有边界的 shapefile 并将站点添加为点效果很好,但现在在许多尝试中失败的是将瑞士坐标中的地形数据集投影到 WGS84,以便能够将其与边界和站点一起绘制WGS84。
过去几天我尝试过的最佳解决方案是什么:
# read xyz data:
topo=read.table("DHM200.xyz", sep=" ")
CH.topo.x= as.vector(topo$V1)
CH.topo.y= as.vector(topo$V2)
library(rgdal)
coord.topo <- data.frame(lon=CH.topo.x, lat=CH.topo.y)
coordinates(coord.topo) <- c("lon", "lat")
proj4string(coord.topo) <- CRS("+proj=somerc +lat_0=46.95240555555556+
lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel+
towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs") # CH1903 / LV03 (EPSG:21781)
CRS.new <- CRS("+init=epsg:4326") # WGS84
coord.topo.wgs84 <- spTransform(coord.topo, CRS.new)
# this should have transformed the coordinates properly into a SpatialPoints object
# I now try to replace the old swiss coordinates by the degrees lat/lon:
topo[,1:2]=coordinates(coord.topo.wgs84)
topo=topo[order(topo$V1, topo$V2),]
# but creating a raster (that can be plotted!?)
topo.raster= rasterFromXYZ(topo, res=c(0.002516,0.00184), crs="+init=epsg:4326",
digits=5)
# returns the following error (either with or without "res" input):
# " x cell sizes are not regular"
尽管排序:这个错误是坐标变换中舍入错误的结果吗? R 是否提供了更好的解决方案来投影和绘制terrain.colors() 中的数据,并且可以将形状和点添加到绘图中?
我直接问这个问题的原因是:数据集也可以作为 ESRI ASCII Grid 使用,但是当我尝试在瑞士坐标中绘制它时(对于第一个概述),默认颜色是红色到黄色。我尝试使用image() 函数为terrain.colors() 绘制它,但是点和形状都无法添加。
谁能帮忙?
提前致谢!!!
【问题讨论】:
-
您能否使用
rasterFromXYZ读取您的数据,并使用projectRaster()将该栅格投影到新的CRS? -
天哪!非常感谢,最好用!!!有时只是被直率蒙蔽了双眼;-) 当然,您可以将其发布为“真正的答案”!
标签: r plot projection coordinate-transformation wgs84