Skip to content

Commit 5ddb2ec

Browse files
fix some issues
#101
1 parent 8998755 commit 5ddb2ec

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

R/shape_to_geojson.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ shape_to_geojson <- function(input,
5151

5252
## Check if the input is a directory ####
5353
if(dir.exists(input)){
54-
filelist <- dir(path = input, pattern = ".shp", recursive = TRUE)
54+
filelist <- dir(path = input, pattern = ".shp", recursive = TRUE, full.names = FALSE)
5555
## Overwrite output with input if not specified
5656
if(missing(output)){
5757
message("Output folder is not specified, using input folder as output folder")
@@ -63,9 +63,12 @@ shape_to_geojson <- function(input,
6363
## Extract input folder ####
6464
input <- dirname(input)
6565

66+
filelist <- gsub(pattern = input, replacement = "", filelist)
67+
6668
## Output is not specified, but needed
6769
if(missing(output)){
68-
stop("The output folder is not specified, but needed >> specify output folder")
70+
message("Output folder is not specified, using input folder as output folder")
71+
output <- input
6972
}
7073
}
7174

@@ -111,7 +114,8 @@ shape_to_geojson <- function(input,
111114
next()
112115
}
113116

114-
shape <- sf::st_read(here::here(input, paste0(f, ".shp")))
117+
shape <- sf::st_read(here::here(input, paste0(f, ".shp"))) %>%
118+
sf::st_make_valid()
115119

116120
## Check if the shape has a crs ####
117121
if(is.na(sf::st_crs(shape))){
@@ -125,6 +129,10 @@ shape_to_geojson <- function(input,
125129
shape <- sf::st_transform(shape, output_crs)
126130
}
127131

132+
if(q_overwrite == TRUE & file.exists(here::here(output, output_fn))){
133+
file.remove(here::here(output, output_fn))
134+
}
135+
128136
## Write the shape to geojson ####
129137
sf::st_write(shape, here::here(output, output_fn),
130138
driver = "GeoJSON",

0 commit comments

Comments
 (0)