-
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
Methods for sf objects #95
Conversation
get_epsg(x[[geom_col]]) | ||
} | ||
|
||
get_epsg.sfc <- function(x) attr(x, "epsg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has now changed; sfc
objects have a crs
attribute which is a list with a epsg
integer and a proj4string
proj4string. I guess that only in case epsg
is 4326 you can directly convert to geojson, otherwise you need to st_transform
into epsg 4326.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good to know, thanks @edzer. And thanks very much for taking the time to look.
Yes, I've been struggling with what to do with non-EPSG:4326 CRS's. As written, the sf
to geojson
methods don't depend on the sf
package, adding st_transform
would require it. @sckott what do you think, as I know you were hoping to keep the dependencies down? We could add it in Suggests
(which I think we would need to anyways for tests), then conditionally transform to 4326 (with a message) if sf
is available, otherwise throw an error telling the user they need to transform it? Or bite the bullet and add it in Imports
, as I think (hope!) sf
will replace sp
as the standard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean towards Suggests
, but if needs to go in Imports
, so be it
Ok I'll go with suggests. I wonder if in the same vein we can eventually move sp and rgdal to Suggests if can parse sp to json without them |
that's my hope! at least |
Nothing wrong with Suggests: as long as you use constructs like this. Also pls use |
Yep, that is how I was planning on doing it. I think I need to access the epsg <- attr(x, "crs")[["epsg"]]
if (epsg != 4326)) {
if (!requireNamespace("sf", quietly = TRUE)) {
stop("Your input is not in a CRS that geojson supports and you don't have the 'sf' package installed. Please install and try again")
} else {
x <- sf::st_transform(x, 4326)
}
}
## turn x into json Unless I'm missing something else...? |
No that should work - I didn't anticipate you want to write the geojson without |
lol, thanks! Unless I'm really deceiving myself, because |
Lucky you - the geojson standard excludes Z and M, and constraints to the first 7 types. |
A couple of notes on the draft new GEOSJON standard:
|
Current approach: detect non-wgs84 (epsg:4326) and transform. Don't include crs member
@sckott any thoughts on number 1 above? |
@ateucher Seems like since WGS84 is the standard for geojson we could just convert it to that, but letting the user toggle that will make more people happy perhaps? |
Thanks @sckott that works for me. Selfishly, I want to be able to bypass transformation to use in |
@ateucher wait, which one works? |
@sckott I think this is ready for merge (or further review/testing by other eyes). It's passing on my fork, failing here with the I omitted dealing with non-epsg:4326 CRS until we decide to do it package-wide - didn't seem right to implement it only in these methods... |
Just playing with Travis... |
i think its failing cause |
that makes sense to implement converting pkg wide later |
Thanks for the tests! Can you add some examples though for the different sf classes for both files |
Oh right, examples. Yep, will do. Re Travis failing, I figured that it was GITHIB_PAT. |
@sckott I think this is good to go now. I added examples (hopefully they're enough), and methods for |
Sweet, will look in morning |
LGTM nice work sir @ateucher |
Woot! Thanks :) |
This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
Hey @sckott - I'm not sure you'll want to merge this yet, but thought I'd let you know how it was going. I think it's mostly working well, but obviously have to flesh out the tests. If you haven't seen it, the sf vignette gives a good overview of the sf and related classes.