Commit 729ad162 authored by floriandeboissieu's avatar floriandeboissieu

fix: CRS comparison in diversity_from_plots, removed get_projection

parent 06f1204a
......@@ -2,7 +2,6 @@
export(check_data)
export(diversity_from_plots)
export(get_projection)
export(list_shp)
export(map_alpha_div)
export(map_beta_div)
......@@ -28,7 +27,6 @@ importFrom(matrixStats,rowSds)
importFrom(methods,is)
importFrom(raster,projection)
importFrom(raster,raster)
importFrom(raster,shapefile)
importFrom(raster,writeRaster)
importFrom(rgdal,readOGR)
importFrom(rgdal,writeOGR)
......
......@@ -6,6 +6,7 @@
- moved examples to repository root: example files are not installed with package anymore.
- removed Plots reprojection from `diversity_from_plots`:
now, Plots and Raster must be in the same projection. Changed example Plots projection accordingly.
- removed `get_projection` (useless)
# biodivMapR v1.0.1 (Release date: 2019-09-27)
......
......@@ -10,26 +10,6 @@
# the main goal is to validate ground data associated with biodiversity metrics
# ==============================================================================
#' get projection of a raster or a vector
#' @param file path for a raster or vector (shapefile)
#' @param type 'raster' or 'vector'
#' @return projection
#' @importFrom raster raster shapefile projection
#' @importFrom rgdal readOGR
#' @import tools
#' @export
get_projection <- function(file, type = 'raster'){
if (type == 'raster'){
obj <- raster(file)
} else if (type == 'vector'){
Shp.Path = dirname(file)
Shp.Name = file_path_sans_ext(basename(file))
obj = readOGR(dsn = Shp.Path,layer = Shp.Name,verbose = FALSE)
}
projstr <- projection(obj)
return(projstr)
}
#' Get list of shapefiles in a directory
#'
#' @param x character or list. Directory containing shapefiles
......@@ -141,6 +121,7 @@ get_alpha_metrics = function(Distrib){
#' @param NbClusters numeric. Number of clusters defined in k-Means.
#' @param Name_Plot character. Name of the plots defined in the shapefile
#' @return alpha and beta diversity metrics
#' @importFrom raster raster projection
#' @importFrom rgdal readOGR
#' @import tools
#' @export
......@@ -173,10 +154,8 @@ diversity_from_plots = function(Raster, Plots, NbClusters = 50, Name_Plot = FALS
if (file.exists(paste(file_path_sans_ext(File.Vector),'.shp',sep=''))){
Plot = readOGR(Dir.Vector,Name.Vector[[ip]],verbose = FALSE)
# check if vector and rasters are in the same referential
Projection.Plot = get_projection(File.Vector,'vector')
Projection.Raster = get_projection(Raster,'raster')
# if not, convert vector file
if (compareCRS(Projection.Raster, Projection.Plot)){
if (!compareCRS(raster(Raster), Plot)){
stop('Raster and Plots have different projection. Plots should be reprojected to Raster CRS, see help(')
}
} else if (file.exists(paste(File.Vector,'kml','sep'='.'))){
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Lib_Validation_biodivMapR.R
\name{get_projection}
\alias{get_projection}
\title{get projection of a raster or a vector}
\usage{
get_projection(file, type = "raster")
}
\arguments{
\item{file}{path for a raster or vector (shapefile)}
\item{type}{'raster' or 'vector'}
}
\value{
projection
}
\description{
get projection of a raster or a vector
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment