裁剪R中有多边形的光栅:错误范围不重叠
我想使用我在ArcGIS中制作的多边形形状文件裁剪光栅堆栈,但我得到的错误是范围不重叠 首先,我创建光栅堆栈:裁剪R中有多边形的光栅:错误范围不重叠,r,image-processing,crop,raster,R,Image Processing,Crop,Raster,我想使用我在ArcGIS中制作的多边形形状文件裁剪光栅堆栈,但我得到的错误是范围不重叠 首先,我创建光栅堆栈: test1 < stack("C:/mydir/test1.tif") 这一信息不言自明。您的范围不重叠。。。以下是如何检查: library(raster) ext.ras <- extent(6e+05, 709800, 5690220, 5800020) ext.pol <- extent(499386.6, 517068.2, 6840730, 685727
test1 < stack("C:/mydir/test1.tif")
这一信息不言自明。您的范围不重叠。。。以下是如何检查:
library(raster)
ext.ras <- extent(6e+05, 709800, 5690220, 5800020)
ext.pol <- extent(499386.6, 517068.2, 6840730, 6857271)
plot(ext.ras, xlim = c( 499386.6,709800), ylim= c(5690220,6857271), col="red")
plot(ext.pol, add=T, col="blue")
库(光栅)
谢谢你,我按照你的建议使用了readOGR()和spTransform(),效果非常好。这可能是因为,在调用myExtent时
myExtent <- readShapePoly("C:/mydir/loc1.shp", verbose=TRUE, proj4string=myCRS)
myCrop <- crop(test1, myExtent)
Error in .local(x, y, ...) : extents do not overlap
> test1$test1.1
class : RasterLayer
band : 1 (of 4 bands)
dimensions : 10980, 10980, 120560400 (nrow, ncol, ncell)
resolution : 10, 10 (x, y)
extent : 6e+05, 709800, 5690220, 5800020 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=31 +datum=WGS84 +units=m +no_defs +ellps=WGS84
+towgs84=0,0,0
data source : C:\mydir\test1.tif
names : test1.1
values : 0, 65535 (min, max)
> myExtent
class : SpatialPolygonsDataFrame
features : 1
extent : 499386.6, 517068.2, 6840730, 6857271 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=31 +datum=WGS84 +units=m +no_defs +ellps=WGS84
+towgs84=0,0,0
variables : 2
names : Shape_Leng, Shape_Area
min values : 67444.6461177, 283926851.657
max values : 67444.6461177, 283926851.657
library(raster)
ext.ras <- extent(6e+05, 709800, 5690220, 5800020)
ext.pol <- extent(499386.6, 517068.2, 6840730, 6857271)
plot(ext.ras, xlim = c( 499386.6,709800), ylim= c(5690220,6857271), col="red")
plot(ext.pol, add=T, col="blue")
myExtent <- readShapePoly("C:/mydir/loc1.shp", verbose=TRUE, proj4string=myCRS)
library(rgdal)
myExtent <- readOGR("C:/mydir","loc1.shp")
myExtent <- spTRansform(myExtent, CRS(proj4string(test1)))