Closed bhogan-mitre closed 4 years ago
My work around was to convert point data lat/long to xy using the elevation maps extent/bbox. It seems to put the labels close enough to right place.
p1 = (x-extent(elevation)@xmin) / (extent(elevation)@xmax-extent(elevation)@xmin) * ncol(elevation)
p2 = (y-extent(elevation)@ymin) / (extent(elevation)@ymax-extent(elevation)@ymin) * nrow(elevation)
That work around is what the package 'geoviz' does in latlong_to_rayshader_coords(). You can also make GPS overlays with it if you want to try @bhogan-mitre
@ojabri's approach (https://github.com/tylermorganwall/rayshader/issues/30#issuecomment-463794935) does not quite work for me, I need to add a 1-... in the second line. This is my adopted function:
coords_to_xy <- function(x, y, elevation){
require(raster)
ex <- extent(elevation)
x = (x-ex@xmin)/(ex@xmax-ex@xmin)*ncol(elevation)
y = (1-(y-ex@ymin)/(ex@ymax-ex@ymin))*nrow(elevation)
out <- c(x,y)
names(out) <- c("x","y")
return(out)
}
Added in 7052b91dd73fe9dc745f6139bcc589c65050c4ec
Could you explain your workflow for determining the matrix indices used in the
render_label
examples?It would be more natural for some applications to specify Santa Cruz for example by
latitude=37,longitude=-122
rather thanx=220,y=330
.Do you see a role in this package for helper functions to assist with that translation?
This was mentioned by @YsoSirius in https://github.com/tylermorganwall/rayshader/issues/25 as well (who gave an example using
raster
'scolFromX
andcolFromY
), but I think this is deserving of its own issue.The use case would be for placing labels by their lat/long coordinates, but also for other types of overlays such as a GPS track. Presumably some input data types such as GeoTIFF would have the necessary information to facilitate this.