5
votes

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.Ward 2 East

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

2
You would need to manually georeference your image using standard GIS software such as QGIS. See e.g. here qgistutorials.com/en/docs/georeferencing_basics.htmlTimSalabim
Is there a way to do this in R?monkeyshines
Not that I am aware of. It can't be done computationally, but needs to be done manually, therefore it is unlikely that this can be done in R. Especially as you want to have interactivity for this task (zooming in particular).TimSalabim

2 Answers

1
votes

You can do:

library(raster)
b <- brick("8aSe9.png")

That gives you a four layer georeferenced RasterBrick object (RGB+alpha) you can look at with

plotRGB(b)

Of course the georeference is not relation to any other spatial object, but it seems that this may not matter to you.

If you want a single layer object (a RasterLayer) you can take any of the three layers (they are all the same)

r <- b[[1]]

or directly from the file:

r <- raster("8aSe9.png")

and then

image(r, col=gray(seq(0,1,.1)))
# or  plot(r, col=gray(seq(0,1,.1)), legend=F)
1
votes

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.