To subset the extent of a raster to a desired area, we use the 'crop' function in the 'raster' package. This is the most commonly used function to modify the extent of a raster object. The raster function takes two main arguments:
...
RasterLayer object Coordinate Reference System (CRS)
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
SPGC.2010q3.rl
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## class : RasterLayer
## dimensions : 135159, 141481, 19122430479 (nrow, ncol, ncell)
## resolution : 30, 30 (x, y)
## extent : -1944645, 2299785, -4910195, -855425 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs
## data source : C:/Users/uqbblanc/Documents/TERN/04b-DSDP_GitHub/Prep/Landscapes_AusCover-RemoteSensing/YasiEffectsonGCatMB/YasiEffectsonGCatMB_Tutorial/SPGC_2010q3.vrt
## names : SPGC_2010q3
## values : 0, 255 (min, max)
|
.
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
crs(SPGC.2010q3.rl)
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## CRS arguments:
## +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=132 +x_0=0 +y_0=0
## +ellps=GRS80 +units=m +no_defs
|
.
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
CRS("+init=epsg:3577")
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## CRS arguments:
## +init=epsg:3577 +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0
## +lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0
## +units=m +no_defs
|
.
.
.
Reproject SpatialPolygons object and create an Extent object
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
StudyArea.SP.reprj = spTransform(StudyArea.SP, CRS("+init=epsg:3577"))
StudyArea.extent.reprj = extent(StudyArea.SP.reprj)
StudyArea.extent.reprj
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## class : Extent
## xmin : 1484019
## xmax : 1490198
## ymin : -1996975
## ymax : -1988144
|
.
.
.
Crop (Spatially Subset) RasterLayer objects
.
Example 1: SPGC for the Winter of 2010
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
SPGC.StudyArea.2010q3.rl = crop(SPGC.2010q3.rl, StudyArea.extent.reprj)
SPGC.StudyArea.2010q3.rl
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## class : RasterLayer
## dimensions : 295, 206, 60770 (nrow, ncol, ncell)
## resolution : 30, 30 (x, y)
## extent : 1484025, 1490205, -1996985, -1988135 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs
## data source : in memory
## names : SPGC_2010q3
## values : 100, 197 (min, max)
|
.
Example 2: SPGC for the Winter of 2011
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
SPGC.StudyArea.2011q3.rl = crop(SPGC.2011q3.rl, StudyArea.extent.reprj)
SPGC.StudyArea.2011q3.rl
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## class : RasterLayer
## dimensions : 295, 206, 60770 (nrow, ncol, ncell)
## resolution : 30, 30 (x, y)
## extent : 1484025, 1490205, -1996985, -1988135 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs
## data source : in memory
## names : SPGC_2011q3
## values : 100, 196 (min, max)
|
.
.
.