lineup with leaflet off for projection that should work...
jebyrnes opened this issue · 7 comments
I'm working with a raster that is
CRS arguments:
+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
I have a shape file of the area it should overlay in 4326, and plotting them together is fine. The overlay works. However, a simple call to tiler - just the raster file, a write-out directory and zoom of "0-7" as the arguments, yields a tileset that, when I serve it up locally, has this overlay.
Note, this is a tileset that should overlay the Falkland islands in the southern hemisphere, and is significantly smaller than what is shown here.
Thoughts in where things are going awry?
For reference, the leaflet call is
library(leaflet)
#in the relevant directory
#python -m SimpleHTTPServer 8000
tilesUrl <- "http://localhost:8000/{z}/{x}/{y}.png"
leaflet() %>%
addTiles() %>%
addTiles(urlTemplate = tilesUrl, options = tileOptions(opacity = 0.8)) %>%
addLegend(colors = col_default, position = "bottomright",
labels = as.character(4:13), title = "Users Agreeing")
Sidenote: might be worthwhile including the how-to-serve-locally in your vignette. Also, thanks for a truly awesome and very useful package! It's a game changer for the project I'm working on!
Thanks. I'm glad it is useful at all! :) It has a very narrow purpose and even that, as you have seen, it doesn't do perfectly. Regarding the above example, is there any way you can make data available to support a reproducible example with the code above?
I'm not sure what is going on there. If you take a look at any of the GitHub issues relating to the projections
branch, it's a real mess. A few people have contributed there but we never got things sorted completely.
This doesn't involve that branch or alternative projections though so I don't what may be going wrong. But maybe it is related to some of those other issues though, in the sense that there have been longstanding difficulties with combining with leaflet, specifically for spatial maps, not the non-spatial ones. It's been a while since I've worked on this (yours is the first explicit interest I've seen in a while- thank you!) but I previously had difficulties where I could make spatial tiles that looked perfect, in whatever projection, but they clashed with leaflet because their underlying coordinates did not map correctly. I was at a loss to get it all figured out myself.
It's definitely a projection issue. I just ran the example, but, did
r2 <- projectRaster(r, crs ="+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
and then wrote it out and ran the script forward. And got...
Odd - I wouldn't think those final two bits are the problem, but so it goes.
Let me see if I can retroject back and get it to work and/or play with the projections branch.
FYI, this is just so damned convenient that I might be wrapping it into a package I'm working on for some citizen science work with Zooniverse (I'm a PI on http://floatingforests.org) and there's nothing out there like this! Thank you again!
OK - problem solved. The leaflet map in the vignette was not generated by the call as written. If you look at the github hosted tileset at https://github.com/leonawicz/tiles/blob/master/us48lr/tiles/tilemapresource.xml you'll see the raster was in EPSG:3785 not 4326 before being tiled.
If you reproject the raster with a CRS of "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" and then tile, it works perfectly.
So - perhaps the vignette needs to be changed?
Also might be good to include python -m SimpleHTTPServer 8000
in the directory of the tiles and then set tilesUrl <- "http://localhost:8000/{z}/{x}/{y}.png"
and run leaflet, you can check your tiles against leaflet locally!
I'll take a gander at the projection branch as well.
That sounds awesome!
Yeah, this is weird; I need to find some time to dig back in. I'm guessing/hopeful that anything that could get sorted in the projections branch would solve any problems here. I have wanted to get that branch merged into master for a while. It represents how I want tiler
to actually operate: simple CRS plus any arbitrary geospatial projection.
If you have another package import tiler
that would be a first for me. But keep in mind it has these frustrating system reqs. Which is enough to make people not want to use a package.
Thanks for looking into these issues. There are a lot of people better at all things geospatial than me and I've been somewhat limited in what I need to know to solve some of these pesky edge cases.
There are a lot of people better at all things geospatial than me and I've been somewhat limited in what I need to know to solve some of these pesky edge cases.
Hey, stop describing me to myself! (I am an ecologist by training)
OK, closing, as I know what the problem is and how to deal. Good luck with the projections branch - and if you want to throw anything to look at my way, feel free.
My last comment was lagging behind your later reply. I'll look into the vignette issue.
Regarding checking locally with leaflet, are you thinking an optional argument to tile
or another function that will do that? Is this local server spinup something that might be impacted by CRAN policies for R package behavior? It's not something I've put in a package before. We can start a new issue for that topic.
I guess I should also ask, is it not enough/different to just check by opening the preview.html
document?