Skip to contents

The function joins ports locations using data from ports buffers. mx_ports data is used which is provided by INEGI https://en.www.inegi.org.mx/

Usage

join_ports_locations(x, mx_ports = mx_ports, buffer_size = 0.15)

Arguments

x

a data.frame with latitude and longitude coordinates

mx_ports

is a shapefile of point data storing coordinates of ports and marina in Mexico, you can upload this using data("mx_ports")

buffer_size

a number (double) indicating the size of the buffer for the ports to implement

Value

A data.frame

Details

The function adds a location column indicating if the vessel was at port or at sea.

Examples


# With sample data

data("sample_dataset")
data("mx_ports")
vms_cleaned <- vms_clean(sample_dataset)
#> Cleaned: 969 empty rows from data! 

# It is a good idea to subsample when testing... it takes a while on the full data!

vms_subset <- dplyr::sample_n(vms_cleaned, 1000)
with_ports <- join_ports_locations(vms_subset)
#> Warning: st_buffer does not correctly buffer longitude/latitude data
#> dist is assumed to be in decimal degrees (arc_degrees).
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_difference assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout all geometries
with_ports_sf <- sf::st_as_sf(with_ports, coords = c("longitude", "latitude"), crs = 4326)

data("mx_shape")
library(ggplot2)
ggplot(mx_shape) +
  geom_sf(col = "gray90") +
  geom_sf(data = with_ports_sf, aes(col = location)) +
  facet_wrap(~location) +
  theme_bw()