Skip to content

Commit

Permalink
Rename proj attribute in geojson objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ateucher committed Mar 22, 2020
1 parent 9be7c80 commit 390880b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion R/filter_fields.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ms_filter_fields_sp <- function(input, fields, sys) {
#
# ret <- apply_mapshaper_commands(data = geojson, command = cmd, force_FC = FALSE)
#
# GeoJSON_to_sp(ret, proj = attr(geojson, "proj4"))
# GeoJSON_to_sp(ret, proj = attr(geojson, "proj"))

if (!(all(is.element(fields, names(input@data))))) {
stop("Not all named fields exist in input data", call. = FALSE)
Expand Down
10 changes: 5 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ms_sp <- function(input, call, sys = FALSE) {
were reduced to null.", call. = FALSE)
}

ret <- GeoJSON_to_sp(ret, proj = attr(geojson, "proj4"))
ret <- GeoJSON_to_sp(ret, proj = attr(geojson, "proj"))

# remove data slot if input didn't have one (default out_class is the class of the input)
if (!has_data) {
Expand All @@ -168,7 +168,7 @@ sp_to_GeoJSON <- function(sp, file = FALSE){
js <- readr::read_file(js_tmp, locale = readr::locale())
on.exit(unlink(js_tmp))
}
structure(js, proj4 = proj)
structure(js, proj = proj)
}

## Utilties for sf
Expand All @@ -192,7 +192,7 @@ ms_sf <- function(input, call, sys = FALSE) {
were reduced to null.", call. = FALSE)
}

ret <- GeoJSON_to_sf(ret, proj = attr(geojson, "proj4"))
ret <- GeoJSON_to_sf(ret, proj = attr(geojson, "proj"))

## Only return sfc if that's all that was input
if (!has_data) {
Expand All @@ -219,7 +219,7 @@ GeoJSON_to_sf <- function(geojson, proj = NULL) {
curly_brace_na(sf)
}

sf_to_GeoJSON <- function(sf, file = FALSE){
sf_to_GeoJSON <- function(sf, file = FALSE) {
proj <- sf::st_crs(sf)
if (file) {
js <- sf_sp_to_tempfile(sf)
Expand All @@ -228,7 +228,7 @@ sf_to_GeoJSON <- function(sf, file = FALSE){
## the geo_json classing that goes on there
js <- geo_list_to_json(sf)
}
structure(js, proj4 = proj)
structure(js, proj = proj)
}

geo_list_to_json <- function(x) {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ test_that("NA values dealt with in sf_to_GeoJSON", {
geojson <- sf_to_GeoJSON(sf_obj)
expect_equal(geojson,
structure("{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"a\":1},\"geometry\":{\"type\":\"Point\",\"coordinates\":[0,0]}},{\"type\":\"Feature\",\"properties\":{\"a\":null},\"geometry\":{\"type\":\"Point\",\"coordinates\":[1,1]}}]}",
class = "json", proj4 = structure(list(
class = "json", proj = structure(list(
epsg = NA_integer_, proj4string = NA_character_
), class = "crs")
)
)
back_to_sf <- GeoJSON_to_sf(geojson, proj = attr(geojson, "proj4"))
back_to_sf <- GeoJSON_to_sf(geojson, proj = attr(geojson, "proj"))
expect_equivalent(sf_obj, back_to_sf)
})

Expand Down

0 comments on commit 390880b

Please sign in to comment.