1

R でポリゴンをラスターに変換する際に大きな問題を抱えています。つまり、属性テーブルには 574 行あります (つまり、FID は 0 ~ 573 です)。データのサブセットはこちらにあります: https://drive.google.com/file/d/1AdTChjerCXopE1-PZIAPp5ZXISdq45i8/view?usp=sharing

ラスターに変換したかったのです。出力ラスターでは、最小値と最大値が 1 と 574 であることがわかります。私が疑うのは、セル内のフィールド ID を取得してはならないピクセル値として取得していることです。セルの値は、カバー ポリゴンから取得する必要があります。どんな助けでも大歓迎です。以下はサンプルコードです。

library(raster)
library(rgdal)
library(maptools)


# define porjection
projection1 <- CRS ("+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs")

# load species polygons for all 574 species
# already in the home directory

sp <- readShapePoly("AllP574sp.shp", proj4string = projection1)

# load a raster file to use as a mirror for rasterize
raster1 <- raster("/data/projects/MeanTemp2050rcp45_BCC_CSM1_1.tif")


r.sp <- rasterize(sp, raster1) # rasterize our species polygon to the same resoluton of loaded raster

writeRaster(r.sp, "/data/projects/all574spRaster", format = "GTiff", overwrite = TRUE)

出力ラスターのプロパティを以下に示します。

class       : RasterLayer 
dimensions  : 18000, 43200, 777600000  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : E:\all574spRaster.tif 
names       : all574spRaster 
values      : 1, 574  (min, max)
4

1 に答える 1