save_R_list_Features_2_FeatureCollection: creates a FeatureCollection from R list objects ( see the...

Description Usage Arguments Details Value Examples

View source: R/utils.R

Description

creates a FeatureCollection from R list objects ( see the details section about the limitations of this function )

Usage

1
2
3
4
5
save_R_list_Features_2_FeatureCollection(
  input_list,
  path_to_file = "",
  verbose = FALSE
)

Arguments

input_list

a list object that includes 1 or more geojson R list Features

path_to_file

either an empty string ("") or a valid path to a file where the output FeatureCollection will be saved

verbose

a boolean. If TRUE then information will be printed out in the console

Details

The input_list parameter can be EITHER created from scratch OR GeoJson Features (in form of a FeatureCollection) can be loaded in R and modified so that this list can be processed by this function

Value

a FeatureCollection in form of a character string

a FeatureCollection saved in a file

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
## Not run: 

library(geojsonR)

#------------------------------------------------
# valid example that will save the data to a file
#------------------------------------------------

Feature1 = list(type ="Feature",
                id = 1L,
                properties = list(prop1 = 'id', prop2 = 1.0234),
                geometry = list(type = 'Polygon',
                                coordinates = matrix(runif(20), nrow = 10, ncol = 2)))

Feature2 = list(type ="Feature",
                id = 2L,
                properties = list(prop1 = 'non-id', prop2 = 6.0987),
                geometry = list(type = 'MultiPolygon',
                                coordinates = list(matrix(runif(20), nrow = 10, ncol = 2),
                                                  matrix(runif(20), nrow = 10, ncol = 2))))

list_features = list(Feature1, Feature2)

path_feat_col = tempfile(fileext = '.geojson')

res = save_R_list_Features_2_FeatureCollection(input_list = list_features,
                                               path_to_file = path_feat_col,
                                               verbose = TRUE)

#-------------------------------------
# validate that the file can be loaded
#-------------------------------------

res_load = FROM_GeoJson_Schema(url_file_string = path_feat_col)
str(res_load)


#----------------------------------------------------
# INVALID data types such as NA's will throw an ERROR
#----------------------------------------------------


Feature1 = list(type ="Feature",
                id = 1L,
                properties = list(prop1 = NA, prop2 = 1.0234),
                geometry = list(type = 'Polygon',
                                coordinates = matrix(runif(20), nrow = 10, ncol = 2)))

list_features = list(Feature1, Feature2)

path_feat_col = tempfile(fileext = '.geojson')

res = save_R_list_Features_2_FeatureCollection(input_list = list_features,
                                               path_to_file = path_feat_col,
                                               verbose = TRUE)

## End(Not run)

geojsonR documentation built on May 4, 2021, 9:06 a.m.