Commit 4415836b authored by Johannes Knoch's avatar Johannes Knoch
Browse files

adjusted docu and implemented new flag in writeOutSamples.r; default output...

adjusted docu and implemented new flag in writeOutSamples.r; default output format is shape; use output_format = 'geojson' for geojson output
parent 293b6570
#' Sample Collection for Habitat Types #' Sample Collection for Habitat Types
#' #'
#'Writes out a set of samples (SpatialPointsDataFrame) into an GeoJSON file for a selected habitat type. Each point represents a valid sample location that identifies the selected habitat type. #'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 inPath 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 step step number (numeric)
#' @param className name (character) of habitat type for which samples should be selected #' @param className name (character) of habitat type for which samples should be selected
#' @param output_format format (character) of output; whether shp (default) or geojson
#' #'
#' @return GeoJSON file with name: RefHaSa_step_classname.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 #' 1) Point Shape represents pixel that belong to selected habitat type and can be used as reference for further model building
#' #'
#' #'
#' @export #' @export
###write out selected samples ###write out selected samples
write_Out_Samples <- function (inPath, step, className) { write_Out_Samples <- function (inPath, step, className, output_format = c("shp", "geojson")) {
paste(inPath, "step_", step, "_", className, ".tif", sep = "") paste(inPath, "step_", step, "_", className, ".tif", sep = "")
run1 <- get(load(paste(inPath, "Run", step, sep = ""))) run1 <- get(load(paste(inPath, "Run", step, sep = "")))
...@@ -54,16 +55,33 @@ write_Out_Samples <- function (inPath, step, className) { ...@@ -54,16 +55,33 @@ write_Out_Samples <- function (inPath, step, className) {
res <- result[-which(is.na(res)), ] res <- result[-which(is.na(res)), ]
} }
crs_dummy <- sp::proj4string(dummy_sample) output_format <- match.arg(output_format)
crs(res) <- crs_dummy
res <- sp::spTransform(res, CRS("+proj=longlat +datum=WGS84 +init=epsg:4326")) 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"))
rgdal::writeOGR(
res,
layer = paste("RefHaSa_step_", step, "_", className, sep = ""),
dsn = paste(inPath, "RefHaSa_step_", step, "_", className, ".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"))
rgdal::writeOGR( rgdal::writeOGR(
res, res,
layer = paste("RefHaSa_step_", step, "_", className, sep = ""), layer = paste("RefHaSa_step_", step, "_", className, sep = ""),
dsn = paste(inPath, "RefHaSa_step_", step, "_", className, ".geojson", sep = ""), dsn = paste(inPath, "RefHaSa_", className, "_", step, ".shp", sep = ""),
driver = "GeoJSON", driver = "ESRI Shapefile",
check_exists = TRUE, check_exists = TRUE,
overwrite_layer = TRUE overwrite_layer = TRUE
) )
}
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
\alias{write_Out_Samples} \alias{write_Out_Samples}
\title{Sample Collection for Habitat Types} \title{Sample Collection for Habitat Types}
\usage{ \usage{
write_Out_Samples(inPath, step, className) write_Out_Samples(inPath, step, className, output_format = c("shp", "geojson"))
} }
\arguments{ \arguments{
\item{inPath}{file path (character) for results of habitat type sampling and probability mapping (same as outPath from function multi_Class_Sampling)} \item{inPath}{file path (character) for results of habitat type sampling and probability mapping (same as outPath from function multi_Class_Sampling)}
...@@ -12,13 +12,15 @@ write_Out_Samples(inPath, step, className) ...@@ -12,13 +12,15 @@ write_Out_Samples(inPath, step, className)
\item{step}{step number (numeric)} \item{step}{step number (numeric)}
\item{className}{name (character) of habitat type for which samples should be selected} \item{className}{name (character) of habitat type for which samples should be selected}
\item{output_format}{format (character) of output; whether shp (default) or geojson}
} }
\value{ \value{
GeoJSON file with name: RefHaSa_step_classname.geojson ESRI shapefiles/GeoJSON with name: RefHaSa_step_classname.shp/RefHaSa_step_classname.geojson
\enumerate{ \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 represents pixel that belong to selected habitat type and can be used as reference for further model building
} }
} }
\description{ \description{
Writes out a set of samples (SpatialPointsDataFrame) into an GeoJSON file for a selected habitat type. Each point represents a valid sample location that identifies the selected habitat type. 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.
} }
Supports Markdown
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