[英]How to plot spatial points (vector) on a raster file (landsat img) in R
我想在landsat合成上繪制空間點(sp),繪制landsat作品並繪制sp,但是它不能一起工作。 我非常確定我不會以某種方式覆蓋投影/坐標系,但是不知道我在做什么錯。 Googleing沒有幫助,所以我問你。
這是代碼:
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)
我認為解決方案是:
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"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.