Commit 1ce61d1a authored by Romulo Pereira Goncalves's avatar Romulo Pereira Goncalves
Browse files

Merge branch 'master' into issue#13

parents 54c41204 c2f076b1
......@@ -107,10 +107,14 @@ saveSamplePoints <-
}
result <- do.call(rbind, collect)
res <- raster::extract(dummy_raster, result)
if (length(which(is.na(res))) > 0) {
result <- result[-which(is.na(res)), ]
if (!is.null(result)) {
res <- raster::extract(dummy_raster, result)
if (length(which(is.na(res))) > 0) {
result <- result[-which(is.na(res)), ]
}
} else {
result <-
sp::SpatialPolygonsDataFrame(Sr = sp::SpatialPolygons(list()), data = data.frame())
}
raster::crs(result) <- raster::crs(dummy_raster)
......@@ -120,22 +124,22 @@ saveSamplePoints <-
if (nrow(result) > 0) {
result <- sp::spTransform(result, sp::CRS("+init=epsg:4326"))
}
rgdal::writeOGR(
obj = result,
sf::st_write(
obj = sf::st_as_sf(x = result, crs = 4326),
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
append = FALSE
)
} else {
rgdal::writeOGR(
obj = result,
sf::st_write(
obj = sf::st_as_sf(x = result, crs = 4326),
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
append = FALSE
)
}
}
......@@ -193,10 +197,14 @@ writeOutSamples <- function(in_path, step, class_name, output_format = c("shp",
}
result <- do.call(rbind, collect)
res <- raster::extract(dummy_sample, result)
if (length(which(is.na(res))) > 0) {
result <- result[-which(is.na(res)), ]
if (!is.null(result)) {
res <- raster::extract(dummy_sample, result)
if (length(which(is.na(res))) > 0) {
result <- result[-which(is.na(res)), ]
}
} else {
result <-
sp::SpatialPolygonsDataFrame(Sr = sp::SpatialPolygons(list()), data = data.frame())
}
raster::crs(result) <- raster::crs(dummy_sample)
output_format <- match.arg(output_format)
......@@ -205,22 +213,22 @@ writeOutSamples <- function(in_path, step, class_name, output_format = c("shp",
if (nrow(result) > 0) {
result <- sp::spTransform(result, sp::CRS("+init=epsg:4326"))
}
rgdal::writeOGR(
obj = result,
layer = paste("sel_SamplePoints_step_", step, "_", class_name, sep = ""),
dsn = paste(in_path, "sel_SamplePoints_step_", step, "_", class_name, ".geojson", sep = ""),
sf::st_write(
obj = sf::st_as_sf(x = result, crs = 4326),
layer = paste("RefHaSa_", class_name, "_", step, sep = ""),
dsn = paste(in_path, "RefHaSa_", class_name, "_", step, ".geojson", sep = ""),
driver = "GeoJSON",
check_exists = TRUE,
overwrite_layer = TRUE
append = FALSE
)
} else {
rgdal::writeOGR(
obj = result,
layer = paste("sel_SamplePoints_step_", step, "_", class_name, sep = ""),
dsn = paste(in_path, "sel_SamplePoints_step_", step, "_", class_name, ".shp", sep = ""),
sf::st_write(
obj = sf::st_as_sf(x = result, crs = 4326),
layer = paste("RefHaSa_", class_name, "_", step, sep = ""),
dsn = paste(in_path, "RefHaSa_", class_name, "_", step, ".shp", sep = ""),
driver = "ESRI Shapefile",
check_exists = TRUE,
overwrite_layer = TRUE
append = FALSE
)
}
}
\ No newline at end of file
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