Create Map of Points
# load packages
suppressWarnings(suppressPackageStartupMessages({
library(leaflet)
library(rgdal)
}))
# set paths
gdb = 'H:/esm296-4f/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
leaflet() %>%
addTiles() %>%
addMarkers(data = pts_gcs, popup=~sprintf('id: %d', id))
# create map with Stamen.Watercolor basemap
leaflet() %>%
addProviderTiles('Stamen.Watercolor') %>%
addMarkers(data = pts_gcs, popup=~sprintf('id: %d', id))
# create map with Stamen.Toner basemap
leaflet() %>%
addProviderTiles('Stamen.Toner') %>%
addMarkers(data = pts_gcs, popup=~sprintf('id: %d', id))
# create map with Stamen.Toner basemap
leaflet() %>%
addProviderTiles('OpenTopoMap') %>%
addMarkers(data = pts_gcs, popup=~sprintf('id: %d', id))
# read points, lines and polygons from geodatabase
pts_gcs = readOGR(gdb, 'pts_tree', verbose=F) %>% spTransform(leaflet:::epsg4326)
lns_gcs = readOGR(gdb, 'lns_cart', verbose=F) %>% spTransform(leaflet:::epsg4326)
plys_gcs = readOGR(gdb, 'plys_bunker', verbose=F) %>% spTransform(leaflet:::epsg4326)
# map with lines and polygons
leaflet() %>%
addProviderTiles('Stamen.Toner') %>%
addPolygons(data=plys_gcs, stroke = FALSE, color = 'yellow') %>%
addPolylines(data=lns_gcs) %>%
addMarkers(data=pts_gcs, popup=~sprintf('id: %d', id))
library(raster)
# set path to your final chosen classified image
tif = 'H:/esm296-4f/lab3/images_rect/vid_sec148_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=.7) %>%
addLegend(pal=pal, values=values(r), title='Habitats')
library(rgdal)
gdb = 'H:/esm296-4f/lab3/golf.gdb'
dir = 'H:/esm296-4f/lab5/adv-gis/data'
# iterate through features in geodatabase
for (fc in ogrListLayers(gdb)){
# print paths
geo = sprintf('%s/%s.geojson', dir, fc)
tmp = tempfile()
cat(sprintf('gdb/fc: %s/%s\n -> tmp: %s\n -> geo: %s\n', gdb, fc, tmp, geo))
# skip stuff we don't want
if (fc %in% c('table')) next()
# read in feature class
sp = readOGR(gdb, fc)
# output to geojson
writeOGR(sp, dsn=tmp, layer='dummy', driver='GeoJSON')
# move file
file.rename(tmp, geo)
}