не могу открыть соединение в R - PullRequest
0 голосов
/ 01 мая 2020

Я сталкиваюсь с ошибкой соединения R при запуске земли классификация . Я думаю, что это как-то связано с анализом текстур и добавлением этих полос к моему исходному изображению. Я удалил анализ текстур и добавил полосы, и все работает отлично. Есть предложения?

library(caret) # 6.0-86
library(randomForest) # *4.6-14
library(e1071) # 1.7-2
library(raster) # 3.0-12
library(sf) # *0.8-0
library(RStoolbox) # *0.2.6
library(glcm) # 1.6.5
# version 3.5.2

#----------------------------------------------------------------------------

# Load image/shp
img_2 <- brick("C:/Users/name/location/small_ROI2.tif")
shp_2 <- st_read("C:/Users/name/location/Training.shp")

#----------------------------------------------------------------------------

# Convert shp to S4
shpS4_2 <- as_Spatial(shp_2)

#----------------------------------------------------------------------------

# Texture analysis bands
red.glcm <- glcm(img$small_ROI2.1, 
                 window = c(3,3), 
                 shift=list(c(0,1), c(1,1), c(1,0), c(1,-1)), 
                 statistics = c("mean", "variance", "homogeneity", "contrast", 
                                "dissimilarity", "entropy", "second_moment"))

green.glcm <- glcm(img$small_ROI2.2,
                   window = c(3,3), 
                   shift=list(c(0,1), c(1,1), c(1,0), c(1,-1)), 
                   statistics = c("mean", "variance", "homogeneity", "contrast", 
                                  "dissimilarity", "entropy", "second_moment"))
blue.glcm <- glcm(img$small_ROI2.3,
                  window = c(3,3), 
                  shift=list(c(0,1), c(1,1), c(1,0), c(1,-1)), 
                  statistics = c("mean", "variance", "homogeneity", "contrast", 
                                 "dissimilarity", "entropy", "second_moment"))

#----------------------------------------------------------------------------

# Combine and rename Bands
img_update_2 <- addLayer(img_2, red.glcm, green.glcm, blue.glcm)

#----------------------------------------------------------------------------

#Random Forest
SC <- superClass(img_2, trainData = shpS4, responseCol = "id", model = "rf", tuneLength = 1, trainPartition = 0.7)

#----------------------------------------------------------------------------

#Save Raster as .tif
writeRaster(SC$map, filename = "C:/Users/name/location/R_classification.tif")

#----------------------------------------------------------------------------

Error in file(fn, "rb") : cannot open the connection
...