如何在R中的光栅文件(landsat img)上绘制空间点(矢量)

时间:2018-01-28 11:41:07

标签: r spatial raster projection points

我想在地图上绘制空间点(sp),绘制地图作品并绘制sp,但它不能同时工作。我很确定我在某种程度上没有覆盖投影/坐标系,但不知道我做错了什么。谷歌没有帮助,所以我问你。

以下是代码:

coords_glaciers <- data.frame(x = prec_year$latitude, y = prec_year$longitude)
head(coords_glaciers)

         x        y
1 30.69800 95.10474
2 30.69628 95.09544
3 30.69173 95.04394
4 30.68793 95.08615
5 30.68799 95.20155
6 30.68472 95.21425

pts_glaciers <- SpatialPoints(coords = coords_glaciers)
pts_glaciers

class       : SpatialPoints 
features    : 865 
extent      : 29.50121, 30.82512, 94.24684, 96.19304  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
proj <- projection(landsat)
proj
[1] "+proj=utm +zone=46 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"

pts_glaciers <- SpatialPoints(coords = coords_glaciers, proj4string = CRS(proj))
pts_glaciers

class       : SpatialPoints 
features    : 865 
extent      : 29.50121, 30.82512, 94.24684, 96.19304  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=46 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 

plotRGB(landsat, r=5, g=4,b=3)
plot(pts_glaciers, add =TRUE)

1 个答案:

答案 0 :(得分:1)

我认为解决方案是:

coords_glaciers <- data.frame(x = prec_year$longitude, y = prec_year$latitude)

coordinates(coords_glaciers) <- c("x","y")

proj4string(coords_glaciers) <- CRS("+proj=longlat +datum=WGS84") 

pts_glaciers <- spTransform(coords_glaciers, CRS("+proj=utm +zone=46 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"))