knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  echo = TRUE,tidy='formatR', 
  tidy.opts=list(width.cutoff = 70)
)
library(TransGPS)

TransGPS: Toward a better analysis of GPS data

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.

Installation

devtools::install_github("farinoushsharifi/TransGPS")

Usage

library(TransGPS)

### Load Sample Data
data("SampleTransGPS")

The first 10 rows of the data can be seen here:

head(as.data.frame(SampleTransGPS),10)

1. Coordinates Conversion to New CRS

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).

#define the conversion function inputs 
LatList1 <- SampleTransGPS$Latitude  
LongList1 <- SampleTransGPS$Longitude
timeseq1 <- SampleTransGPS$First.Time
timeseq1 <-  as.POSIXct(timeseq1, format = "%I:%M:%S %p")

InitProj <- "+proj=longlat +ellps=WGS84 
+datum=WGS84 +no_defs +towgs84=0,0,0"
NextProj <- "+init=epsg:28992"

#convert from the initial CRS to a new one
convlist <- convert_crs(LatList=LatList1,LongList=LongList1,
                        InitProj=InitProj,NextProj=NextProj)

The first 10 rows of the converted data can be seen here:

head(data.frame(convlist$Latitude,convlist$Longitude),10)

2. Coordinates Interpolation

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,]

There is no need to sort the data before using the interpolation_coords function. The first 10 rows can be seen here:

head(SampleTransGPS_ir,10)

This data can be interpolated using function interpolate_coord

#define the interpolation function inputs
LatList2 <- SampleTransGPS_ir$Latitude
LongList2 <- SampleTransGPS_ir$Longitude
timeseq2 <- SampleTransGPS_ir$First.Time
timeseq2 <-  as.POSIXct(timeseq2, format = "%I:%M:%S %p")
timeint <- 2 ###2 seconds

#interpolate the GPS coordinates
interp_data <- interpolate_coords(LatList=LatList2,LongList=LongList2,
                                  timeseq=timeseq2,timeint=timeint)

The first 10 rows of this interpolated datacan be seen here:

head(interp_data,10)

3. Generate Bounding Boxes

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 offLatare 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 boxes
boxout <- get_boxes(LatList=LatList1,LongList=LongList1,
                    timeseq=timeseq1,resolution = resolution,
                    offLong=offLong,offLat = offLat)
boxcuts <- boxout$boxtable$boxcuts
boxlist <- boxout$boxlist

4. Plot Link Speed and Bounding Boxes

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_route(LatList1,LongList1,timeseq1,boxlist)

5. Matching The OSM Link IDs to GPS Coordinates

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.

IDList <- match_highway(LatList= LatList1,LongList= LongList1,timeseq=timeseq1,k=5,boxcuts = boxcuts, boxlist=boxlist)

The output of this function is the list of OSM highway link IDs assigned to each point.

head(IDList,10)

Details

For more information on TransGPS Package, please access the package documentations. Please feel free to contact the author.



farinoushsharifi/TransGPS documentation built on June 3, 2019, 7:19 a.m.