【问题标题】:How to insert variable value into JSON string for use with PDAL如何将变量值插入 JSON 字符串以与 PDAL 一起使用
【发布时间】:2019-09-15 04:52:13
【问题描述】:

我正在尝试使用 PDAL 的 Python 扩展来读取 laz 文件。

为此,我使用了此处示例的简单管道结构:https://gis.stackexchange.com/questions/303334/accessing-raw-data-from-laz-file-in-python-with-open-source-software。但是,插入“文件名:”字段的变量中包含的值对我很有用。为此,我尝试了以下方法,其中 fullFileName 是一个包含文件名称(完整路径)的 str 变量,但我收到一个错误,即不存在此类文件。我假设我的 JSON 语法有点偏离或什么的;谁能帮忙?

    pipeline="""{
    "pipeline": [
            {
                    "type": "readers.las",
                    "filename": "{fullFileName}"
                    }
            ]
    }"""

【问题讨论】:

    标签: python json pdal


    【解决方案1】:

    您可以按照以下代码:

    import json
    import pdal
    
    file = "D:/Lidar data/input.laz"
    
    pipeline={
      "pipeline": [
        {
            "type": "readers.las",
            "filename": file
        },
        {
            "type": "filters.sort",
            "dimension": "Z"
        }
      ]
    }
    
    r = pdal.Pipeline(json.dumps(pipeline))
    r.validate()
    points = r.execute()
    print(points)
    

    【讨论】:

    • 是的,在你回答之前我已经解决了这个问题,但我发现 json.dumps 命令是关键。谢谢!
    猜你喜欢
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    相关资源
    最近更新 更多