-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateShapefile.qmd
52 lines (37 loc) · 1.07 KB
/
CreateShapefile.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
title: "Create Shapefile"
author: "Julia Blanchard"
format: html
editor: visual
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Convert your bounding box to a shapefile
If you would like to create a map in R or combine shapefiles to create a mask, it may be helpful to create a shapefile first and save it for later.
This simple R code does that for a set of bounding boxes for regional ecosystem models used in FishMIP.
First, install packages you need:
```{r}
install.packages("sp")
install.packages("sf")
install.packages("raster")
install.packages("tidyverse")
install.packages("spData")
install.packages("tmap")
library(sp)
library(sf)
library(raster)
library(tidyverse)
library(spData)
library(tmap)
```
## Set up Bounding Box
```{r,echo=FALSE}
cook_strait <- as(raster::extent(174.5, 179.5, -46.5, -40.5), "SpatialPolygons")
proj4string(cook_strait) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
plot(cook_strait)
shapefile(cook_strait, filename='cook_strait.shp')
cook_strait_shp <- st_read(
"cook_strait.shp")
cook_strait_shp
```