Skip to content

Commit

Permalink
coordinates format in the req (fix #44 ?)
Browse files Browse the repository at this point in the history
  • Loading branch information
rCarto committed Jun 14, 2019
1 parent cf599e3 commit 3ab5cb6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ sfToDf <- function(x){
coords <- sf::st_coordinates(x)
# this function takes an sf and transforms it into a dataframe
x <- data.frame(id = row.names(x),
lon = format(round(coords[,1],5),
scientific = FALSE, trim = TRUE),
lat = format(round(coords[,2],5),
scientific = FALSE, trim = TRUE),
lon = format(coords[,1], scientific = FALSE, justify = "none",
trim = TRUE, nsmall = 5, digits = 5),
lat = format(coords[,2], scientific = FALSE, justify = "none",
trim = TRUE, nsmall = 5, digits = 5),
stringsAsFactors = FALSE)
return(x)
}




## osrmIsochrone Utils
#' @import sf
isopoly <- function(x, breaks,
Expand Down Expand Up @@ -139,15 +138,18 @@ coordFormat <- function(res, src, dst){
return(list(sources = sources, destinations = destinations)
)
}

tableLoc <- function(loc, gepaf = FALSE){
# Query build
if (gepaf == TRUE){
tab <- paste0(getOption("osrm.server"), "table/v1/", getOption("osrm.profile"), "/polyline(")
tab <- paste0(tab, gepaf::encodePolyline(loc[,c("lat","lon")]),")")
}else{
tab <- paste0(getOption("osrm.server"), "table/v1/", getOption("osrm.profile"), "/")
tab <- paste0(tab, paste(format(loc$lon, scientific = FALSE, trim = TRUE),
format(loc$lat, scientific = FALSE, trim = TRUE),
tab <- paste0(tab, paste(format(loc$lon, scientific = FALSE, justify = "none",
trim = TRUE, nsmall = 5, digits = 5),
format(loc$lat, scientific = FALSE, justify = "none",
trim = TRUE, nsmall = 5, digits = 5),
sep=",",collapse = ";"))
}
return(tab)
Expand Down

0 comments on commit 3ab5cb6

Please sign in to comment.