o
o
o
o
o
o
o
o
install.packages("sf")
install.packages("raster")
install.packages("spData")
install.packages("spDataLarge", repos =
"https://nowosad.github.io/drat/", type = "source")
library(sf) #Classes e funções para dados vetoriais
library(raster) #Classes e funções para dados raster
library(spData) #Acessar dados geográficos
library(spDataLarge) #Acessar dados geográficos grandes
names(world)
plot(world)
summary(world["pop"])
world_sub = world[1:3, 1:5]
world_sub
library(sp)
world_sp = as(world, Class = "Spatial")
world_sp
world_sf = st_as_sf(world_sp)
world_sf
help(“raster-package”)
vignette("functions", package = "raster")
raster_filepath = system.file("raster/srtm.tif", package =
"spDataLarge")
Zion = raster(raster_filepath)
Zion
plot(Zion)
dim(Zion)
ncell(Zion)
res(Zion)
extent(Zion)
crs(Zion)
inMemory(Zion)
plot(world[1:3])
plot(world[3:6])
plot(world[1:6])
plot(world["lifeExp"])
world_america = world[world$continent == "South America", ]
plot(world_america)
brazil = world[world$name_long == "Brazil", ]
plot(st_geometry(brazil), expandBB = c(0, 0.2, 0.1, 1), col =
"gray", lwd = 3)
plot(world_america[0], add = TRUE)
plot(world["continent"], reset = FALSE)
cex = sqrt(world$pop) / 10000
world_cents = st_centroid(world, of_largest = TRUE)
plot(st_geometry(world_cents), add = TRUE, cex = cex)
st_proj_info(type = "datum")
st_proj_info(type = "proj")
crs_data = rgdal::make_EPSG()
View(crs_data)
st_crs(world)
world = st_set_crs(world, 4326) # set CRS
projection(Zion)
brazil = world[world$name_long == "Brazil", ]
st_area(brazil)
st_area(brazil)/1000000
units::set_units(st_area(brazil), km^2)
library(sf)
library(raster)
library(dplyr)
library(spData)
download.file(url =
"http://www.sergeo.deg.ufla.br/geo/downloads/brasil.zip",
destfile = "brasil.zip")
unzip(zipfile = "brasil.zip")
mun = st_read(dsn = "mun_01_wgs84.shp")
plot(mun)
install.packages("rnaturalearth")
library(rnaturalearth)
brasil = ne_countries(country = "Brazil") # Fronteiras do Brasil
class(brasil)
brasil_sf = st_as_sf(brasil)
class(brasil_sf)
plot(brasil_sf)
library(raster)
worldclim_prec = getData(name = "worldclim", var = "prec", res =
10)
class(worldclim_prec)
install.packages("osmdata")
library(osmdata)
vignette('osmdata')
parks = opq(bbox = "leeds uk") %>%
add_osm_feature(key = "leisure", value = "park") %>%
osmdata_sf()
parks
world2 = spData::world
world3 = st_read(system.file("shapes/world.gpkg", package =
"spData"))
base_url = "http://www.fao.org"
endpoint = "/figis/geoserver/wfs"
q = list(request = "GetCapabilities")
res = httr::GET(url = httr::modify_url(base_url, path =
endpoint), query = q)
res$url
res
txt = httr::content(res, "text")
xml = xml2::read_xml(txt)
qf = list(request = "GetFeature", typeName = "area:FAO_AREAS")
file = tempfile(fileext = ".gml")
httr::GET(url = base_url, query = qf, httr::write_disk(file))
fao_areas = sf::read_sf(file)
install.packages("ows4R")
library(ows4R)
wfs = WFSClient$new("http://www.fao.org/figis/geoserver/wfs",
serviceVersion = "1.0.0", logger = "INFO")
fao_areas = wfs$getFeatures("area:FAO_AREAS")
sf_drivers = st_drivers()
head(sf_drivers, n = 5)
vector_filepath = system.file("shapes/world.gpkg", package =
"spData")
world = st_read(vector_filepath)
cycle_hire_txt = system.file("misc/cycle_hire_xy.csv", package =
"spData")
cycle_hire_xy = st_read(cycle_hire_txt, options =
c("X_POSSIBLE_NAMES=X", "Y_POSSIBLE_NAMES=Y"))
world_txt = system.file("misc/world_wkt.csv", package = "spData")
world_wkt = read_sf(world_txt, options =
"GEOM_POSSIBLE_NAMES=WKT")
world_wkt = st_read(world_txt, options =
"GEOM_POSSIBLE_NAMES=WKT", quiet = TRUE, stringsAsFactors =
FALSE, as_tibble = TRUE)
u =
"https://developers.google.com/kml/documentation/KML_Samples.kml
"
download.file(u, "KML_Samples.kml")
st_layers("KML_Samples.kml")
raster_filepath = system.file("raster/srtm.tif", package =
"spDataLarge")
single_layer = raster(raster_filepath)
multilayer_filepath = system.file("raster/landsat.tif", package
= "spDataLarge")
band3 = raster(multilayer_filepath, band = 3)
multilayer_brick = brick(multilayer_filepath)
multilayer_stack = stack(multilayer_filepath)
st_write(obj = world, dsn = "world.gpkg")
st_write(obj = world, dsn = "world.gpkg")
st_write(obj = world, dsn = "world.gpkg", layer_options =
"OVERWRITE=YES")
st_write(obj = world, dsn = "world.gpkg", delete_layer = TRUE)
write_sf(obj = world, dsn = "world.gpkg")
st_write(cycle_hire_xy, "cycle_hire_xy.csv", layer_options =
"GEOMETRY=AS_XY")
st_write(world_wkt, "world_wkt.csv", layer_options =
"GEOMETRY=AS_WKT")
writeRaster(single_layer, filename = "my_raster.tif", datatype =
"INT2U")
writeRaster(x = single_layer,
filename = "my_raster.tif",
datatype = "INT2U",
options = c("COMPRESS=DEFLATE"),
overwrite = TRUE)
png(filename = "lifeExp.png", width = 500, height = 350)
plot(world["lifeExp"])
dev.off()
library(tmap)
tmap_obj = tm_shape(world) + tm_polygons(col = "lifeExp")
tmap_save(tm = tmap_obj, filename = "lifeExp_tmap.png")
library(mapview)
mapview_obj = mapview(world, zcol = "lifeExp", legend = TRUE)
mapshot(mapview_obj, file = "my_interactive_map.html")
library(sf)
library(raster)
library(dplyr)
library(spData)
library(spDataLarge)
library(rgdal)
library(maptools)
library(sf)
library(tmap) # para mapeamento estático e interativo
library(leaflet) # para mapeamento interativo
library(mapview) # para mapeamento interativo
library(ggplot2) # visualização de dados
library(shiny) # aplicações para web
brasil <-
readOGR(dsn="C:/livros/geo/4_tipos_mapas/brasil/mun_01_wgs84.shp
", "mun_01_wgs84")
names(brasil)
download.file(url =
"http://www.sergeo.deg.ufla.br/geo/downloads/brasil.zip",
destfile = "brasil.zip")
unzip(zipfile = "brasil.zip")
brasil = st_read(dsn = "mun_01_wgs84.shp")
plot(brasil, border = "transparent")
tm_shape(brasil) +
tm_fill()
tm_shape(brasil) +
tm_borders()
tm_shape(brasil) +
tm_fill() +
tm_borders()
map_brasil = tm_shape(brasil) + tm_polygons()
class(map_brasil)
map_brasil
soja=tm_shape(brasil) + tm_fill(col = "soja")
cafe=tm_shape(brasil) + tm_fill(col = "cafe")
tmap_arrange(soja, cafe)
ma1 = tm_shape(brasil) + tm_fill(col = "red")
ma2 = tm_shape(brasil) + tm_fill(col = "red", alpha = 0.3)
ma3 = tm_shape(brasil) + tm_borders(col = "blue")
ma4 = tm_shape(brasil) + tm_borders(lwd = 3)
ma5 = tm_shape(brasil) + tm_borders(lty = 2)
ma6 = tm_shape(brasil) + tm_fill(col = "red", alpha = 0.3) +
tm_borders(col = "blue", lwd = 3, lty = 2)
tmap_arrange(ma1, ma2, ma3, ma4, ma5, ma6)
legend_title = expression("Area (km"^2*")")
map_brasil1 = tm_shape(brasil) +
tm_fill(col = "AREA_TOT_G", title = legend_title) +
tm_borders()
map_brasil1
tm_shape(brasil) + tm_polygons(col = "cafe")
breaks = c(0, 3, 4, 5) * 10000
tm_shape(brasil) + tm_polygons(col = "cafe", breaks = breaks)
tm_shape(brasil) + tm_polygons(col = "cafe", n = 10)
tm_shape(brasil) + tm_polygons(col = "cafe", palette = "BuGn")
tm_shape(brasil) + tm_polygons(col = "cafe", palette = "Blues")
tm_shape(brasil) + tm_polygons(col = "cafe", palette = "YlOrBr")
tm_shape(brasil) + tm_polygons(col = "cafe", style = "pretty")
tm_shape(brasil) + tm_polygons(col = "cafe", style = "equal")
tm_shape(brasil) + tm_polygons(col = "cafe", style = "quantile")
tm_shape(brasil) + tm_polygons(col = "cafe", style = "jenks")
tm_shape(brasil) + tm_polygons(col = "cafe", style = "cont")
tm_shape(brasil) + tm_polygons(col = "cafe", style = "cat")
map_brasil +
tm_compass(type = "8star", position = c("right", "top")) +
tm_scale_bar(breaks = c(0, 200, 400), text.size = 1)
map_brasil + tm_layout(title = "Brasil")
map_brasil + tm_layout(scale = 5)
map_brasil + tm_layout(bg.color = "lightblue")
map_brasil + tm_layout(frame = FALSE)
map_brasil + tm_style("bw")
map_brasil + tm_style("classic")
map_brasil + tm_style("cobalt")
map_brasil + tm_style("col_blind")
urb_1970_2030 = urban_agglomerations %>%
filter(year %in% c(1970, 1990, 2010, 2030))
tm_shape(world) +
tm_polygons() +
tm_shape(urb_1970_2030) +
tm_symbols(col = "black", border.col = "white", size =
"population_millions") +
tm_facets(by = "year", nrow = 2, free.coords = FALSE)
install.packages("installr")
install.packages("magick")
install.packages("ImageMagick")
require(installr)
require(magick)
install.ImageMagick()
require(ImageMagick)
urb_anim = tm_shape(world) + tm_polygons() +
tm_shape(urban_agglomerations) + tm_dots(size =
"population_millions") +
tm_facets(along = "year", free.coords = FALSE)
urb_anim
tmap_animation(urb_anim, filename = "urb_anim.gif", delay = 25)
tmap_mode("view")
map_brasil
map_brasil + tm_basemap(server = "OpenTopoMap")
world_coffee = left_join(world, coffee_data, by = "name_long")
facets = c("coffee_production_2016", "coffee_production_2017")
tm_shape(world_coffee) + tm_polygons(facets) +
tm_facets(nrow = 1, sync = TRUE)
mapview::mapview(brasil)
install.packages("mapdeck")
library(mapdeck)
set_token(Sys.getenv("MAPBOX"))
crash_data = read.csv("https://git.io/geocompr-mapdeck")
crash_data = na.omit(crash_data)
ms = mapdeck_style("dark")
mapdeck(style = ms, pitch = 45, location = c(0, 52), zoom = 4)
%>%
add_grid(data = crash_data, lat = "lat", lon = "lng", cell_size
= 1000,
elevation_scale = 50, layer_id = "grid_layer",
colour_range = viridisLite::plasma(6))
pal = colorNumeric("RdYlBu", domain = cycle_hire$nbikes)
leaflet(data = cycle_hire) %>%
addProviderTiles(providers$OpenStreetMap.BlackAndWhite) %>%
addCircles(col = ~pal(nbikes), opacity = 0.9) %>%
addPolygons(data = lnd, fill = FALSE) %>%
addLegend(pal = pal, values = ~nbikes) %>%
setView(lng = -0.1, 51.5, zoom = 12) %>%
addMiniMap()
library(shiny) # para aplicativos shiny
library(leaflet) # funções leaflet
library(spData) # base de dados global
ui = fluidPage(
sliderInput(inputId = "life", "Life expectancy", 49, 84, value
= 80),
leafletOutput(outputId = "map")
)
server = function(input, output) {
output$map = renderLeaflet({
leaflet() %>% addProviderTiles("OpenStreetMap.BlackAndWhite")
%>%
addPolygons(data = world[world$lifeExp < input$life, ])})
}
shinyApp(ui, server)
install.packages("cartogram")
library(cartogram)
brasil_carto = cartogram_cont(brasil, "cafe", itermax = 5)
tm_shape(brasil_carto) + tm_polygons("cafe")