- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含不同位置的数百个纬度-经度坐标对的列表。我的目标是使用 R 估算从“家”位置到每个坐标对的行驶持续时间。
我在 R 中使用 googleway
包取得了一些成功,但(可以预见)在远离道路的位置遇到问题,例如如果坐标是山顶。在这些情况下,我想估计到每个有问题的坐标对的最近道路的行驶时间。
为了说明,假设我家的位置是;
home <- "Edinburgh, UK"
...以及我想找到可能到达的行车时间的位置示例数据框;
location <- c("place_a", "place_b", "place_c")
latitude <- c("56.87034", "57.69380", "57.36243")
longitude <- c("-4.199001", "-5.128715", "-5.104728")
df <- data.frame(location, latitude, longitude)
我可以获得home
和place_a
之间,home
和place_b
之间的距离/时长等> 使用类似的东西;
(注意。您需要自己的 Google Maps api key 才能复制此部分...)
library(googleway)
api_key <- [insert your Google Maps api key here!]
results <- google_distance(origins = home,
destinations = list(c("56.87034,-4.199001"),
("57.69380,-5.128715")),
mode = "driving",
key = api_key,
units = "imperial")
我得到了我想要使用的所有数据:
results$rows[[1]]
然而,当我们为 place_c
尝试相同的坐标时遇到了麻烦,它返回 ZERO_RESULTS
;
results2 <- google_distance(origins = home,
destinations = ("57.36243,-5.104728"),
mode = "driving",
key = api_key,
units = "imperial")
这里我认为问题是坐标是半山腰,所以在这种情况下我想找到离坐标最近的路。我希望在 googleway
的 nearest_road
功能上有一些好运,但似乎无法让它工作,例如这样的事情不起作用;
df_points <- read.table(text = "lat lon
57.36243 -5.104728", header = T)
nearest_road <- google_nearestRoads(df_points, key = api_key)
谁能告诉我这里的问题是什么?或者完全提出更好的解决方案?!
非常感谢。
最佳答案
我正在研究一个即将在 github 上可用的包(称为 spaceheater)中的这个问题。与此同时:
我会从 geofabrik 下载与您合作的国家/地区的 Open Street Maps shapefile。例如尼日利亚:http://download.geofabrik.de/africa/nigeria.html
根据 monkeytennis 的建议进行编辑(谢谢!):
library(sp)
library(rgdal)
library(raster)
library(googleway)
library(geosphere)
library(foreach)
###I did Nigeria because I have it in my file downloaded, you would use UK###
roadshp <- readOGR(dsn="nigeria-latest-free.shp",
layer="gis.osm_roads_free_1")
#Isolate primary roads (or secondary and tertiary) if you wish#
roads <- roadshp[roadshp$fclass %in% c("primary", "secondary", "tertiary"),]
#Use SpatialPoints for your gps coords
location <- c("place_a", "place_b", "place_c")
latitude <- c(8.641, 10.892, 11.797)
longitude <- c(6.0046, 11.146, 5.477)
df <- data.frame(location, latitude, longitude)
coordinates(df)=~longitude+latitude
sp1 <- SpatialPoints(df)
proj4string(sp1)=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
+towgs84=0,0,0")
clodist <- dist2Line(sp1, roads)
df <- as.data.frame(df)
df$clodist <- clodist[,c("distance")]
df$lat <- clodist[,c("lat")]
df$lon <- clodist[,c("lon")]
iters <- nrow(df)
origin <- as.character("9.056, 7.497")
gc1 <- data.frame(round(df[,c("lat")],3), round(df[,c("lon")],3))
colnames(gc1) <- c("lat","lon")
df$lat <- as.character(gc1$lat)
df$lon <- as.character(gc1$lon)
gt2 <- paste(df[,c("lat")], df[,c("lon")], sep=",")
results <- google_distance(origins =origin, destinations= gt2,
mode="driving",
key="Your API Key Here")
results <-unlist(results)
results <- as.data.frame(results)
ttt <- head(results,-1)
ttt <- ttt[-c(iters+1), ]
m1 <- matrix(ttt, ncol=iters, byrow=TRUE)
distance <- as.data.frame(m1)
rownames(distance) <- c("Address", "DistanceKM",
"DistanceM","TimeTextLow","TimeSecondsLow","TimeTextHigh","TimeSecondsHigh",
"Status")
关于r - 如何使用 R 找到到单对纬度/经度坐标的最近道路?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48175907/
所以:我有以下函数,改编自在线找到的公式,它采用两个纬度/经度坐标并计算它们之间的距离(以英里为单位)(沿着球形地球): public static double distance (double l
我有一个给定点(经度、纬度),我想获取给定点 5 英里半径范围内的所有点范围? 最佳答案 我只是在这里猜测,但我认为您需要找到一种不同的方法。如果您尝试使用 Foursquare、Google map
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
我找到了一些代码,用于将纬度/经度转换为给定图像上的像素,反之亦然。我将其移植到 JavaScript,但在纬度上得到了不正确的返回值。我测试了原始的、未修改的代码,它给出了同样的不准确之处。下面是带
我正在考虑使用 rChart/LeafLet 为我所在县的房屋销售创建一个 Shiny 的应用程序。在任何给定时间,都有数百套房屋出售。想要为所有人绘制街道地址到地理位置(纬度/经度)的 map 并将
是否有任何方法(任何 API 或任何 URL)仅通过传递区号(邮政编码)来查找经纬度? 最佳答案 Google map 地理编码器将仅根据邮政编码进行搜索。 这是一个例子:(和一个 fiddle 来查
我正在尝试使用 openlayers 中的方形多边形来获取边界框。我需要从框中获取 North、South、West 和 East 值。现在我正在使用: var topleft = vectors.f
下面的代码将在 map 中添加一个标记并在警报中显示其纬度/经度。 var note = document.getElementById('note'); var datepick = documen
如何将地址或城市转换为纬度/经度?我可以从哪些商业机构“租用”这项服务?这将用于具有全时互联网访问的 Windows PC 上的商业桌面应用程序。 最佳答案 Google 有一个地理编码 API,对于
我的地理位置字符串为 25°9'37"N 55°13'28"E。使用 JavaScript Regex 我想从上面的字符串中提取 Lat 和 Lng。谢谢。 最佳答案 Your first row c
考虑在 map 上有一个圆,其中心为 GLatLng (A),半径 (r) 以米为单位。 如何计算B位置的GLatLng?假设r平行于赤道。 使用 GLatLng.distanceFrom() 方法在
我有 CLLocation 对象,其中包含用户的当前位置,并且对于可以倾斜的矩形的每个角,我有 4 个纬度/经度对。现在我想检查 CLLocation 坐标是否在该矩形内。 以下是矩形的坐标 #def
我正在尝试使用以下代码获取用户当前的纬度/经度: LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SER
我在这里不合时宜,所以如果我没有正确/清楚地问这个问题,请原谅我。 我有一张用户表,每个用户都有经纬度。 我收到一个联邦机构的查询,它提供了这样的多边形或圆形: 38.47,-120.14 38.34
我刚刚开始使用 python 的 BeautifulSoup 包进行抓取。在我的代码中,我得到以下汤对象 >>> soupObj [u'$(function(){SEAT.PG.initDialog(
目前我想通过JDBC将我的GPS经纬度发送到MYSQL。为了检索 GPS 纬度,我使用了下面的代码,并且在 GPSTracker 类中有 GPS 跟踪器代码。这将在任何时候按下按钮来 toast 纬度
我想根据输入的源地址和目标地址画一条路线。我需要根据地址获取纬度/日志才能在 android 中绘制 map 。那么我如何根据输入的地址获取纬度/日志。 Geocoder geoCoder = ne
如何在 android map 上显示我从服务器收到的纬度和经度。我实现了 google map V2 但不知道如何在 map 上显示 gps 坐标。经过大量研究,我来到这里,但无法找到一个合理的解决
我的 Controller 中有以下代码。 .controller('MapCtrl', ['$scope', function initialize() {
我也四处搜寻,但没有发现任何真正有帮助的东西。情况如下: 假设我对城市和天气预报有一个简单的关系。我们可以与纬度和经度联系起来,因此我们可以得到以下结果: 城市表: cityId | name
我是一名优秀的程序员,十分优秀!