@@ -51,7 +51,7 @@ shape_to_geojson <- function(input,
51
51
52
52
# # Check if the input is a directory ####
53
53
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 )
55
55
# # Overwrite output with input if not specified
56
56
if (missing(output )){
57
57
message(" Output folder is not specified, using input folder as output folder" )
@@ -63,9 +63,12 @@ shape_to_geojson <- function(input,
63
63
# # Extract input folder ####
64
64
input <- dirname(input )
65
65
66
+ filelist <- gsub(pattern = input , replacement = " " , filelist )
67
+
66
68
# # Output is not specified, but needed
67
69
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
69
72
}
70
73
}
71
74
@@ -111,7 +114,8 @@ shape_to_geojson <- function(input,
111
114
next ()
112
115
}
113
116
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()
115
119
116
120
# # Check if the shape has a crs ####
117
121
if (is.na(sf :: st_crs(shape ))){
@@ -125,6 +129,10 @@ shape_to_geojson <- function(input,
125
129
shape <- sf :: st_transform(shape , output_crs )
126
130
}
127
131
132
+ if (q_overwrite == TRUE & file.exists(here :: here(output , output_fn ))){
133
+ file.remove(here :: here(output , output_fn ))
134
+ }
135
+
128
136
# # Write the shape to geojson ####
129
137
sf :: st_write(shape , here :: here(output , output_fn ),
130
138
driver = " GeoJSON" ,
0 commit comments