Skip to content

Commit

Permalink
bump version; tidy; limit imports; debug vignette error
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Nov 3, 2015
1 parent 5a9d365 commit 3e5df4e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ Depends:
frbs
Imports:
methods,
igraph,
sp,
rgeos,
rgdal,
maptools,
igraph,
spacetime,
trajectories
Suggests:
rjson,
stringr,
geosphere,
RCurl,
rgeos,
rgdal,
maptools,
XML
License: GPL (>= 2)
URL: http://github.com/ngort01/fuzzyMM
Expand Down
10 changes: 6 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export(mm)
export(set_var_bounds)
export(update_mf)
import(frbs)
import(igraph)
import(maptools)
import(methods)
import(osmar)
import(rgdal)
import(rgeos)
import(sp)
import(spacetime)
import(trajectories)
importFrom(igraph,"V<-")
importFrom(igraph,E)
importFrom(igraph,V)
importFrom(igraph,as.undirected)
importFrom(igraph,get.edgelist)
importFrom(igraph,shortest.paths)
6 changes: 4 additions & 2 deletions R/IMP.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ imp <- function (traj, roads = "DigitalRoadNetwork", err_region) {
current_pt <- cbind(lon, lat)
rec <- err_region(lon, lat, err_region)

if (!requireNamespace("rgeos", quietly = TRUE))
stop("package rgeos required")
# Get edges inside the error region
candidate_links <- data.frame(edge_id = unique(c(which(gIntersects(rec, roads@sl, byid = TRUE)),
which(gContains(rec, roads@sl, byid = TRUE)))))
candidate_links <- data.frame(edge_id = unique(c(which(rgeos::gIntersects(rec, roads@sl, byid = TRUE)),
which(rgeos::gContains(rec, roads@sl, byid = TRUE)))))

# Nodes of the candidate links
candidate_links$V1 <- get.edgelist(roads@g)[candidate_links$edge_id, 1]
Expand Down
43 changes: 24 additions & 19 deletions R/SMP2.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ smp2 <- function(traj, roads = "DigitalRoadNetwork", current_link, pt_index = "n
,prev_link$V1, prev_link$V2)
}

if (!requireNamespace("rgeos", quietly = TRUE))
stop("package rgeos required")
# Get edges inside the error region
candidate_links <- data.frame(edge_id = unique(c(which(gIntersects(rec, roads@sl, byid = TRUE)),
which(gContains(rec, roads@sl, byid = TRUE)))))
candidate_links <- data.frame(edge_id = unique(c(which(rgeos::gIntersects(rec, roads@sl, byid = TRUE)),
which(rgeos::gContains(rec, roads@sl, byid = TRUE)))))
# Nodes of the candidate links
candidate_links$V1 <- get.edgelist(roads@g)[candidate_links$edge_id, 1]
candidate_links$V2 <- get.edgelist(roads@g)[candidate_links$edge_id, 2]
Expand All @@ -46,15 +48,26 @@ smp2 <- function(traj, roads = "DigitalRoadNetwork", current_link, pt_index = "n
stop("package geosphere required")
# Calculate the perpendicular distance from the current point to all
# segments inside the error region and the closest point on the segments
#str(candidate_links[,c("edge_id")])
PD <- sapply(candidate_links[,c("edge_id")],
function(x) geosphere::dist2Line(current_pt, roads@sl@lines[[x]]@Lines[[1]]@coords))

#str(PD) -- EP
# Perpendicular distance
candidate_links$PD <- PD[1,]
# Nearest point
candidate_links$NP_x <- PD[2,]
candidate_links$NP_y <- PD[3,]
function(x) geosphere::dist2Line(current_pt, roads@sl@lines[[x]]@Lines[[1]]@coords))

#str(PD) -- EP: might be list(), which then breaks;
#str(class(PD))
str(candidate_links)
if (length(PD) == 0) {
# Perpendicular distance
#candidate_links$PD <- 1e9 # large
# Nearest point
#candidate_links$NP_x <- 0
#candidate_links$NP_y <- 0
} else {
# Perpendicular distance
candidate_links$PD <- PD[1,]
# Nearest point
candidate_links$NP_x <- PD[2,]
candidate_links$NP_y <- PD[3,]
}

# Calculate the beraing of the segments
# If a segment is defined by the points a and b, bearing can be:
Expand Down Expand Up @@ -135,15 +148,7 @@ smp2 <- function(traj, roads = "DigitalRoadNetwork", current_link, pt_index = "n
candidate_links$pred <- predict(fis3, newdata)$predicted.val

# Current link the vehicle is traveling on
current_link <- candidate_links[candidate_links$pred ==
max(candidate_links$pred),][,c("V1", "V2", "edge_id", "direction", "NP_x", "NP_y")]
current_link <- candidate_links[which.max(candidate_links$pred),c("V1", "V2", "edge_id", "direction", "NP_x", "NP_y")]

current_link
}







3 changes: 2 additions & 1 deletion R/fuzzyMM-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
#'
#' @docType package
#' @name fuzzyMM-package
#' @import methods igraph frbs osmar sp rgeos rgdal maptools spacetime trajectories
#' @import methods frbs osmar sp spacetime trajectories
#' @importFrom igraph as.undirected V "V<-" get.edgelist E shortest.paths
NULL

0 comments on commit 3e5df4e

Please sign in to comment.