I'm trying to get some routes with here.com using Rstudio for Canada, from side to side but making sure I exclude getting in the US. I've found exclude in Routing but I can't find a way to allocate it in route() function, or don't know where to include. Also used avoid_area = USA as shown in their guide through this link using US shapefile as criteria for the function, where I named the shp USA and that's what I added in the function as specified below, and no luck because it's returning fewer options than if I didn't include that piece, how do I exclude USA for Canadian routing using here.com?
# Packages
library("sf")
library("tidyverse")
library( "hereR")
library("stringi")
library("dplyr")
# Load data
address <- structure(list(Origin = "Fredericton", Lat1 = 45.9379251883697,
Lon1 = -66.593737477555, Destination = "Richmomnd", Lat2 = 45.8767690820575,
Lon2 = -66.3300656050966), row.names = c(NA, -1L), class = c("tbl_df",
"tbl", "data.frame"))
# Set API key for free through throug https://developer.here.com/self-serve
set_key(api_key = "YOUR_FREEMIUN_KEY")
# Create SFDFs (points with lat-lon pairs):
dist.pairs.input.1 <- dist.pairs.query %>%
st_as_sf(coords = c("Lon1","Lat1"),
crs = "WGS84",
remove = F)
dist.pairs.input.2 <- dist.pairs.query %>%
st_as_sf(coords = c("Lon2", "Lat2"),
crs = "WGS84",
remove = F)
# Get routing:
query_result <- route(origin = dist.pairs.input.1,
destination = dist.pairs.input.2,
traffic = T,
avoid_area = USA) # where USA is USA's shapefile