Closed layik closed 6 years ago
HI @layik
Yes, this is by design, but I'm open for a discussion about the validity of it.
from RFC 7946
A Feature object has a member with the name "properties".
I implemented sf_geojson()
so that if there weren't any properties in an sf
object, it won't get interpreted as a Feature
.
What's your opinion on how this should behave? Should an sf
object become a FeatureCollection
regardless of whether it contains properties?
Hey @SymbolixAU, thank you for the confirmation and reference.
I actually don't know. Let me also say how I got to become aware of this, 'plumber' is my underlying HTTP package which in turn relies on "httr", and to serve application/json
it does not like vectors > 1.
If a vector > 1 is provided, it only returns the first element. Does that mean, they too, expect a one vector "FeatureCollection" by default? I doubt they would be willing to contribute to this discussion.
This is the warning coming from httr
In (function (x) : argument should be a character vector of length 1
all but the first element will be ignored
and here is a quick googling.
I will try to educate myself a little more on GeoJSON before I can be of help!
Maybe the solution is to have an argument inside sf_geojson()
like simplify = TRUE/FALSE
(much like drop = FALSE
for [.data.frame
). So setting simplify = FALSE
will mean
sf
always becomes FeatureCollectionsfc
always becomes vectors of featuresand simplify = TRUE
will reduce sf
objects to vectors of features if there aren't any properties.
That would make my underlying code happy!
I've added it to v1.2 milestone due by the end of October.
Thank you very much @SymbolixAU. Awesome response time.
Close it when you feel like it.
@layik in this commit I've implemented a simplify
argument.
to test you'll need to install jsonify
(I've submitted it to CRAN, but it's not accepted yet).
# devtools::install_github("SymbolixAU/jsonify")
## jsonify now on CRAN
devtools::install_github("SymbolixAU/geojsonsf")
Hi @SymbolixAU you know I am using the package in
geoplumber
and last time I opened an issue I just wasted your time. Hope I am not doing the same now.Please have a look at this and let me know if that is what you expect the outcome to be. Thank you
Created on 2018-10-13 by the reprex package (v0.2.1)
TODO
simplify
argument