if (FALSE) {
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)
}
Run the code above in your browser using DataLab