Skip to content

Commit

Permalink
# biodivMapR v1.12.0
Browse files Browse the repository at this point in the history
## Fix
- remove dependency to rgdal and rgeos (issue #18)
  • Loading branch information
jbferet committed Sep 16, 2023
1 parent df5fe49 commit 8375e23
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 131 deletions.
19 changes: 11 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: biodivMapR
Title: biodivMapR: an R package for a- and ß-diversity mapping using remotely-sensed images
Version: 1.11.1
Version: 1.12.0
Authors@R: c(person(given = "Jean-Baptiste",
family = "Feret",
email = "jb.feret@teledetection.fr",
Expand All @@ -18,28 +18,31 @@ Encoding: UTF-8
License: GPL-3 + file LICENSE
LazyData: true
Imports:
dissUtils,
ape,
cli,
data.table,
dissUtils,
dplyr,
fields,
future,
future.apply,
gdalUtilities,
geometry,
jsonlite,
labdsv,
magrittr,
matlab,
matrixStats,
mmand,
progressr,
raster,
rgdal,
snow,
stars,
stringr,
terra,
tools,
vegan,
zip,
progressr,
cli,
ape,
terra
zip
RoxygenNote: 7.2.3
Suggests:
knitr,
Expand Down
24 changes: 13 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export(exclude_spectral_domains)
export(extract.big_raster)
export(extract_pixels)
export(extract_pixels_coordinates)
export(extract_pixels_coordinates.From.OGR)
export(extract_samples_from_image)
export(filter_PCA)
export(filter_prior_CR)
Expand All @@ -52,6 +51,7 @@ export(get_Shannon)
export(get_Simpson)
export(get_alpha_metrics)
export(get_byte_order)
export(get_gdal_info)
export(get_image_bands)
export(get_random_subset_from_image)
export(get_sunlit_pixels)
Expand Down Expand Up @@ -99,19 +99,26 @@ export(write_PCA_raster)
export(write_StarsStack)
export(write_raster)
import(cli)
import(magrittr)
import(stars)
import(tools)
importFrom(ape,mst)
importFrom(data.table,data.table)
importFrom(data.table,rbindlist)
importFrom(data.table,setorder)
importFrom(dissUtils,diss)
importFrom(dplyr,group_by)
importFrom(dplyr,group_split)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(fields,rdist)
importFrom(future,multisession)
importFrom(future,plan)
importFrom(future,sequential)
importFrom(future.apply,future_lapply)
importFrom(gdalUtilities,gdalinfo)
importFrom(geometry,convhulln)
importFrom(jsonlite,fromJSON)
importFrom(labdsv,pco)
importFrom(matlab,meshgrid)
importFrom(matlab,ones)
Expand All @@ -123,22 +130,12 @@ importFrom(progressr,handlers)
importFrom(progressr,progressor)
importFrom(progressr,with_progress)
importFrom(raster,brick)
importFrom(raster,cellFromPolygon)
importFrom(raster,cellFromXY)
importFrom(raster,compareCRS)
importFrom(raster,hdr)
importFrom(raster,nbands)
importFrom(raster,ncell)
importFrom(raster,projection)
importFrom(raster,raster)
importFrom(raster,values)
importFrom(raster,writeRaster)
importFrom(rgdal,GDAL.close)
importFrom(rgdal,GDAL.open)
importFrom(rgdal,GDALinfo)
importFrom(rgdal,getDriver)
importFrom(rgdal,getDriverLongName)
importFrom(rgdal,readOGR)
importFrom(snow,splitCols)
importFrom(snow,splitList)
importFrom(snow,splitRows)
Expand All @@ -154,8 +151,13 @@ importFrom(stats,prcomp)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(stringr,str_count)
importFrom(terra,cells)
importFrom(terra,colFromCell)
importFrom(terra,rast)
importFrom(terra,rowFromCell)
importFrom(terra,same.crs)
importFrom(terra,values)
importFrom(terra,vect)
importFrom(tools,file_path_sans_ext)
importFrom(utils,file.edit)
importFrom(utils,read.table)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# biodivMapR v1.12.0

## Fix
- remove dependency to rgdal and rgeos (issue #18)

# biodivMapR v1.11.1

## Change
Expand Down
18 changes: 16 additions & 2 deletions R/Lib_ImageProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ extract.big_raster <- function(ImPath, rowcol, MaxRAM=.50){
# stars data cube dimension order is x*y*band
ipix_stars <- (rc$rowInBlock-min(rc$rowInBlock))*nXSize+rc$col
# get driver
driver <- attr(rgdal::GDALinfo(ImPath,returnStats = FALSE), 'driver')
values <- read_stars(ImPath, RasterIO =list(nXSize=nXSize, nYOff=rr[1], nYSize=nYSize),proxy = FALSE, driver=driver)[[1]]
driver <- get_gdal_info(ImPath)$driverShortName
values <- read_stars(ImPath, RasterIO =list(nXSize=nXSize, nYOff=rr[1], nYSize=nYSize), proxy = FALSE, driver = driver)[[1]]
values <- matrix(values, nrow=nYSize*nXSize)
if (length(ipix_stars)>1){
res <- cbind(rc$sampleIndex, values[ipix_stars, ])
Expand Down Expand Up @@ -689,6 +689,20 @@ get_byte_order <- function() {
return(ByteOrder)
}

#' Get GDAL info as a nested list
#' @param x character. Raster image path.
#' @return list. Nested list of raster characteristics.
#' @import magrittr
#' @importFrom gdalUtilities gdalinfo
#' @importFrom jsonlite fromJSON
#' @export
get_gdal_info <- function(x){
x <- normalizePath(x)
if(!file.exists(x))
stop("File not found: ", x)
gdalUtilities::gdalinfo(x, json = TRUE, quiet = TRUE) %>%
jsonlite::fromJSON()
}
#' get hdr name from image file name, assuming it is BIL format
#'
#' @param ImPath character. ath of the image
Expand Down
8 changes: 4 additions & 4 deletions R/Lib_MapAlphaDiversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ compute_SSD <- function(Image_Chunk, window_size, nbclusters,
#'
#' @return list. includes Spectral_Species_Path
#' @importFrom stars read_stars write_stars
#' @importFrom rgdal GDALinfo
#' @importFrom tools file_path_sans_ext
#' @export

Expand Down Expand Up @@ -583,8 +582,9 @@ get_SSpath <- function(Output_Dir, Input_Image_File, TypePCA, ClassifMap, nbclus
}
# save classification map in proper format in output directory
# if not expected file format for Spectral Species map
driver <- attr(rgdal::GDALinfo(ClassifMap,returnStats = FALSE), 'driver')
df <- unique(attr(rgdal::GDALinfo(ClassifMap,returnStats = FALSE),"df")$GDType)
info <- get_gdal_info(ClassifMap)
driver <- info$driverShortName
df <- unique(info$bands$type)
if (driver=='ENVI' & df =='Byte'){
if (Input_Image_File==FALSE){
Input_Image_File <- tools::file_path_sans_ext(basename(ClassifMap))
Expand Down Expand Up @@ -726,7 +726,7 @@ compute_ALPHA_SSD_per_window <- function(listAlpha, nb_partitions, nbclusters,
SimpsonAlpha <- NA*vector(length = nb_partitions)
SSDMap <- NA*vector(length = nb_partitions*nbclusters)
}
res <- list('shannonIter' = shannonIter, 'SimpsonAlpha' = SimpsonAlpha,
res <- list('shannonIter' = shannonIter, 'SimpsonAlpha' = SimpsonAlpha,
'FisherAlpha' = FisherAlpha, 'SSDMap' = SSDMap)
return(res)
}
Expand Down
2 changes: 0 additions & 2 deletions R/Lib_MapFunctionalDiversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ map_functional_div <- function(Original_Image_File,Functional_File = FALSE,
#' @importFrom future.apply future_lapply
#' @importFrom stats sd
#' @import cli
#' @importFrom future plan multisession sequential
#' @importFrom future.apply future_lapply
#' @importFrom terra rast values
#' @export

Expand Down
12 changes: 1 addition & 11 deletions R/Lib_MapSpectralSpecies.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#'
#' @return Kmeans_info
#' @importFrom utils read.table
#' @importFrom rgdal getDriverLongName getDriver GDAL.open GDAL.close
#' @export
map_spectral_species <- function(Input_Image_File, Output_Dir,
SpectralSpace_Output,
Expand All @@ -40,12 +39,7 @@ map_spectral_species <- function(Input_Image_File, Output_Dir,

# check if input mask file has expected format
if (!Input_Mask_File==FALSE){
# driverMask_class <- new("GDALReadOnlyDataset", Input_Mask_File)
driverMask_class <- GDAL.open(filename = Input_Mask_File,
read.only = TRUE, silent=FALSE,
allowedDrivers = NULL, options=NULL)
driverMask <- rgdal::getDriverLongName(getDriver(driverMask_class))
GDAL.close(driverMask_class)
driverMask <- get_gdal_info(Input_Mask_File)$driverLongName
if (driverMask == 'ENVI .hdr Labelled'){
HDR <- read_ENVI_header(get_HDR_name(Input_Mask_File))
if (!HDR$`data type`==1){
Expand Down Expand Up @@ -589,7 +583,3 @@ error_PC_sel <- function(Output_Dir_PCA){
print("or in the 'SelectedPCs' variable of map_spectral_species")
print("Image processing aborted")
}




Loading

0 comments on commit 8375e23

Please sign in to comment.