save_R_list_Features_2_FeatureCollection {geojsonR}R Documentation

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

Description

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

Usage

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


## 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)


[Package geojsonR version 1.1.1 Index]