【问题标题】:Invalid parameter when using rgrass7 with GRASS 7.2.0. and R 3.3.2将 rgrass7 与 GRASS 7.2.0 一起使用时参数无效。和 R 3.3.2
【发布时间】:2017-02-27 20:31:08
【问题描述】:

我正在尝试使用带有rgrass7 库的 R 3.3.2 在 GRASS 7.2.0 中处理多个操作。

我的主要目标是使用 GRASS 网络工具计算多个位置之间的道路网络距离。

我的问题是我的数据库中的位置是由个人组织的,我想计算嵌套在个人中的位置的网络距离,而不是数据库中的所有位置。

这是我的数据结构示例

ID | Locations
--------------
A  |    1
A  |    2
A  |    3
B  |    4
B  |    5

我能够在 GRASS 中编写这个脚本来计算一个 ID 的所有距离。我省略了加载位置 (my_locations) 和道路 (street_vector) 图层并设置区域的脚本开头。

# Select locations for ID == 'A'
v.extract --overwrite --verbose input=my_locations output=my_locations_sub where="ID='A'"

# Prepare network: connect my_locations to street vector map 
v.net input=street_vectors points=my_locations_sub output=network operation=connect thresh=500

## The option operation=connect allows to create the links between lines and      
## points and to create a single vector map containing lines, nodes and 
## links. 

## The parameter thresh=500 means that only points within the distance of 
## 500 metres are connected to the lines.

# verify result
v.category input=network option=report

# shortest path between all points
v.net.allpairs input=network out=network_dist --overwrite

# output results
v.db.select network_dist

接下来,我使用rgrass7包来执行GRASS7.2.0。来自 R 3.3.2 的命令。 目标是使用for 循环通过一个脚本生成我所有的网络距离表。

这是我的代码:

library(rgrass7)

IDs <- read.table("./path/to/my/ID_list.txt", header = TRUE)

# initialisation of GRASS7
initGRASS(gisBase = "C:/Program Files/GRASS GIS 7.2.0",
          gisDbase = "C:/Users/Me/GRASSdata",
          location = "My_project", mapset = "R", override = TRUE)   

# For loop to calculate road network distance by IDs
for (i in 1: length(IDs)){
  ID <- IDs[i]
  condition <- paste0("ID=\'", as.character(ID), "\'")

  execGRASS('v.extract', parameters = list(input='my_locations', 
             output='my_locations_sub', where=condition))

  execGRASS('v.net', parameters = list(input = street_vectors', 
             points = 'my_locations_sub', output = 'network', 
             operation = 'connect', thresh = 500))

  execGRASS('v.net.allpairs', parameters = list(input='network', 
                                                out='netword_dist'), 
             flags = 'overwrite')

  # Set the path to write files
  path <- paste0("./data/", ID, ".csv")

  # Write file
  execGRASS('db.out.ogr', parameters = list(input = 'network_dist', 
                                            output = path))

}

但是当我使用 GRASS 中的 v.net 执行 execGRASS 函数时,出现以下错误:

 Error in doGRASS(cmd, flags = flags, ..., parameters = parameters, 
 echoCmd = echoCmd,  : 
       Invalid parameter name: thresh

就像 doGRASS 无法将 thresh 识别为有效的 v.net 参数。我有点卡在这里,所以如果有人知道我做错了什么,那真的很有帮助。

【问题讨论】:

    标签: r network-analysis grass


    【解决方案1】:

    我才意识到我在复制代码时犯了一个错误。我在以下部分中错过了 input = 'street_vectors' 中的 ':

    execGRASS('v.net', parameters = list(input = 'street_vectors', 
             points = 'my_locations_sub', output = 'network', 
             operation = 'connect', thresh = 500))
    

    【讨论】:

      猜你喜欢
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-30
      • 1970-01-01
      • 1970-01-01
      • 2018-06-23
      相关资源
      最近更新 更多