I am a beginning user of Rstudio, and I want to run Random Forest by using a couple of "raster layers" which were stacked in ENVI.
Before doing stacking I checked the cell size and the columns and rows numbers in GIS which they all had the same cell size and the columns and rows numbers. My data contains slope, aspect, landuse, geology, etc.
The main problem is that the following error happens whether I entered just one raster layer or whole layer as a stack layer I face with the error
library(rgdal)
Loading required package: sp
rgdal: version: 1.5-12, (SVN revision 1018)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
Path to GDAL shared files: C:/Program Files/R/R-4.0.2/library/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
Path to PROJ shared files: C:/Program Files/R/R-4.0.2/library/rgdal/proj
Linking to sp version:1.4-2
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
library(sp)
library(raster)
library(caret)
Loading required package: lattice
Loading required package: ggplot2
library(lattice)
library(ggplot2
library(readr)
img1 <- read_csv("E:/Topic_sinkholes/Final data/stack layers/img1.hdr")
Parsed with column specification:
cols(
ENVI = col_character()
)
Warning: 8 parsing failures.
row col expected actual file
12 -- 1 columns 11 columns 'E:/Topic_sinkholes/Final data/stack layers/img1.hdr'
13 -- 1 columns 23 columns 'E:/Topic_sinkholes/Final data/stack layers/img1.hdr'
16 -- 1 columns 3 columns 'E:/Topic_sinkholes/Final data/stack layers/img1.hdr'
17 -- 1 columns 2 columns 'E:/Topic_sinkholes/Final data/stack layers/img1.hdr'
18 -- 1 columns 3 columns 'E:/Topic_sinkholes/Final data/stack layers/img1.hdr'
... ... ......... .......... .....................................................
See problems(...) for more details.
This error happens even when I enter layers with TIFF format
I tried the suggested direction from the comments, but the problem still remains:
library(raster) library(readr) img1 <- read_csv("E:/Topic_sinkholes/Final data/stack layers/img1.img") Parsed with column specification: cols( EHFA_HEADER_TAG = col_character() ) Warning: 153556 parsing failures. row col expected actual file 1 EHFA_HEADER_TAG embedded null 'E:/Topic_sinkholes/Final data/stack layers/img1.img' 1 NA 1 columns 222 columns 'E:/Topic_sinkholes/Final data/stack layers/img1.img' 2 EHFA_HEADER_TAG embedded null 'E:/Topic_sinkholes/Final data/stack layers/img1.img' 3 EHFA_HEADER_TAG embedded null 'E:/Topic_sinkholes/Final data/stack layers/img1.img' 3 NA 1 columns 2 columns 'E:/Topic_sinkholes/Final data/stack layers/img1.img' ... ............... ......... ............. ..................................................... See problems(...) for more details.
View(img1) raster() class : RasterLayer dimensions : 180, 360, 64800 (nrow, ncol, ncell) resolution : 1, 1 (x, y) extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs
resd.csv
to read an img or hdr file? The correct function(s) areraster
for single band andstack
orbrick
for multi band raster data.