Commit 293b6570 authored by Johannes Knoch's avatar Johannes Knoch
Browse files

adjusted docu and deleted unnessecary lines in function writeOutSamples.r

parent a3033f8b
......@@ -14,41 +14,32 @@
###write out selected samples
write_Out_Samples <- function (inPath, step, className) {
print("function started")
paste(inPath, "step_", step, "_", className, ".tif", sep = "")
run1 <- get(load(paste(inPath, "Run", step, sep = "")))
load(paste(inPath, "threshold_step_", step, sep = ""))
dummy_sample <-
raster::raster(paste(inPath, "step_", step, "_", className, ".tif", sep =
""))
print("problem zone 0")
length_threshold <- length(threshold)
thres <- threshold[length_threshold]
dummy_sample[dummy_sample < thres] <- NA
dummy_sample[dummy_sample >= thres] <- 1
print("problem zone 1")
collect <- list()
j <- 0
###extract only class samples
for (i in 1:length(run1@ref_samples)) {
print("problem zone 1.1")
if (length(dim(run1@ref_samples[[i]])) != 0)
{
print("problem zone 1.2")
if (is.na(run1@switch[i]) == F) {
j = j + 1
collect[[j]] <-
run1@ref_samples[[i]][which(run1@ref_samples[[i]]@data == 1), ]
} else
{
print("problem zone 1.3")
j = j + 1
collect[[j]] <-
run1@ref_samples[[i]][which(run1@ref_samples[[i]]@data == 2), ]
......@@ -56,8 +47,6 @@ write_Out_Samples <- function (inPath, step, className) {
}
}
print("problem zone 2")
result <- do.call(rbind, collect)
res <- raster::extract(dummy_sample, result)
......@@ -65,43 +54,10 @@ write_Out_Samples <- function (inPath, step, className) {
res <- result[-which(is.na(res)), ]
}
print("problem zone 3")
### save the points as .shp with crs
# crs_dummy <- proj4string(dummy_sample)
# proj4string(res) <- crs_dummy
# print(str(res))
# print(proj4string(res))
#
# rgdal::writeOGR(
# res,
# layer = "result",
# dsn = paste(inPath, "RefHaSa_", className, "_", step, ".shp", sep = ""),
# driver = "ESRI Shapefile",
# check_exists = TRUE,
# overwrite_layer = TRUE
# )
#### this approach is for a shape file in a Geopackage (.dpkg) container
# print(proj4string(res))
#
# crs_dummy <- proj4string(dummy_sample)
# proj4string(res) <- crs_dummy
#
# print(proj4string(res))
#
# rgdal::writeOGR(
# res,
# layer = paste("RefHaSa_step_", step, "_", className, sep = ""),
# dsn = paste(inPath, "RefHaSa_step_", step, "_", className, ".gpkg", sep = ""),
# driver = "ESRI Shapefile",
# check_exists = TRUE,
# overwrite_layer = TRUE
# )
crs_dummy <- proj4string(dummy_sample)
crs_dummy <- sp::proj4string(dummy_sample)
crs(res) <- crs_dummy
res <- spTransform(res, CRS("+proj=longlat +datum=WGS84 +init=epsg:4326"))
res <- sp::spTransform(res, CRS("+proj=longlat +datum=WGS84 +init=epsg:4326"))
rgdal::writeOGR(
res,
layer = paste("RefHaSa_step_", step, "_", className, sep = ""),
......@@ -110,6 +66,4 @@ write_Out_Samples <- function (inPath, step, className) {
check_exists = TRUE,
overwrite_layer = TRUE
)
print("finished")
}
......@@ -14,11 +14,11 @@ write_Out_Samples(inPath, step, className)
\item{className}{name (character) of habitat type for which samples should be selected}
}
\value{
ESRI shapefile with name: RefHaSa_className_step.shp
GeoJSON file with name: RefHaSa_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
}
}
\description{
Writes out a set of samples (SpatialPointsDataFrame) into an ESRI shapefile 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 an GeoJSON file for a selected habitat type. Each point represents a valid sample location that identifies the selected habitat type.
}
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