如何将 API 响应转换为 R 中的多边形对象? R 中的 Graphhopper API - 等时线
How do I convert an API response to a Polygon object in R? Graphhopper API in R - Isochrones
我是 API 和 R 的新手,我想知道如何使用这个 GraphHopper API。(https://graphhopper.com/api/1/docs/isochrone/https://graphhopper.com/api/1/docs/isochrone/)
上面的页面是这样的:
curl "https://graphhopper.com/api/1/isochrone?point=51.131108,12.414551&key=[YOUR_KEY]"
有没有办法将响应转换为多边形对象?
到目前为止我到了这里,但我不知道如何将请求转换为多边形:
library(httr)
library(jsonlite)
a = GET("https://graphhopper.com/api/1/isochrone?point=51.131108,12.414551&key=KEY")
class(a)
a$status_code
这有效..
library(RJSONIO)
library(sp)
library(leaflet)
## GraphHopper API
# https://graphhopper.com/api/1/docs/isochrone/
#Request
a <-fromJSON("https://graphhopper.com/api/1/isochrone?point=51.131108,12.414551&key=[GET YOUR OWN KEY]")
#Response
x = a$polygons$geometry$coordinates
#Response Manipulation
x = data.frame(unlist(x))
m = nrow(x)/2
x1 = x[1:m,1]
x2 = x[(1+m):nrow(x),1]
x0 = data.frame(cbind(x1,x2))
#Polygon plotting on Leaflet
p = Polygon(coords = x0)
leaflet()%>%
addTiles()%>%
addPolygons(data = p)
我是 API 和 R 的新手,我想知道如何使用这个 GraphHopper API。(https://graphhopper.com/api/1/docs/isochrone/https://graphhopper.com/api/1/docs/isochrone/) 上面的页面是这样的:
curl "https://graphhopper.com/api/1/isochrone?point=51.131108,12.414551&key=[YOUR_KEY]"
有没有办法将响应转换为多边形对象?
到目前为止我到了这里,但我不知道如何将请求转换为多边形:
library(httr)
library(jsonlite)
a = GET("https://graphhopper.com/api/1/isochrone?point=51.131108,12.414551&key=KEY")
class(a)
a$status_code
这有效..
library(RJSONIO)
library(sp)
library(leaflet)
## GraphHopper API
# https://graphhopper.com/api/1/docs/isochrone/
#Request
a <-fromJSON("https://graphhopper.com/api/1/isochrone?point=51.131108,12.414551&key=[GET YOUR OWN KEY]")
#Response
x = a$polygons$geometry$coordinates
#Response Manipulation
x = data.frame(unlist(x))
m = nrow(x)/2
x1 = x[1:m,1]
x2 = x[(1+m):nrow(x),1]
x0 = data.frame(cbind(x1,x2))
#Polygon plotting on Leaflet
p = Polygon(coords = x0)
leaflet()%>%
addTiles()%>%
addPolygons(data = p)