无法从 JSON 中提取多边形,st_read 中出现错误
我有一个 JSON
格式的文件 Watershed_JSON
。
headers_watershed = c('Accept-Encoding' = 'gzip',
`accept` = 'application/json',
`Authorization` = ' Token {Your API Key Here}',
`X-CSRFToken` = '1I2YxuQlHlxpxPM09qZTlT6vEuFgucuaTpFDpN56MksR6lttbWGjiQnwdamAw0NH',
`Allow` = 'GET'
)
url_1 <-paste0(URL='https://modelmywatershed.org/api/jobs/', job_ID, '/')
res_job <- GET(url=url_1,
add_headers(.headers = headers_watershed))
Watershed_char <- rawToChar(res_job$content)
Watershed_JSON <- fromJSON(Watershed_char, flatten = TRUE)
Watershed_JSON
####
$job_uuid
[1] "f684a0c7-debb-4adc-9510-908a9a7a98e5"
$status
[1] "complete"
$result
$result$input_pt
$result$input_pt$geometry
$result$input_pt$geometry$coordinates
[1] -102.48203 35.66726
$result$input_pt$geometry$type
[1] "Point"
$result$input_pt$properties
$result$input_pt$properties$DistStr_m
[1] 0
$result$input_pt$properties$Dist_moved
[1] 0
$result$input_pt$properties$ID
[1] 1
$result$input_pt$properties$Lat
[1] 35.66736
$result$input_pt$properties$Lon
[1] -102.4819
$result$input_pt$type
[1] "Feature"
$result$watershed
$result$watershed$geometry
$result$watershed$geometry$coordinates
[ reached getOption("max.print") -- omitted 2 matrix slice(s) ]
$result$watershed$geometry$type
[1] "Polygon"
$result$watershed$properties
$result$watershed$properties$Area_km2
[1] 3475.114
$result$watershed$properties$GRIDCODE
NULL
$result$watershed$type
[1] "Feature"
$error
[1] ""
$started
[1] "2022-03-01T21:23:53.343710Z"
$finished
[1] "2022-03-01T21:23:55.719275Z"
我正在尝试使用 st_read
读取我的文件,因为我想提取其中找到的polygon
shapefile。
Type <- Watershed_JSON$result$watershed$geometry$type
# "Polygon"
Coords <- Watershed_JSON$result$watershed$geometry$coordinates
Example <- st_read(dsn=Watershed_JSON, layer = Type)
但是,运行代码时,出现以下错误
Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
Expecting a single value: [extent=6].
In addition: Warning message:
In if (nchar(dsn) < 1) { :
the condition has length > 1 and only the first element will be used
I have a file Watershed_JSON
in JSON
format.
headers_watershed = c('Accept-Encoding' = 'gzip',
`accept` = 'application/json',
`Authorization` = ' Token {Your API Key Here}',
`X-CSRFToken` = '1I2YxuQlHlxpxPM09qZTlT6vEuFgucuaTpFDpN56MksR6lttbWGjiQnwdamAw0NH',
`Allow` = 'GET'
)
url_1 <-paste0(URL='https://modelmywatershed.org/api/jobs/', job_ID, '/')
res_job <- GET(url=url_1,
add_headers(.headers = headers_watershed))
Watershed_char <- rawToChar(res_job$content)
Watershed_JSON <- fromJSON(Watershed_char, flatten = TRUE)
Watershed_JSON
####
$job_uuid
[1] "f684a0c7-debb-4adc-9510-908a9a7a98e5"
$status
[1] "complete"
$result
$result$input_pt
$result$input_pt$geometry
$result$input_pt$geometry$coordinates
[1] -102.48203 35.66726
$result$input_pt$geometry$type
[1] "Point"
$result$input_pt$properties
$result$input_pt$properties$DistStr_m
[1] 0
$result$input_pt$properties$Dist_moved
[1] 0
$result$input_pt$properties$ID
[1] 1
$result$input_pt$properties$Lat
[1] 35.66736
$result$input_pt$properties$Lon
[1] -102.4819
$result$input_pt$type
[1] "Feature"
$result$watershed
$result$watershed$geometry
$result$watershed$geometry$coordinates
[ reached getOption("max.print") -- omitted 2 matrix slice(s) ]
$result$watershed$geometry$type
[1] "Polygon"
$result$watershed$properties
$result$watershed$properties$Area_km2
[1] 3475.114
$result$watershed$properties$GRIDCODE
NULL
$result$watershed$type
[1] "Feature"
$error
[1] ""
$started
[1] "2022-03-01T21:23:53.343710Z"
$finished
[1] "2022-03-01T21:23:55.719275Z"
I am trying to read the my file with st_read
as I would like to extract the polygon
shapefile found within.
Type <- Watershed_JSON$result$watershed$geometry$type
# "Polygon"
Coords <- Watershed_JSON$result$watershed$geometry$coordinates
Example <- st_read(dsn=Watershed_JSON, layer = Type)
However, when running the code, I get the following error
Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
Expecting a single value: [extent=6].
In addition: Warning message:
In if (nchar(dsn) < 1) { :
the condition has length > 1 and only the first element will be used
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论