DataCamp Spatial Analysis with sf and raster in R
Compute tree density and average tree canopy by neighborhood
SPATIAL ANALYSIS WITH SF AND RASTER IN R
Compute tree density and average tree canopy by neighborhood Zev - - PowerPoint PPT Presentation
DataCamp Spatial Analysis with sf and raster in R SPATIAL ANALYSIS WITH SF AND RASTER IN R Compute tree density and average tree canopy by neighborhood Zev Ross President, ZevRoss Spatial Analysis DataCamp Spatial Analysis with sf and
DataCamp Spatial Analysis with sf and raster in R
SPATIAL ANALYSIS WITH SF AND RASTER IN R
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> head(neighborhoods) # Simple feature collection with 6 features and 8 fields # geometry type: MULTIPOLYGON # dimension: XY # bbox: xmin: -74.00736 ymin: 40.61264 xmax: -73.77574 ... # epsg (SRID): 4326 # proj4string: +proj=longlat +ellps=WGS84 +no_defs # county_fip boro_name hood ntaname boro_code area tree_cnt # 1 047 Brooklyn BK88 Borough Park 3 5017229 565 # 2 081 Queens QN52 East Flushing 4 2736433 295 # 3 081 Queens QN48 Auburndale 4 3173995 507 # 4 081 Queens QN51 Murray Hill 4 4876380 732 # 5 081 Queens QN27 East Elmhurst 4 1832715 211 # 6 005 Bronx BX35 Morrisania-Melrose 2 1569317 214 # tree_density geometry # 1 0.0001126120 MULTIPOLYGON(((-73.97604935... # 2 0.0001078046 MULTIPOLYGON(((-73.79493246... # 3 0.0001597356 MULTIPOLYGON(((-73.77573836... # 4 0.0001501114 MULTIPOLYGON(((-73.80379022... # 5 0.0001151297 MULTIPOLYGON(((-73.86109724... # 6 0.0001363650 MULTIPOLYGON(((-73.89696589...
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> head(neighborhoods) # Simple feature collection with 6 features and 9 fields # geometry type: MULTIPOLYGON # dimension: XY # bbox: xmin: 1828213 ymin: 2168794 xmax: 1844284 ymax: 2194502 # epsg (SRID): NA # proj4string: +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 ... # county_fip boro_name hood ntaname boro_code area total # 1 047 Brooklyn BK88 Borough Park 3 5017229 565 # 2 081 Queens QN52 East Flushing 4 2736433 295 # 3 081 Queens QN48 Auburndale 4 3173995 507 # 4 081 Queens QN51 Murray Hill 4 4876380 732 # 5 081 Queens QN27 East Elmhurst 4 1832715 211 # 6 005 Bronx BX35 Morrisania-Melrose 2 1569317 214 # tree_density avg_canopy geometry # 1 0.0001126120 0.7253846 MULTIPOLYGON(((1830843.4956... # 2 0.0001078046 8.4133333 MULTIPOLYGON(((1842344.8587... # 3 0.0001597356 4.1568750 MULTIPOLYGON(((1844283.8606... # 4 0.0001501114 8.5205000 MULTIPOLYGON(((1841161.6511... # 5 0.0001151297 2.5930000 MULTIPOLYGON(((1836803.3413... # 6 0.0001363650 3.1740000 MULTIPOLYGON(((1832056.9137...
DataCamp Spatial Analysis with sf and raster in R
SPATIAL ANALYSIS WITH SF AND RASTER IN R
DataCamp Spatial Analysis with sf and raster in R
SPATIAL ANALYSIS WITH SF AND RASTER IN R
DataCamp Spatial Analysis with sf and raster in R
ggplot2 for plots and maps tmap for polished maps
DataCamp Spatial Analysis with sf and raster in R
# New York State > county <- st_read("county.shp") > head(county) # geoid total_pop area geometry # 1 36101 98665 3601.568 MULTIPOLYGON (((-77.423093 ... # 2 36091 223774 2097.880 MULTIPOLYGON (((-74.124335 ... # 3 36003 48070 2665.875 MULTIPOLYGON (((-78.309193 ... # 4 36075 121183 2464.746 MULTIPOLYGON (((-76.617586 ... # 5 36111 181300 2911.758 MULTIPOLYGON (((-74.67402 4... # 6 36089 112011 6939.259 MULTIPOLYGON (((-74.939447 ...
DataCamp Spatial Analysis with sf and raster in R
> library(ggplot2) > ggplot(data = county, aes(x = total_pop, y = area))
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> ggplot(data = county, aes(x = total_pop, y = area)) + + geom_point()
DataCamp Spatial Analysis with sf and raster in R
> ggplot(data = county, aes(x = total_pop, y = area)) + + geom_point() + + stat_smooth()
DataCamp Spatial Analysis with sf and raster in R
> ggplot(data = county) + + geom_sf()
DataCamp Spatial Analysis with sf and raster in R
> ggplot(data = county, aes(fill = area)) + + geom_sf()
DataCamp Spatial Analysis with sf and raster in R
> ggplot(data = county, aes(fill = area)) + + geom_sf() + + scale_fill_gradient(low = "wheat1", high = "red")
DataCamp Spatial Analysis with sf and raster in R
> county <- st_transform(county, crs = 32618) > ggplot(data = county, aes(fill = area)) + + geom_sf() + + scale_fill_gradient(low = "wheat1", high = "red")
DataCamp Spatial Analysis with sf and raster in R
> cor(county$area, county$total_pop) [1] -0.378985
DataCamp Spatial Analysis with sf and raster in R
SPATIAL ANALYSIS WITH SF AND RASTER IN R
DataCamp Spatial Analysis with sf and raster in R
SPATIAL ANALYSIS WITH SF AND RASTER IN R
DataCamp Spatial Analysis with sf and raster in R
# Running this with no layers will produce an error > tm_shape(county)
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> tm_shape(county) + + tm_polygons()
DataCamp Spatial Analysis with sf and raster in R
> tm_shape(county) + + tm_polygons() + + tm_bubbles(col = "forestgreen")
DataCamp Spatial Analysis with sf and raster in R
> tm_shape(elevation) + + tm_raster() + + tm_shape(county) + + tm_borders()
DataCamp Spatial Analysis with sf and raster in R
> tm_shape(county) + + tm_polygons(col = "total_pop")
DataCamp Spatial Analysis with sf and raster in R
> map1 <- tm_shape(county) + + tm_polygons(col = "total_pop") > map2 <- tm_shape(elevation) + + tm_raster() > tmap_arrange(map1, map2, nrow = 1)
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
SPATIAL ANALYSIS WITH SF AND RASTER IN R
DataCamp Spatial Analysis with sf and raster in R
SPATIAL ANALYSIS WITH SF AND RASTER IN R
DataCamp Spatial Analysis with sf and raster in R
sf is a dramatic improvement over sp for handling vectors raster is a smart and intuitive package that can perform spatial analysis with
DataCamp Spatial Analysis with sf and raster in R
st_read("myvector.shp") raster("myraster.tif") or brick("myraster.tif")
DataCamp Spatial Analysis with sf and raster in R
sf objects are data frames
st_geometry() returns just the geometry
DataCamp Spatial Analysis with sf and raster in R
st_crs() and crs() to get or set the CRS st_transform() and projectRaster() to change the CRS
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> library(ggplot2) > ggplot(polys) + + geom_sf() > library(tmap) > tm_shape(polys) + + tm_polygons()
DataCamp Spatial Analysis with sf and raster in R
SPATIAL ANALYSIS WITH SF AND RASTER IN R