knitr::opts_chunk$set(echo = TRUE,tidy='formatR', tidy.opts=list(width.cutoff = 70))
This package is developed to ease the tedious procedure of GPS data cleaning and map matching. The functions provided here focus from the very basic regularization and coordinates conversion of the GPS data toward creating bounding boxes and accessing the well-known OpenStreetMap(OSM) data for the purpose of map matching.
Creating bounding boxes allows the users to access OSM data without any challenges of developing a data server. This package also provides an interactive platform for the users to find the desired bounding boxes on the map. Finally, the user can find the best link match for each GPS coordinate.
devtools::install_github("farinoushsharifi/TransGPS")
library(TransGPS)
### Load Sample Data data("SampleTransGPS") head(as.data.frame(SampleTransGPS),10) #define the conversion function inputs LatList <- SampleTransGPS$Latitude LongList <- SampleTransGPS$Longitude timeseq <- SampleTransGPS$First.Time timeseq <- as.POSIXct(timeseq, format = "%I:%M:%S %p") InitProj <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0" NextProj <- "+init=epsg:28992"
Conversion of the GPS coordinates into a new CRS is the base to initiate any GPS analysis studies. convert_crs
takes the initial latitude and longitude of a list of points and convert to any new CRS. The default value for the final projection is "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
, which the CRS corresponding to OSM data (and the CRS for the SampleTransGPS
data).
#convert from the initial CRS projection to a new one convlist <- convert_crs(LatList=LatList,LongList=LongList, InitProj=InitProj,NextProj=NextProj)
Intepolation of coordinates over a desired time sequence is so useful in case of irregular time sequence or better visualization of data on contour maps. Function interpolate_coords
takes the lists of latitudes and longitudes over an irregular time sequence and interpolates coordinates.
#taking a sample of data for an irregular time sequence rowIDs <- sample(1:nrow(SampleTransGPS),200) SampleTransGPS_ir <- SampleTransGPS[rowIDs,]
#interpolate the GPS coordinates over 3 seconds interp_data <- interpolate_coords(LatList=LatList,LongList=LongList, timeseq=timeseq,timeint=3)
While working with specific few roads rather than the whole network, generating regions and boxes around the corridors helps to better focus on the route, instead of the whole area, and remove unnecessary areas or roads from the data. So, accessing the OSM data can be easier, less challenging, and can be done in small chunks. get_boxes
function splits the corridors in smaller regions by considering a maximum route distance of resolution
within each box. offLong
and offLat
are the margins of each box from the closest coordinate point. The output gives the ID of box (boxcuts
) for each point as well as the coordinates of each box (boxlists
).
#define resolutions and margins resolution = 5 offLong=0.001 offLat=0.002
#create bounding boxes boxout <- get_boxes(LatList=LatList,LongList=LongList, timeseq=timeseq,resolution = resolution, offLong = offLong,offLat = offLat) boxcuts <- boxout$boxtable$boxcuts boxlist <- boxout$boxlist
To better study the bounding boxes generated and estimate the resolution
and margins, plot_route
function is provided. It also has the option to show the average speed of the vehicle on the corridor.
#plot the link speeds and bounding boxes plot_route(LatList=LatList,LongList=LongList,timeseq=timeseq, boxlist=boxlist)
The process of matching the GPS points to the OSM data links or features can so challenging and inaccurate. The function match_highway
in this package helps with this process in multiple ways. Firstly, it splits the network in few boxes and reduce the tension of accessing the whole OSM data at once or setting up a server for "planet.osm" data. Secondly, it considers k
close points rather than the closest point to the coordinate. Finally, it tries to keep the route choice consistency.
#match each points to an OSM highway IDList <- match_highway(LatList= LatList,LongList= LongList,timeseq=timeseq,k=5,boxcuts = boxcuts, boxlist=boxlist)
For more information on TransGPS Package, please access the package documentations or vignettes. Please feel free to contact the author.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.