If you would like to return to information from the previous session, please click here
In order to correctly represent spatial coordinates from WGS84 (i.e. Latitude-Longitude) on a flat surface, we need to project them. This projection makes the easting and northing values equidistant and necessary for measuring distance between sites.
This wiki page illustrates ways to easily manage projections using
the sf
package.
In the integrate.R
script, we set the utm details for
the Western Indian Ocean region (i.e. UTM 38 S):
# set utm details
utm_details <-
paste0("+proj=utm +zone=38 +south +datum=WGS84 +units=m",
" +no_defs +ellps=WGS84") %>% CRS()
Once the UTM details are set, the transformation is relatively
straight forward. As the WIO coastline is a sf
object, we
can use the st_transform()
function:
# reproject
wio_coastline %<>%
st_transform(crs = utm_details)
# Simple feature collection with 1366 features and 6 fields
# Geometry type: MULTIPOLYGON
# Dimension: XY
# Bounding box: xmin: -2556703 ymin: 5843442 xmax: 2465777 ymax: 11361570
One can notice the bounding box is now represented by a different number format (i.e. in metres!).
For transforming the spatial objects for the Kenya fishes data, this can also b e achieved by specifying the CRS reference number:
# project to utm 38 s
kenya_fishes_sites %<>%
st_transform(crs = 32738)
# project bounds
kenya_bounds <-
c(lim_e,
lim_w,
lim_s,
lim_n) %>%
extent() %>%
st_bbox(crs = st_crs(4326)) %>%
st_as_sfc() %>%
st_transform(crs = 32738)
# Geometry set for 1 feature
# Geometry type: POLYGON
# Dimension: XY
# Bounding box: xmin: -85960.96 ymin: 9554141 xmax: -39432.18 ymax: 9643856
# Projected CRS: WGS 84 / UTM zone 38S
# POLYGON ((-85441.03 9554141, -39432.18 9554427,...
# set extent
kenya_bounds %<>% st_bbox()
Note: Because of the width of the WIO region, this UTM region does not adequately represent the entire region - in which case, a custom projection would be better suited.
Users interested in additional information on managing projections in
R
should look here.
Now that we have a way to easily manage the projections, we can go on to visualising our monitoring data.