3

I'm trying to create an interactive plot with leaflet containing polygons. The coordinates of these polygons are not longitude/latitudes but rather Cartesian x and y coordinates that represent a building floor plan.

For coordinates that are single digit numbers the results look good:

library(leaflet)
library(sp)
Sr1 = Polygon(cbind(c(9, 8, 8, 9, 9), 
                    c(3, 3, 4, 4, 3)))

Srs1 = Polygons(list(Sr1), "s1")
SpP = SpatialPolygons(list(Srs1), 1L)
leaflet() %>% addPolygons(data = SpP)

Good plot

But when I increase all y coordinates by 100 things go wrong:

library(leaflet)
library(sp)
Sr1 = Polygon(cbind(c(9, 8, 8, 9, 9), 
                    c(103, 103, 104, 104, 103)))

Srs1 = Polygons(list(Sr1), "s1")
SpP = SpatialPolygons(list(Srs1), 1L)
leaflet() %>% addPolygons(data = SpP)

Bad plot

I'm guessing this has to do with the default projection settings of the map. I tried initializing the map with these settings:

leaflet(options(crsClass = "L.CRS.Simple"))

After reading this example but with no success.

Jeroen Boeye
  • 580
  • 4
  • 18
  • 1
    Does this work for you: `leaflet(options = leafletOptions(crs = leafletCRS(crsClass = "L.CRS.Simple"))) %>% addPolygons(data = SpP)`? – Henrik Aug 07 '17 at 14:21
  • Yes!! That does exactly what I want it to. Thanks a lot Hendrik! – Jeroen Boeye Aug 07 '17 at 14:32
  • 1
    Fwiw mapview will do this automatically for you. `mapview(SpP, native.crs = TRUE)` Note though that `L.CRS.Simple` does currently not work with raster images. – TimSalabim Aug 07 '17 at 19:31

0 Answers0