Projecting my shapefile data on leaflet map using R

前端 未结 2 539
鱼传尺愫
鱼传尺愫 2021-02-02 04:39

I (on Win7) was trying to get my shapefile data (Here are the data files.) to be displayed using leaflet package. But without any success. I only get the background

2条回答
  •  梦谈多话
    2021-02-02 04:50

    Hi you have to change the projection :

    library("rgdal")
    shapeData <- readOGR(".",'myGIS')
    shapeData <- spTransform(shapeData, CRS("+proj=longlat +ellps=GRS80"))
    library("leaflet")
    leaflet()  %>% addTiles() %>% 
      setView(lng = -106.363590, lat=31.968483,zoom=11) %>% 
      addPolygons(data=shapeData,weight=5,col = 'red') %>% 
      addMarkers(lng = -106.363590,lat=31.968483,popup="Hi there") 
    

    But I can't tell you why this works, i only know a little about geo and proj.

提交回复
热议问题