这与免费增值帐户上的here.com和developer有关。
问题:创建一个空的数据框或唯一的ID,而不是给我一个完整的数据表与多边形每行基于等值线路由基于时间。
下面这篇文章可以指导任何人解决这个问题的方法吗?通过this example获得的代码
1.我的输入质心为df +我的函数
1.糟糕的结果,但一个接一个地完美运作
set_key(api_key = "12345") # not it
df <- structure(list(address = c("853, Boul. Albiny-Paquette", "790 Boul. Wilfrid-Lavigne",
"495 Vanier", "209, Chemin Aylmer", "585 Boul. Des Grives", "265 Boul. Saint-Raymond",
"725 Boul. Des Hautes-Plaines", "9 Rue Daniel-Johnson", "480 Boul. St-Joseph",
"15 Rue Eddy"), city = c("Mont-Laurier", "Gatineau", "Gatineau",
"Gatineau", "Gatineau", "Gatineau", "Gatineau", "Gatineau", "Gatineau",
"Gatineau"), state = c("QC", "QC", "QC", "QC", "QC", "QC", "QC",
"QC", "QC", "QC"), zip_code = c("J9L 1L6", "J9J 2S5", "J9J 1Z4",
"J9H 1A3", "J9A 3W9", "J9A 3G6", "J8Z 2W9", "J8Z 1X6", "J8Y 3Y7",
"J8X 4B3"), county = c("Antoine-Labelle", "Communauté-Urbaine-de-l'Outaouais",
"Communauté-Urbaine-de-l'Outaouais", "Communauté-Urbaine-de-l'Outaouais",
"Communauté-Urbaine-de-l'Outaouais", "Communauté-Urbaine-de-l'Outaouais",
"Communauté-Urbaine-de-l'Outaouais", "Communauté-Urbaine-de-l'Outaouais",
"Communauté-Urbaine-de-l'Outaouais", "Communauté-Urbaine-de-l'Outaouais"
), country = c("Canada", "Canada", "Canada", "Canada", "Canada",
"Canada", "Canada", "Canada", "Canada", "Canada"), geometry = structure(list(
structure(c(-75.4880697, 46.5512158), class = c("XY", "POINT",
"sfg")), structure(c(-75.8386017, 45.4110993), class = c("XY",
"POINT", "sfg")), structure(c(-75.8070987999999, 45.4161897
), class = c("XY", "POINT", "sfg")), structure(c(-75.8322898,
45.3959535), class = c("XY", "POINT", "sfg")), structure(c(-75.7859960999999,
45.4435358), class = c("XY", "POINT", "sfg")), structure(c(-75.7611743,
45.4269774), class = c("XY", "POINT", "sfg")), structure(c(-75.7719339,
45.474538), class = c("XY", "POINT", "sfg")), structure(c(-75.7475764,
45.4625748), class = c("XY", "POINT", "sfg")), structure(c(-75.7323619,
45.4464210999999), class = c("XY", "POINT", "sfg")), structure(c(-75.7202519,
45.4251762), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT",
"sfc"), precision = 0, bbox = structure(c(xmin = -75.8386017,
ymin = 45.3959535, xmax = -75.4880697, ymax = 46.5512158), class = "bbox"), crs = structure(list(
input = "WGS84", wkt = "GEOGCRS[\"WGS 84\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n ID[\"EPSG\",4326]]"), class = "crs"), n_empty = 0L)), sf_column = "geometry", agr = structure(c(store_number = NA_integer_,
store_type = NA_integer_, address = NA_integer_, city = NA_integer_,
state = NA_integer_, zip_code = NA_integer_, phone_number = NA_integer_,
store_hours = NA_integer_, services = NA_integer_, website_address = NA_integer_,
latitude = NA_integer_, longitude = NA_integer_, country_code = NA_integer_,
county = NA_integer_, country = NA_integer_, geo_accuracy = NA_integer_
), class = "factor", levels = c("constant", "aggregate", "identity"
)), row.names = c(NA, 10L), class = "data.frame")
iso <- as.data.frame(c())
for (i in 1:nrow(df)){
iso[i,] <- isoline(
st_sf(df[i,]),
range = (5*60),
range_type = "time",
routing_mode = "fast",
transport_mode = "car",
aggregate = TRUE,
traffic = TRUE
)
print(iso)
iso$store_number[i] <- df$store_number[i]
}
st_write(obj = iso, dsn = "5min_isoline.shp", factorsAsCharacter = T, delete_layer = T)
错误:
<[1] id<0 rows>(or 0-length row.names)Error in $<-.data.frame
(*tmp*
,“zip”,value =“J9L 1L6”):replacement有1行,data有0另外:警告消息:1:在[<-.data.frame
(*tmp*
,i)中,值=列表(id = NA,秩= 1,:替换元素% 1有% 1行可替换% 0行% 2:在[<-.data.frame
(*tmp*
,i)中,value = list(id = NA,rank = 1,:替换元素% 2具有1行以替换0行% 3:在[<-.data.frame
(*tmp*
,i)中,value = list(id = NA,rank = 1,:替换元素3具有1行以替换0行4:在[<-.data.frame
(*tmp*
,i)中,value = list(id = NA,rank = 1,:替换元素4具有1行以替换0行5:在[<-.data.frame
(*tmp*
,i,value = list(id = NA,rank = 1,:替换元素5具有1行以替换0行6:在[<-.data.frame
(*tmp*
,i)中,value = list(id = NA,rank = 1,:替换元素6具有1行以替换0行7:在[<-.data.frame
(*tmp*
,i)中,value = list(id = NA,rank = 1,:提供了6个变量来替换1个变量>
结果:(<structure(list(id = logical(0)),row.names = integer(0),class =“data.frame”)>
1条答案
按热度按时间juzqafwq1#
错误不在HERE库上,而是在用于保存返回的等值线的数据框的数据结构上。
你甚至可以跳过for循环,因为hereR可以批量处理数据,只要记住将聚合值设置为FALSE: