-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Digits with geojson_list()
#141
Comments
Here is a simple example:
Let's print out the
Now we'll convert it.
Now when we look again, we have lost a digit (5 instead of 6):
|
thanks @josiekre will have a look |
one thing is that you're on an older dev version, we're currently on have you played with the options(digits = 8)
s <- dplyr::data_frame(
id = c("A", "B"),
lat = c(38.949019, 39.008222),
lon = c(-77.080369, -76.780363)
)
(g <- geojsonio::geojson_list(input = s, lat = "lat", lon = "lon"))
lapply(g$features, "[[", c("geometry", "coordinates"))
#> [[1]]
#> [1] -77.080369 38.949019
#>
#> [[2]]
#> [1] -76.780363 39.008222 let me know what you think |
I thought I played with that. In the file output (as opposed to interactive output), I don't think it made a difference. But I will rerun and report back in a couple days. Thx @sckott. |
A call to |
Sorry for the delay @josiekre - was on vacation. The number of digits written to the console depends on the R option |
any thoughts @josiekre ? |
I personally think it would be nicer to control the output digits within the function call. It would be better to create a controlled, repeatable function call. I think of It could be smart to default like this:
|
thanks @josiekre for the suggestion. i'll think about that. |
@josiekre I've experimented with this. there's no way I can see to allow the user to change digits in the outupt, AND not effect the global digits option. You can format numbers directly with e.g., format, sprintf, etc. but we can't feasibly do that with the complex nested lists, etc. we're dealing with. I think the best option is to document that if you want to change digits, set them with |
The |
@jeroen any thoughts on this ☝️ ? |
@sckott I might have a simple solution by updating geojson_rw to take precision as a variable since it is used in geojson_write which is called by geojson_rw. I already have the code updated and it works for my use case. I can submit a PR if you think it would be useful for others and not break anything anywhere else. In my testing, it hasn't affected anything else that I have noticed. |
thanks @ChrisJones687 ! a PR would be great. |
So the PR #152 added ability to manipulate digits for sp class objects, but we don't have a solution for data.frame's, vectors, lists, etc. I tried using sf internally with data.frames just to see if it would be feasible, but its much slower than what we have now. Oh, and I didn't even check that we can manipulate precision through this route, but I assume we can. Anyway ... geojson_list_data.frame <- function(input, lat = NULL, lon = NULL, group = NULL,
geometry = "point", type = "FeatureCollection", ...) {
tmp <- guess_latlon(names(input), lat, lon)
out <- list()
for (i in seq_len(NROW(input))) {
out[[i]] <- sf::st_point(as.numeric(c(input[i, tmp$lat], input[i, tmp$lon])))
}
tfile <- tempfile(fileext = ".geojson")
tmpsf <- sf::st_as_sf(input, coords = c("lat", "long"))
sf::st_write(tmpsf, tfile, quiet = TRUE)
xx <- as.geo_list(jsonlite::fromJSON(readLines(tfile), TRUE, FALSE, FALSE),
"data.frame")
xx$features <- lapply(xx$features, function(z) {
z$geometry$coordinates <- rev(as.numeric(z$geometry$coordinates))
z
})
xx$name <- NULL
return(xx)
} |
There does not seem to be control over the number of digits output when passing a data frame to
geojson_list()
. No matter how many significant digits there are in thelon
andlat
columns, the resulting list has at most five digits to the right of the decimal, e.g. -77.11739, 38.94512.I see from #96 that digits were thought about at some point, but I'm not seeing how this translates into
geojson_list()
. What am I missing?Thanks.
Session Info
The text was updated successfully, but these errors were encountered: