我有两个SpatialPolygonsDataFrame文件:dat1,dat2
extent(dat1)
class : Extent
xmin : -180
xmax : 180
ymin : -90
ymax : 90
extent(dat2)
class : Extent
xmin : -120.0014
xmax : -109.9997
ymin : 48.99944
ymax : 60
Run Code Online (Sandbox Code Playgroud)
我想使用dat2的范围裁剪文件dat1.我不知道怎么做.我之前只使用"crop"函数处理光栅文件.
当我将此函数用于当前数据时,会发生以下错误:
> r1 <- crop(BiomassCarbon.shp,alberta.shp)
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function ‘crop’ for signature"SpatialPolygonsDataFrame"’
Run Code Online (Sandbox Code Playgroud) 我需要删除R包"raster"中图形周围的框框,但我无法弄清楚应该更改哪个参数.示例如下:
library(raster)
r <- raster(nrows=10, ncols=10)
r <- setValues(r, 1:ncell(r))
plot(r)
plot(r,axes=F)
Run Code Online (Sandbox Code Playgroud) 尝试使用R从一个文件夹创建一个zip文件.
它在这里提到了"Rcompression"包: 从文件夹创建zip文件
但我没有找到我可以在哪里下载Windows系统的这个包.
有什么建议?或其他功能来创建一个zip文件?
我有一个带空间坐标和一个变量的矩阵数据.空间分辨率为1000米.
> str(dat1)
> List of 3
> $ x: num [1:710] 302340 303340 304340 305340 306340 ...
> $ y: num [1:1241] 5431470 5432470 5433470 5434470 5435470 ...
> $ z: num [1:710, 1:1241] 225 225 225 225 225 ...
Run Code Online (Sandbox Code Playgroud)
我想将其转换为栅格格式.
> dat1$x[1:10]
> [1] 302339.6 303339.6 304339.6 305339.6 306339.6 307339.6 308339.6 309339.6 310339.6 311339.6
> dat1$y[1:10]
> [1] 5431470 5432470 5433470 5434470 5435470 5436470 5437470 5438470 5439470 5440470
Run Code Online (Sandbox Code Playgroud)
我使用以下代码来完成它.但我得到的决议与我的决议不一样.有没有更好的方法来获得与我的真实数据相同的分辨率?
> r <-raster(
dat1$z,
xmn=range(dat1$x)[1], xmx=range(dat1$x)[2],
ymn=range(dat1$y)[1], ymx=range(dat1$y)[2],
crs=CRS("+proj=utm …Run Code Online (Sandbox Code Playgroud) 我想删除栅格数据集的"levelplot"图中的框架.不知道怎么做.
library(raster)
library(rasterVis)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
s <- stack(r, r+500, r-500)
levelplot(s, contour=TRUE)
levelplot(s)
levelplot(s,box=FALSE,axes=FALSE) # It doesn't work.
Run Code Online (Sandbox Code Playgroud) 我需要将shapefile转换为栅格格式.
我在R包"raster"中使用了"rasterize"功能,但结果看起来不正确.
tst <- rasterize(shpfile, r, fun="count")
Found 5 region(s) and 5 polygon(s)
Run Code Online (Sandbox Code Playgroud)
没有发生记录的网格:
range(tst[],na.rm=TRUE)
[1] Inf -Inf
Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
sum(tst[],na.rm=TRUE)
[1] 0
Run Code Online (Sandbox Code Playgroud)
我写的R脚本:
# download the GIS shape file
download.file("http://esp.cr.usgs.gov/data/little/abiebrac.zip",
destfile = "abiebrac.zip")
# unzip
unzip("abiebrac.zip")
# Read shapefile into R
library(maptools)
shpfile <- readShapePoly("abiebrac")
extent(shpfile)
# mapping
plot(shpfile)
library(maps)
map("world",xlim=c(-180,-50),ylim=c(7,83),add=FALSE)
plot(shpfile,add=TRUE,lwd=10)
# rasterize
library(raster)
GridSize <- …Run Code Online (Sandbox Code Playgroud) 我想把以下GIS数据文件读入R:
一些数据规范在这里:
图像类型:通用平面二进制,字节交错(BIL)
投射:中断Goode Homolosine
我试图使用R包"raster",但失败了.
library(raster)
r <- raster(file.choose())
Error in .local(.Object, ...) :
`C:\global_forest_cover.img' not recognised as a supported file format.
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file.
Run Code Online (Sandbox Code Playgroud)
那么,我该如何将这个GIS数据加载到R中呢?另外,将投影"Interrupted Goode Homolosine"转换为LongLat?