DataCamp Spatial Analysis with sf and raster in R
Buffers and centroids
SPATIAL ANALYSIS WITH SF AND RASTER IN R
Buffers and centroids Zev Ross President, ZevRoss Spatial Analysis - - PowerPoint PPT Presentation
DataCamp Spatial Analysis with sf and raster in R SPATIAL ANALYSIS WITH SF AND RASTER IN R Buffers and centroids Zev Ross President, ZevRoss Spatial Analysis DataCamp Spatial Analysis with sf and raster in R Use a projected coordinate
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
# Buffer five trees, this is feet > trees_buf <- st_buffer(trees5, + 5000)
DataCamp Spatial Analysis with sf and raster in R
> poly <- st_read("poly.shp") > poly_cent <- st_centroid(poly)
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
DataCamp Spatial Analysis with sf and raster in R
# Read data in and get the bbox coords > poly <- st_read("poly.shp") # Compute the bounding box coordinates > st_bbox(poly) xmin ymin xmax ymax 913090.8 120053.5 1067383.5 272932.1
DataCamp Spatial Analysis with sf and raster in R
# Bounding box of counties in red > poly_grd <- st_make_grid( + poly, n = 1 + ) # Bounding box of centroids in green > cent_grd <- st_make_grid( + poly_cent, n = 1 + )
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
# Simple feature collection with 2 features and 1 field # geometry type: POLYGON # dimension: XY # bbox: xmin: 971113.7 ymin: 146981.3 xmax: 1030504 ymax: 259547.8 # epsg (SRID): NA # proj4string: +proj=lcc +lat_1=40.66666666666666 +lat_2=41.033333 ... # BoroName geometry # 1 Manhattan POLYGON ((971113.66006219 1... # 2 Brooklyn POLYGON ((972454.529951439 ...
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> grds_union <- st_union(polys) > grds_union # Geometry set for 1 feature # geometry type: POLYGON # dimension: XY # bbox: xmin: 971113.7 ... # epsg (SRID): NA # proj4string: +proj=lcc ... # POLYGON ((1010061.70003446 ...
DataCamp Spatial Analysis with sf and raster in R
> select(boro_cent, BoroName, geometry) # Simple feature collection with 5 features and 1 field # geometry type: POINT # dimension: XY # bbox: xmin: 941777.1 ymin: 150931 xmax: 1034598 ymax: 249928.1 # epsg (SRID): NA # proj4string: +proj=lcc +lat_1=40.66666666666666 ... # BoroName geometry # 1 Manhattan POINT (993372.855589884 222... # 2 The Bronx POINT (1021130.02634457 249... # 3 Staten Island POINT (941777.089270765 150... # 4 Brooklyn POINT (999165.45349374 1739... # 5 Queens POINT (1034598.34861245 196...
DataCamp Spatial Analysis with sf and raster in R
> boro_union <- st_union(boro_cent) > boro_union # Geometry set for 1 feature # geometry type: MULTIPOINT # dimension: XY # bbox: xmin: 941777.1 ymin: 150931 xmax: 1034598 ymax: 249928.1 # epsg (SRID): NA # proj4string: +proj=lcc +lat_1=40.66666666666666 ... # MULTIPOINT (941777.089270765 150931.02608931, 9...
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> chull <- st_convex_hull(boro_union)
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
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> head(roads) # Simple feature collection with 6 features and 2 fields # geometry type: MULTILINESTRING # dimension: XY # bbox: xmin: 283409.6 ymin: 13674360 xmax: 415302.7 ... # epsg (SRID): 32712 # proj4string: +proj=utm +zone=12 +south +datum=WGS84 +units=m +no_defs # fullname linearid geom # 3 15400 N 1106093299255 MULTILINESTRING ((368965.05... # 4 W Thomas Rd N 1103680827068 MULTILINESTRING ((359947.09... # 5 W Thomas Rd S 1103680826832 MULTILINESTRING ((359642.75... # 6 W Lost Creek Dr E 1101629369359 MULTILINESTRING ((360798.66... # 7 W Lost Creek Dr W 1101629369529 MULTILINESTRING ((358095.55... # 8 I- 10 1101629193616 MULTILINESTRING ((283409.56...
DataCamp Spatial Analysis with sf and raster in R
> roads <- st_join(roads, tracts) > head(roads) # Simple feature collection with 6 features and 3 fields # geometry type: MULTILINESTRING # dimension: XY # bbox: xmin: 358095.6 ymin: 13704750 xmax: 368965.1 ... # epsg (SRID): 32712 # proj4string: +proj=utm +zone=12 +south +datum=WGS84 +units=m +no_defs # fullname linearid geoid geom # 3 15400 N 1106093299255 04013050605 MULTILINESTRING ((368965.0... # 3.1 15400 N 1106093299255 04013061031 MULTILINESTRING ((368965.0... # 4 W Thomas Rd N 1103680827068 04013050605 MULTILINESTRING ((359947.0... # 5 W Thomas Rd S 1103680826832 04013050605 MULTILINESTRING ((359642.7... # 6 W Lost Creek Dr E 1101629369359 04013050605 MULTILINESTRING ((360798.6... # 7 W Lost Creek Dr W 1101629369529 04013050605 MULTILINESTRING ((358095.5...
DataCamp Spatial Analysis with sf and raster in R
> plot(roads["geoid"]) > plot(st_geometry(tracts), border = "black", add = TRUE)
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
# Result is a list > intersects <- st_intersects(tract, roads)[[1]] # The index number of roads that intersect > head(intersects) [1] 1 2 6 12 15 19 > plot(st_geometry(roads[intersects,]), add = TRUE, col = "red")
DataCamp Spatial Analysis with sf and raster in R
> contains <- st_contains(tract, roads)[[1]] > plot(st_geometry(roads[contains,]), add = TRUE, col = "blue")
DataCamp Spatial Analysis with sf and raster in R
# Clip the roads to the tract polygon > clipped <- st_intersection(tract, roads) > plot(st_geometry(tract), col = "grey", border = "white") > plot(st_geometry(clipped), add = TRUE)
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> dist1 <- st_distance(tract_cent, roads) > roads$dist <- dist1[1, ]
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
DataCamp Spatial Analysis with sf and raster in R
> polys <- as(polys, "Spatial") > el_mask <- mask(elevation, mask = polys) > plot(el_mask)
DataCamp Spatial Analysis with sf and raster in R
> el_crop <- crop(elevation, polys) > plot(el_crop) > plot(polys, add = TRUE)
DataCamp Spatial Analysis with sf and raster in R
> el_crop <- crop(elevation, polys) > el_mask <- mask(el_crop, mask = polys) > plot(el_mask)
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
# For polys fun = NULL will return all values > vals <- extract(elevation, polys, fun = mean) > vals # [,1] # [1,] 471.1458 # hill polygon # [2,] 203.4773 # lake polygon
DataCamp Spatial Analysis with sf and raster in R
DataCamp Spatial Analysis with sf and raster in R
> f <- function(rast1, rast2) rast1 * rast2 > alt_ele <- overlay(elevation, multiplier, fun = f)
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