Create Map of Points

# load packages
suppressWarnings(suppressPackageStartupMessages({
  library(leaflet)
  library(rgdal)
}))

# set paths
gdb = 'H:/Fall15/GIS296/lab3new/lab3/golf.gdb'

# read points from geodatabase
pts = readOGR(gdb, 'pts_tree', verbose=F)

# project points to geographic projection
pts_gcs = spTransform(pts, leaflet:::epsg4326)

# create map of points
leaflet() %>%
  addTiles() %>%
  addMarkers(data = pts_gcs) 

create map with popups

# create map with popups
leaflet() %>%
  addTiles() %>%
  addMarkers(data = pts_gcs, popup=~sprintf('id: %d', id)) 

create map with Stamen.Terrain basemap

# create map with Stamen.Terrain basemap
leaflet() %>%  
  addProviderTiles('Stamen.Terrain') %>%
  addMarkers(data = pts_gcs, popup=~sprintf('id: %d', id))

read points, lines and polygons from geodatabase

# read points, lines and polygons from geodatabase
pts_gcs  = readOGR(gdb, 'pts_tree', verbose=F)    %>% spTransform(leaflet:::epsg4326)
lns_gcs  = readOGR(gdb, 'lns_cart_proj', verbose=F)    %>% spTransform(leaflet:::epsg4326)
plys_gcs = readOGR(gdb, 'plys_bunker', verbose=F) %>% spTransform(leaflet:::epsg4326)

# map with lines and polygons
leaflet() %>%  
  addProviderTiles('Stamen.Terrain') %>%
  addPolygons(data=plys_gcs, stroke = F, color = "orange") %>%  
  addPolylines(data=lns_gcs) %>%
  addMarkers(data=pts_gcs, popup=~sprintf('id: %d', id))

Input Habitat Raster

library(raster)
# set path to your final chosen classified image
tif = 'H:/Fall15/GIS296/lab3new/lab3/images_rectify/vid_090_5.tif'
  
# read raster, presumably in Web Mercator
r = raster(tif, crs = leaflet:::epsg3857)

# setup color palette
pal = colorFactor('Set3', values(r), na.color='transparent')

# map with raster
leaflet() %>%  
  addProviderTiles('Stamen.Toner') %>%
  addRasterImage(r, colors=pal, project=F, opacity=0.8) %>%
  addLegend(pal=pal, values=values(r), title='Habitats')