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