【问题标题】:Use bbox to clip image in R使用 bbox 在 R 中剪辑图像
【发布时间】:2021-09-09 03:01:23
【问题描述】:

我有一个 shapefile 的边界框。我想用这个 bbox 来剪辑一个我同时拥有光栅和 shapefile 的图像。

我尝试使用 gIntersection 和裁剪(见下文)。不确定我是否需要将 bbox 转换为多边形来执行此操作。

raster = county raster 
plot_parcel_bb = bbox 
county_shp = county shape

    #4.Use bounding box to clip the appropriate county imagery tile (raster&vector in QGIS)

#Check class
class(raster) 
class(plot_parcel_bb)

#Check extents
extent(raster)
extent(plot_parcel_bb)

#set the raster image extent to match the shp extent
new_raster<- setExtent(raster, ext = county_shp)
extent(new_raster)

#check the raster and plot parcels crs
st_crs(new_raster)
st_crs(plot_parcel_bb)

#make sure both crs's match 
crs(new_raster) <- "EPSG:4326"
st_crs(new_raster)


#this does not overlap
cropped<- crop(new_raster, extent(plot_parcel_bb), filename = "cropped", snap = 'near')

我是否需要覆盖图像 shapefile 和光栅并从中剪裁 bbox?也许我从错误的地方开始。我不确定要先采取哪一步。

我在这个网站的正确位置吗 - https://datacarpentry.org/r-raster-vector-geospatial/11-vector-raster-integration/

谢谢

【问题讨论】:

  • 请参阅raster::crop --- 或者,如果您想要更详细的答案,请编辑您的问题以更清楚地解释您的目标以及您遇到的问题,包括 minimal,独立的、可重复的示例.
  • 会的,谢谢罗伯特

标签: r crop intersection bounding-box clip


【解决方案1】:

参见?raster::crop?terra::crop 中的示例

示例数据

library(raster)
p <- shapefile(system.file("external/lux.shp", package="raster"))
r <- raster(extent(p) + 3, resolution=0.1)
values(r) <- 1:ncell(r)

裁剪具有多边形范围的栅格

x <- crop(r, p)

据我所见,您似乎对一些基础知识有些困惑,首先阅读教程可能是个好主意,例如来自https://rspatial.org/

【讨论】:

  • 我很困惑,你是对的,谢谢罗伯特,我很感激(:
猜你喜欢
  • 2013-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多