我有一个需要提交给API的geojson文件。我正在修改一个预先存在的powershell脚本来执行这个查询,但是在将geojson正确解析到要传递给API的查询字符串时遇到了问题。Powershell根本不是我的语言,但我已经能够让它读懂geojson。我的代码中的print语句如下所示:
$inputjson = Get-Content -Raw -Path C:/path/to/file.geojson | ConvertFrom-Json
Foreach ($feature in $inputjson.features){
$gjson = $feature.geometry
Write-Host $gjson
我的输出结果是:
@{type=Polygon; coordinates=System.Object[]}
我已经尝试过ToString(),或者甚至将$gjson转换为string,以强制读取它在文件中出现的内容。在python中,我可以很容易地做到这一点,但这是一个复杂的脚本,我没有时间从头开始重写。如何正确地将其转换为字符串?在Powershell的json子字段中'@‘装饰符到底暗示了什么?
发布于 2018-02-10 19:47:34
关键是GeoJSON
不是平面对象。这意味着您必须(递归地)迭代每个嵌入的对象,以获得每个包含的子项:
$inputjson = Get-Content -Raw -Path C:/path/to/file.geojson | ConvertFrom-Json
Foreach ($feature in $inputjson.features){
$gjson = $feature.geometry
Write-Host "Type = " $gjson.Type
Foreach ($coordinate in $coordinates){
Write-Host "coordinate = " $coordinate
也许这会对你有帮助:$inputjson | Flatten
,看看:https://stackoverflow.com/a/46081131/1701026
发布于 2018-02-10 02:07:56
@{key=value}
是一个hashtable
目前还不清楚你想要实现什么,也许你想将ypur几何图形重新转换为json?如果是这样
$feature.geometry | ConvertTo-Json
就是你需要的
https://stackoverflow.com/questions/48709832
复制相似问题