-
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
Replace rgdal for serializing to/from geojson #41
Comments
working on the |
With a good part of the performance bottleneck of geojson_json removed in #85 and the discussion about disk round-trip in #77 the question is indeed if further speed improvements can be made by not using For well-defined objects serialization is not too hard, so I drafted a function to do it for The function itself you can find at https://gist.github.com/javrucebo/fbbfe4b504d49893ad03d8fe0bd84f73 And I have written some code to benchmark/verify: https://gist.github.com/javrucebo/da86e7bf0fb4f5367e2b405c3bed1e54. The resuling Benchmark from above code for some SpatialPolygons: Not sure if that is a road you would want to go down ... for me it does the job and improves further the elapsed time, in particular when I need bench_sptogeojson(raster::getData('GADM', country='VAT', level=0))
# Unit: seconds
# expr min lq mean median uq max neval
# gejson_json 0.03580 0.03580 0.035799645 0.03580 0.03580 0.03580 1
# SpatialPolygons_to_geojson 0.00433 0.00433 0.004333479 0.00433 0.00433 0.00433 1
bench_sptogeojson(raster::getData('GADM', country='UKR', level=1))
# Unit: seconds
# expr min lq mean median uq max neval
# gejson_json 1.020 1.020 1.0184167 1.020 1.020 1.020 1
# SpatialPolygons_to_geojson 0.274 0.274 0.2737755 0.274 0.274 0.274 1
bench_sptogeojson(raster::getData('GADM', country='SWE', level=2))
# Unit: seconds
# expr min lq mean median uq max neval
# gejson_json 3.77 3.77 3.765165 3.77 3.77 3.77 1
# SpatialPolygons_to_geojson 1.25 1.25 1.251481 1.25 1.25 1.25 1
bench_sptogeojson(raster::getData('GADM', country='CAN', level=3))
# Unit: seconds
# expr min lq mean median uq max neval
# gejson_json 58.1 58.1 58.07351 58.1 58.1 58.1 1
# SpatialPolygons_to_geojson 15.6 15.6 15.64825 15.6 15.6 15.6 1 |
Thanks very much for this @javrucebo Have you tested the function with lots of different spatialpolygon inputs? Curious how well it works with diverse inputs of SpatialPolygon type |
This is awesome, but I have the same concern. |
@jeroenooms and I talked about possibility of simply converting the S4 spatial objects like |
Regarding first question of @sckott: Yes I did try it with many different inputs.
For @ateucher' comment: I certainly agree, it's always safer to rely on heavily tested packages then to take some risk. But
And @sckott's second comment: Indeed, as I said: the format of SpatialPolygonsDataFrame is pretty simple; I do not know how In a nutshell: I think |
I think a package to convert between |
Another thing to think about is sfr, where they are implementing spatial classes using simple features specification, and presumably thinking about conversions between old |
@ateucher AFAICT though (correct me if I'm wrong) I realize there's a tradeoff here between well tested libraries like GDAL and painless setup/installation for users. For me personally, I'd like to have a solution that is robust and covers nearly all cases, but is also portable across all platforms (and never gives travis hell, as GDAL does) Thanks @javrucebo for your detailed notes. Seems like your first function does work pretty generally. Seems like there are two routes we can go down:
Either route we take, probably makes sense to make a separate package for this task of converting sp classes to geojson (which I think would mean only depending on any thoughts on how to proceed? |
Yup, it was funded - see second last item here. I do think it will depend on GDAL. I just know that rgdal goes through some machinations for conversion, because the current It probably does make sense to make a lightweight package for the particular task of converting between |
I think simplicity is the main reason. And the work done in jsonlite is C based, so its fast. BUT, if we can't do with just jsonlite and pure R manipulations, then makes sense to drop down to C |
Makes sense to me |
GDAL TravisCI pain is resolved by @edzer in the I got inspired by the above myself for a bookdown experiment where I need to read Shapefiles/Topojson/...and it works...of course the whole build time has gone from ~4min to ~20min. Another option to reduce Travis pain/build time is to define a docker image and use that in Travis. HTH |
@espinielli You should cache the |
|
The pain is IMO not with (r)gdal, but with travis: it doesn't let you add the ubuntugis-unstable repo, which has gdal 2.1 compiled. |
@edzer that would be nice if travis would allow that |
maybe Travis's Trusty can be of some help... @yihui thanks...I think I got it from other bookdown examples/repos, I'll check and feedback...still learning (BTW super great work) |
Here is a trusty travis file that uses gdal-dev binaries; it is at version 1.10, which is enough for rgdal and rgeos to compile. For sfr 1.10 is currently not enough, but if travis waiting time is your only problem, this might solve it. As explained here, the sp classes do not map 1:1 to the 7 simple features of geojson: sp does not distinguish between POLYGON and MULTIPOLYGON (and, as noted in this thread, doesn't register holes with the rings they fall in, rgeos needed for that), and also not between LINESTRING and MULTILINESTRING. |
@sckott so we can push the more important fixes out the door, I'm going to suggest we move this to the v0.7 milestone |
rgdal replaced with sf, work in 1ea0bd3 |
This issue 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. |
Look and see if can just depend on a small javascript library for this - doing in pure R doable, but slow
The text was updated successfully, but these errors were encountered: