Dear Joao,
I have being performing pixel based classifications in R but recently I realised that in some ocasions it could be more interesting performing object based ones. I have found your package really usefull to non experts users as it allows to apply OBIA without having to learn to use new programing interfaces. However following the tutorial I'm not able to run a single segmentation approach, I'm obtaining different errors.
I'm performing the classification on a small crop of a raster brick of 4 Sentinel 2 bands (B2,B3,B4 and B8A) as a test dataset.
Using the OTB toolbox, no mather which numbers I set as SpectralRange, SpatialRange and MinSize it always appear this error:
> outSegmRst <- segmentation_OTB_LSMS(
+
+ inputRstPath = "D:/Mapa_forestal/WorldView/multilayer2.tif",
+ SpectralRange=1,
+ SpatialRange=5,
+ MinSize=20,
+ outputSegmRst = "D:/Mapa_forestal/WorldView/OBIA_test/test.tif",
+ verbose = T,
+ otbBinPath = otbBinPath)
SpectralRange=1
SpatialRange=5
MinSize=20
>
Using the GRASS it appears a error in the first step of creating a grass database: On my understanding the GRASS.GISDBASE parameter is already a character vector.
> lista3<-list(B02crop,B03crop,B04crop,B8Acrop)
>
> importToGRASS(fileList=lista3,
+ GRASS.path = GRASS.path,
+ GRASS.GISDBASE = "base.db",
+ GRASS.LOCATION_NAME="D:/Mapa_forestal/WorldView/OBIA_test",
+ GRASS.MAPSET = "PERMANENT",
+ addParams = "",
+ verbose = TRUE)
Error in basename(fin) : a character vector argument expected
>
Using the SAGA segmentation:
|
> segmObj <- segmentation_SAGA_SRG(rstList=lista2, + outputSegmRst="D:/Mapa_forestal/WorldView/OBIA_test/test.sgrd", + Bandwidth=2, + GaussianWeightingBW=5, + VarFeatSpace=3, + VarPosSpace=2, + seedType=0, + method1=0, + DWeighting=3, + normalize=0, + neighbour=0, + method2=0, + thresh=0, + leafSize=1024, + SAGApath=env, + verbose=TRUE) Bandwidth=2 GaussianWeightingBW=5 VarFeatSpace=3 VarPosSpace=2 Error in system(command, as.integer(flag), f, stdout, stderr, timeout) : character string expected as first argument |
|
|
Using the RSGISLib segmentation:
|
> segmObj <- segmentation_RSGISLib_Shep(inputRstPath="D:/Mapa_forestal/WorldView/multilayer2.tif", + outputSegmRst="D:/Mapa_forestal/WorldView/OBIA_test/test.tif", + NumClust=10, + MinSize=20, + SpectralThresh=10, + pythonPath=pythonPath, + verbose=TRUE) NumClust=10 MinSize=20 SpectralThresh=10 Warning message: In shell(tmpBatchFile, ignore.stdout = TRUE, ignore.stderr = TRUE, : 'C:/Users/Laura aM/Documents/RSGISLib_Shep_Segm_mo4pol91.bat' execution failed with error code 1 |
|
|
Thanks in advance. Best regards,
Laura
Full script, following, just in case it is needed:
library(SegOptim)
library(raster)
library(sp)
library(devtools)
library(sf)
GRASS.path <-"C:/Program Files/GRASS GIS 7.2.0/grass72.bat"
otbBinPath <-"C:/Program Files/OTB/OTB-7.1.0-Win64/OTB-7.1.0-Win64/bin"
pythonPath <-"C:/Users/Laura aM/anaconda3/envs/py35"
SAGApath <- "C:/Program Files/saga-7.6.2_x64/saga-7.6.2_x64"
TerraLib.path <- "C:/Program Files/TerraLib/terralib-5.2.1-TISA-win_x64/terralib-5.2.1-TISA/lib"
#cargar datos
B02 <- raster("D:/Mapa_forestal/TMH/Sentinel/S2B_MSIL2A_20190212T113319_N0211_R080_T29TMH_20190212T155715.SAFE/GRANULE/L2A_T29TMH_A010116_20190212T113420/IMG_DATA/R20m/B02.jp2")
B03 <- raster("D:/Mapa_forestal/TMH/Sentinel/S2B_MSIL2A_20190212T113319_N0211_R080_T29TMH_20190212T155715.SAFE/GRANULE/L2A_T29TMH_A010116_20190212T113420/IMG_DATA/R20m/B03.jp2")
B04 <- raster("D:/Mapa_forestal/TMH/Sentinel/S2B_MSIL2A_20190212T113319_N0211_R080_T29TMH_20190212T155715.SAFE/GRANULE/L2A_T29TMH_A010116_20190212T113420/IMG_DATA/R20m/B04.jp2")
B8A <- raster("D:/Mapa_forestal/TMH/Sentinel/S2B_MSIL2A_20190212T113319_N0211_R080_T29TMH_20190212T155715.SAFE/GRANULE/L2A_T29TMH_A010116_20190212T113420/IMG_DATA/R20m/B8A.jp2")
multiple<- stack(B02,B03,B04,B8A)
datos<-brick(multiple)
myExtent <- st_read("D:/Mapa_forestal/WorldView/OBIA_test/polygon.shp")
myExtent2<-st_transform(myExtent, "+proj=utm +zone=29 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0")
datos1<- crop(datos, myExtent2)
writeRaster(datos1, filename="D:/Mapa_forestal/WorldView/multilayer2.tif", options="INTERLEAVE=BAND", overwrite=TRUE)
B02crop<- crop(B02,myExtent2)
writeRaster(datos1, filename="D:/Mapa_forestal/WorldView/B02crop.tif", options="INTERLEAVE=BAND", overwrite=TRUE)
B03crop<- crop(B03,myExtent2)
writeRaster(datos1, filename="D:/Mapa_forestal/WorldView/B03crop.tif", options="INTERLEAVE=BAND", overwrite=TRUE)
B04crop<- crop(B04, myExtent2)
writeRaster(datos1, filename="D:/Mapa_forestal/WorldView/B04crop.tif", options="INTERLEAVE=BAND", overwrite=TRUE)
B8Acrop<- crop(B8A, myExtent2)
writeRaster(datos1, filename="D:/Mapa_forestal/WorldView/B8Acrop.tif", options="INTERLEAVE=BAND", overwrite=TRUE)
########################################################################
# Check the manual for more info on this function parameters
?segmentation_OTB_LSMS
outSegmRst <- segmentation_OTB_LSMS(
inputRstPath = "D:/Mapa_forestal/WorldView/multilayer2.tif",
SpectralRange=1,
SpatialRange=5,
MinSize=20,
outputSegmRst = "D:/Mapa_forestal/WorldView/OBIA_test/test.tif",
verbose = T,
otbBinPath = otbBinPath)
# Check the manual for more info on this function parameters
?segmentation_GRASS_RG
lista<-list(B02crop,B03crop,B04crop,B8Acrop)
importToGRASS(fileList=lista3,
GRASS.path = GRASS.path,
GRASS.GISDBASE = "base.db",
GRASS.LOCATION_NAME="D:/Mapa_forestal/WorldView/OBIA_test",
GRASS.MAPSET = "PERMANENT",
addParams = "",
verbose = TRUE)
segmObj <- segmentation_GRASS_RG(GRASS.path="grass",
GRASS.inputRstName,
GRASS.GISDBASE,
GRASS.LOCATION_NAME="demolocation",
GRASS.MAPSET="PERMANENT",
outputSegmRst=NULL,
Threshold=NULL,
MinSize=NULL,
memory=1024,
iterations=20,
verbose=TRUE)
#######################################################
# Check the manual for more info on this function parameters
?segmentation_SAGA_SRG
library(RSAGA)
env <- rsaga.env()
rsaga.import.gdal(B02crop, "B02crop1.sgrd", env = env)
rsaga.import.gdal(B03crop, "B03crop1.sgrd", env = env)
lista2<-list("B02crop1.sgrd","B03crop1.sgrd")
lista4<-list("D:/Mapa_forestal/WorldView/B4segoptim.sgdr","D:/Mapa_forestal/WorldView/B3segoptim.sgdr")
segmObj <- segmentation_SAGA_SRG(rstList=lista4,
outputSegmRst="D:/Mapa_forestal/WorldView/OBIA_test/test.sgrd",
Bandwidth=2,
GaussianWeightingBW=5,
VarFeatSpace=3,
VarPosSpace=2,
seedType=0,
method1=0,
DWeighting=3,
normalize=0,
neighbour=0,
method2=0,
thresh=0,
leafSize=1024,
SAGApath=env,
verbose=TRUE)
########################################################
# Check the manual for more info on this function parameters
?segmentation_RSGISLib_Shep
segmObj <- segmentation_RSGISLib_Shep(inputRstPath="D:/Mapa_forestal/WorldView/multilayer2.tif",
outputSegmRst="D:/Mapa_forestal/WorldView/OBIA_test/test.tif",
NumClust=10,
MinSize=20,
SpectralThresh=10,
pythonPath=pythonPath,
verbose=TRUE)