【问题标题】:How to plot spatial points (vector) on a raster file (landsat img) in R如何在 R 中的栅格文件(landsat img)上绘制空间点(矢量)
【发布时间】:2018-01-28 11:41:07
【问题描述】:

我想在 landsat 合成器上绘制空间点 (sp),绘制 landsat 作品并绘制 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)

【问题讨论】:

  • rgdal尝试pts_glaciers &lt;- spTransform(pts_glaciers, CRS(proj))
  • 嗨 Djack,不幸的是,您的解决方案看起来并没有什么不同......我之前已经加载了 rgdal、sp 和 raster。
  • landsat 的范围是多少?
  • > landsat 类:RasterStack 尺寸:7021、8061、56596281、9(nrow、ncol、ncell、nlayers)分辨率:30、30(x、y)范围:599685、841515、3249585、3460215 (xmin, xmax, ymin, ymax) 坐标。参考。 : +proj=utm +zone=46 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs

标签: r spatial raster projection points


【解决方案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"))

【讨论】:

  • 第二个命令不起作用,所以我输入“+proj=utm +zone=46 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units= m +no_defs" 所以命令运行良好,但问题还是一样。当我分别绘制 pts_glaciers 和 landsat 图像时,它们似乎具有完全不同的尺寸......并且添加 pts_glacier 将不起作用
  • 好,我明白了,你需要在coords_glaciers中切换经纬度
  • 哈哈,我傻了....谢谢你的信息,但无论如何,问题不会解决。在查看空间点和landsat img 时,它们具有不同的范围,pts_glacier 具有地理坐标,而landsat 具有UTM 坐标。更改范围仅适用于 landsat img 但这完全破坏了比例和点,即使它们可以添加到 landsat 场景不适合...
  • 我在 UTM 中的答案项目 pts_glaciers 和上次我检查它是否适合 landsat 的范围,所以它应该可以工作
  • 是的,你是完全正确的,我只是犯了一个更小的错误,但现在它可以工作了。非常感谢!!!
猜你喜欢
  • 2013-01-21
  • 1970-01-01
  • 2021-09-17
  • 2017-05-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多