here.com R-df作为结果的等值线布线?

h7appiyu  于 2023-05-26  发布在  其他
关注(0)|答案(1)|浏览(103)

这与免费增值帐户上的here.comdeveloper有关。
问题:创建一个空的数据框或唯一的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”)>

juzqafwq

juzqafwq1#

错误不在HERE库上,而是在用于保存返回的等值线的数据框的数据结构上。

> for (i in 1:nrow(df)){
+   result <- isoline(
+     st_sf(df[i,]),  
+     range = (5*60),                 
+     range_type = "time",            
+     routing_mode = "fast",          
+     transport_mode = "car",         
+     aggregate = TRUE,
+     traffic = TRUE              
+   )
+   print(result)
+ }
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.5571 ymin: 46.52435 xmax: -75.41428 ymax: 46.58615
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:07 2023-05-22 17:44:07   300 POLYGON ((-75.55676 46.5641...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.8963 ymin: 45.38796 xmax: -75.78884 ymax: 45.44014
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:08 2023-05-22 17:44:08   300 POLYGON ((-75.89626 45.4259...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.8448 ymin: 45.39791 xmax: -75.78129 ymax: 45.44151
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:08 2023-05-22 17:44:08   300 POLYGON ((-75.84476 45.4105...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.86815 ymin: 45.37937 xmax: -75.77717 ymax: 45.4192
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:09 2023-05-22 17:44:09   300 POLYGON ((-75.86811 45.4088...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.82935 ymin: 45.42332 xmax: -75.74078 ymax: 45.45971
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:09 2023-05-22 17:44:09   300 POLYGON ((-75.82931 45.4414...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.80154 ymin: 45.39757 xmax: -75.72601 ymax: 45.4525
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:09 2023-05-22 17:44:09   300 POLYGON ((-75.80146 45.4262...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.81459 ymin: 45.44632 xmax: -75.73013 ymax: 45.51773
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:09 2023-05-22 17:44:09   300 POLYGON ((-75.81425 45.5177...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.78438 ymin: 45.43327 xmax: -75.69855 ymax: 45.48477
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:10 2023-05-22 17:44:10   300 POLYGON ((-75.78429 45.4736...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.78438 ymin: 45.42091 xmax: -75.68687 ymax: 45.47996
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:10 2023-05-22 17:44:10   300 POLYGON ((-75.78429 45.4447...
Simple feature collection with 1 feature and 5 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -75.7679 ymin: 45.40924 xmax: -75.69374 ymax: 45.47104
Geodetic CRS:  WGS 84
  id rank           departure             arrival range                       geometry
1 NA    1 2023-05-22 17:39:10 2023-05-22 17:44:10   300 POLYGON ((-75.76756 45.4154...

你甚至可以跳过for循环,因为hereR可以批量处理数据,只要记住将聚合值设置为FALSE:

result <- isoline(
    st_sf(df), # not need to loop through the data frame
    range = (5 * 60),
    range_type = "time",
    routing_mode = "fast",
    transport_mode = "car",
    aggregate = FALSE, # when aggregate is off it returns 10 results
    traffic = TRUE
)
# if in need, convert the feature data back to data frame
as.data.frame(result)

相关问题