View source: R/ships_methods.R
ais.to.DeponsShips | R Documentation |
Convert Automatic Identification System (AIS) data for ships to
ship track objects. This is done by cropping one or more ship tracks to the
extent of a landscape and converting the data to a DeponsShips-class
object. If the AIS data does not include ship positions recorded in half-hour
steps, the tracks are interpolated to make objects suitable for use in DEPONS.
ais.to.DeponsShips(data, landsc, title = "NA", ...)
data |
data.frame with ship positions and the times at which the positions were recorded. Must contain the columns 'id', 'time' (of the form " type, character), 'length' (ship length, meters), 'x', and 'y' (position, meters/UTM). |
landsc |
A |
title |
Title of the output object |
... |
Optional parameters, including 'startday' and 'endday' (" from 'data'. If startday = endday the output object will contain up to 49 positions from the selected date for each vessel track. |
Returns a DeponsShips
object containing one or more ships
assigned to each of the routes in the object. All ships on a particular
route move at the same speed along the route. The routes are
defined by x and y coordinates based on the same coordinate reference
system as the landscape they are located in. The speed that ships use after
reaching a particular position (a particular 'virtual buoy') is calculated
from the distance to the following position, and the time it takes reaching
that position. If speed is included in the input AIS data, this is NOT used.
The routes include one position per half-hour time step, corresponding to
the default time step used in the DEPONS model. If input data does not
include one position per half hour, new positions are generated using linear
interpolation. If the input data contains many positions in a particular
half-hour interval, only the positions closest to the half-hour interval are
used. The routes contain information about the number of half-hour
intervals were ships 'pause' at a particular location, e.g. in a
port. These are calculated based on the input AIS data.
aisdata
for an example of data that can be used as
input to ais.to.DeponsShips. The function builds on
interpolate.ais.data
, which interpolates tracks to ensure
that there is a position every 30 minutes.
See write.DeponsShips
for conversion of
DeponsShips
objects to json-files to be used in DEPONS. Use
routes
, ships
, and title
for
inspection/modification of the ship tracks.
data(aisdata)
plot(aisdata$x, aisdata$y, type="n", asp=1)
ids <- sort(unique(aisdata$id))
my.colors <- heat.colors(length(ids))
for (i in 1:length(ids)) {
id <- ids[i]
points(aisdata$x[aisdata$id==id], aisdata$y[aisdata$id==id],
cex=0.6, col=my.colors[i])
}
data(bathymetry)
plot(bathymetry, add=TRUE)
depons.ais <- ais.to.DeponsShips(aisdata, bathymetry)
the.routes <- routes(depons.ais)
for (i in 1:length(ids)) {
points(the.routes[[i]]$x, the.routes[[i]]$y,
cex=0.6, pch=16, col=my.colors[i])
}
depons.ais <- ais.to.DeponsShips(aisdata, bathymetry,
startday="2015-12-20", endday="2015-12-20")
routes(depons.ais)
aisdata2 <- aisdata
aisdata2$time <- format(as.POSIXct(aisdata$time)+300)
depons.ais2 <- ais.to.DeponsShips(aisdata2, bathymetry,
startday="2015-12-20", endday="2015-12-21")
routes(depons.ais2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.