I am planning to create an interactive map with markers of hospital OHS incidents using Leaflet, Shiny and Shinydashboard along the lines of the following awesome template for interactive map and histogram
My problem is that I do not have a coordinate reference system as this is not a geographic object (no lat and long). Also it is in raster form.
How can I make the below floorplan into something with a CRS (coordinate reference system) that can be treated like a map.
That is, I want to be able to pan, zoom, add Markers etc.
There appears to be a way to do this using Java however I was hoping to do this in R as I am unfamiliar with Java. See Coordinates to space map
Here's a solution using mapview:
library(raster)
library(png)
library(mapview)
web_img <- "http://i.stack.imgur.com/8aSe9.png"
png <- readPNG(readBin(web_img, "raw", 1e6))
rst_blue <- raster(png[, , 1])
rst_green <- raster(png[, , 2])
rst_red <- raster(png[, , 3])
img <- brick(rst_red, rst_green, rst_blue)
m <- viewRGB(img)
m@map %>% addMarkers(lng = 0.5, lat = 0.5)
Note, that coordinates have their origin in the lower left corner of the image (0, 0) and, in this case scale to (0, 1) in the lower right corner and (0.859, 1) in the upper right corner to keep the aspect ration correct. Adding markers within this local coordinate reference system should be easy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With