Commit 2def921a authored by Johannes Knoch's avatar Johannes Knoch
Browse files

Merge branch 'WriteOutSamples' into 'master'

renamed the function and output names and put in missing packages for functions used

See merge request !19
parents 865d2f66 d78a1249
Pipeline #25238 passed with stages
in 10 minutes and 26 seconds
......@@ -12,5 +12,5 @@ export(sample_nb)
export(save_class_tiff)
export(save_kml)
export(save_run)
export(write_Out_Samples)
export(writeOutSamples)
exportClasses(Habitat)
......@@ -2,25 +2,26 @@
#'
#'Writes out a set of samples (SpatialPointsDataFrame) into ESRI shapefiles or a GeoJSON file for a selected habitat type. Each point represents a valid sample location that identifies the selected habitat type.
#'
#' @param inPath file path (character) for results of habitat type sampling and probability mapping (same as outPath from function multi_Class_Sampling)
#' @param in_path file path (character) for results of habitat type sampling and probability mapping (same as outPath from function multi_Class_Sampling)
#' @param step step number (numeric)
#' @param className name (character) of habitat type for which samples should be selected
#' @param class_name name (character) of habitat type for which samples should be selected
#' @param output_format format (character) of output; whether shp (default) or geojson
#'
#' @return ESRI shapefiles/GeoJSON with name: RefHaSa_step_classname.shp/RefHaSa_step_classname.geojson
#' 1) Point Shape represents pixel that belong to selected habitat type and can be used as reference for further model building
#' @return ESRI shapefiles/GeoJSON with name: SamplePoints_step_classname.shp/SamplePoints_step_classname.geojson
#' 1) Point Shape/GeoJSON represents pixel that belong to selected habitat type and can be used as reference for further model building.
#' ESRI shapefiles have the same CRS as the input raster. GeoJSON files are in the standard CRS of GeoJSON (EPSG:4326).
#'
#'
#' @export
###write out selected samples
write_Out_Samples <- function (inPath, step, className, output_format = c("shp", "geojson")) {
writeOutSamples <- function (in_path, step, class_name, output_format = c("shp", "geojson")) {
paste(inPath, "step_", step, "_", className, ".tif", sep = "")
run1 <- get(load(paste(inPath, "Run", step, sep = "")))
load(paste(inPath, "threshold_step_", step, sep = ""))
paste(in_path, "step_", step, "_", class_name, ".tif", sep = "")
run1 <- get(load(paste(in_path, "Run", step, sep = "")))
load(paste(in_path, "threshold_step_", step, sep = ""))
dummy_sample <-
raster::raster(paste(inPath, "step_", step, "_", className, ".tif", sep =
raster::raster(paste(in_path, "step_", step, "_", class_name, ".tif", sep =
""))
length_threshold <- length(threshold)
......@@ -58,27 +59,24 @@ write_Out_Samples <- function (inPath, step, className, output_format = c("shp",
output_format <- match.arg(output_format)
if (output_format == "geojson") {
crs_dummy <- sp::proj4string(dummy_sample)
crs(res) <- crs_dummy
res <- sp::spTransform(res, CRS("+proj=longlat +datum=WGS84 +init=epsg:4326"))
raster::crs(res) <- sp::proj4string(dummy_sample)
res <- sp::spTransform(res, sp::CRS("+init=epsg:4326"))
rgdal::writeOGR(
res,
layer = paste("RefHaSa_step_", step, "_", className, sep = ""),
dsn = paste(inPath, "RefHaSa_step_", step, "_", className, ".geojson", sep = ""),
obj = res,
layer = paste("SamplePoints_step_", step, "_", class_name, sep = ""),
dsn = paste(in_path, "SamplePoints_step_", step, "_", class_name, ".geojson", sep = ""),
driver = "GeoJSON",
check_exists = TRUE,
overwrite_layer = TRUE
)
} else {
crs_dummy <- sp::proj4string(dummy_sample)
crs(res) <- crs_dummy
res <- sp::spTransform(res, CRS("+proj=longlat +datum=WGS84 +init=epsg:4326"))
raster::crs(res) <- sp::proj4string(dummy_sample)
rgdal::writeOGR(
res,
layer = paste("RefHaSa_step_", step, "_", className, sep = ""),
dsn = paste(inPath, "RefHaSa_", className, "_", step, ".shp", sep = ""),
obj = res,
layer = paste("SamplePoints_step_", step, "_", class_name, sep = ""),
dsn = paste(in_path, "SamplePoints_step_", step, "_", class_name, ".shp", sep = ""),
driver = "ESRI Shapefile",
check_exists = TRUE,
overwrite_layer = TRUE
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/WriteOutSamples.r
\name{write_Out_Samples}
\alias{write_Out_Samples}
% Please edit documentation in R/writeOutSamples.r
\name{writeOutSamples}
\alias{writeOutSamples}
\title{Sample Collection for Habitat Types}
\usage{
write_Out_Samples(inPath, step, className, output_format = c("shp", "geojson"))
writeOutSamples(in_path, step, class_name, output_format = c("shp", "geojson"))
}
\arguments{
\item{inPath}{file path (character) for results of habitat type sampling and probability mapping (same as outPath from function multi_Class_Sampling)}
\item{in_path}{file path (character) for results of habitat type sampling and probability mapping (same as outPath from function multi_Class_Sampling)}
\item{step}{step number (numeric)}
\item{className}{name (character) of habitat type for which samples should be selected}
\item{class_name}{name (character) of habitat type for which samples should be selected}
\item{output_format}{format (character) of output; whether shp (default) or geojson}
}
\value{
ESRI shapefiles/GeoJSON with name: RefHaSa_step_classname.shp/RefHaSa_step_classname.geojson
ESRI shapefiles/GeoJSON with name: SamplePoints_step_classname.shp/SamplePoints_step_classname.geojson
\enumerate{
\item Point Shape represents pixel that belong to selected habitat type and can be used as reference for further model building
\item Point Shape/GeoJSON represents pixel that belong to selected habitat type and can be used as reference for further model building.
ESRI shapefiles have the same CRS as the input raster. GeoJSON files are in the standard CRS of GeoJSON (EPSG:4326).
}
}
\description{
......
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