RFC44:为ogrinfo和gdalinfo添加可解析的输出格式

作者:丹·达基·利特尔,法扎·马哈茂德

联系人:yahoo.com的danlittle,live.com的fazamhd

现状:发展。GDAL 2.0中实现的gdalinfo-json

总结

向ogrinfo和gdalinfo实用程序添加XML和JSON输出。

背景

ogrinfo和gdalinfo是非常有用的元数据收集工具。但是,它们基于文本的本地输出格式不容易被常见的外部工具解析。XML和JSON都很容易解析,添加这些输出格式将大大增加那些希望将ogrinfo和gdalinfo实用程序添加到脚本堆栈中的实用程序。

实施

在下面的github fork中可以看到一个示例实现 https://github.com/theduckylittle/gdal/blob/trunk/gdal/apps/ogrinfo.cpp

要将XML输出添加到每个实用程序中,需要将主循环“分解”为偶发块。还需要将所有诊断消息移动到STDERR,以确保STDOUT上的输出始终是可解析的。XML表示将使用内置于GDAL中的MiniXML库来构建。

为gdalinfo建议的json格式

{
    "description": "...",
    "driverShortName": "GTiff",
    "driverLongName": "GeoTIFF",
    "files": [ (if -nofl not specified)
        "../gcore/data/byte.tif",
        "../gcore/data/byte.tif.aux.xml"
    ],
    "size": [
        20,
        20
    ],
    "coordinateSystem": {
        "proj": "+proj=.......", (if -proj4 specified)
        "wkt": "PROJCS[....]"
    },
    "gcps": { (if -nogcp not specified)
        "coordinateSystem": {
            "proj": "+proj=.......", (if -proj4 specified)
            "wkt": "PROJCS[....]"
        },
        "gcpList": [
            {
                "id": "1",
                "info": "a",
                "pixel": 0.5,
                "line": 0.5,
                "X": 0.0,
                "Y": 0.0,
                "Z": 0.0
            },
            {
                "id": "2",
                "info": "b",
                .
                .
                .
            }
        ]
    },
    "geoTransform": [
        440720.000000000000000,
        60.000000000000000,
        0.0,
        3751320.000000000000000,
        0.0,
        -60.000000000000000
    ],
    "cornerCoordinates":{
      "upperLeft":[
        440720.0,
        3751320.0
      ],
      "lowerLeft":[
        440720.0,
        3750120.0
      ],
      "upperRight":[
        441920.0,
        3751320.0
      ],
      "lowerRight":[
        441920.0,
        3750120.0
      ],
      "center":[
        441320.0,
        3750720.0
      ]
    },
    "wgs84Extent":{
      "type":"Polygon",
      "coordinates":[
      [
        [
          -117.642054,
          33.9023677
        ],
        [
          -117.6419729,
          33.8915454
        ],
        [
          -117.6290752,
          33.9024346
        ],
        [
          -117.6289957,
          33.8916123
        ],
        [
          -117.642054,
          33.9023677
        ]
       ]
      ]
    },
    "rat": { (if -norat not specified)
        "row0Min": 40918,
        "binSize": 1,
        "fieldDefn": [
            {
                "index": 0,
                "name": "Histogram",
                "type": "integer",
                "usage": "PixelCount"
            },
            {
                "index": 1,
                "name": "fieldName2",
                "type": 2,
                "usage": 2
            },
        ],
        "rows": [
            {
                "index": 0,
                "f": [
                    1,
                    4
                ]
            },
            {
                "index": 1,
                "f": [
                    5,
                    4
                ]
            },
            .
            .
            .
        ]
    },
    "metadata": { (if -nomd not specified)
        "": {
            "key1": "value1"
        },
        "IMAGE_STRUCTURE": {
            "key1": "value1"
        },
        "OTHER_DOMAIN": {
            "key1": "value1"
        },
    },
    "cornerCoordinates": {
        "upperLeft": [
            440720.000,
            3751320.000
        ],
        "lowerLeft": [
            440720.000,
            3750120.000
        ],
        "upperRight": [
            441920.000,
            3751320.000
        ],
        "lowerRight": [
            441920.000,
            3750120.000
        ],
        "center": [
            441320.000,
            3750720.000
        ]
    },
    "bands": [
        {
            "description": "...",
            "band": 1,
            "block": [
                20,
                20
            ],
            "type": "Byte",
            "colorInterp": "Gray",
            "min": 74.000,
            "max": 255.000,

            "computedMin": 74.000, (if -mm specified)
            "computedMax": 255.000,

            "minimum": 74.000, (if -stats specified)
            "maximum": 255.000,
            "mean": 126.765,
            "stdDev": 22.928,

            "unit": "....",
            "offset": X,
            "scale": X,
            "noDataValue": X,
            "overviews": [
                {
                    "size": [
                        400,
                        400 ],
                    "checksum": X (if -checksum specified)
                },
                {
                    "size": [
                        200,
                        200 ],
                    "checksum": X (if -checksum specified)
                }
            ],
            "mask": {
                "flags": [
                    "PER_DATASET",
                    "ALPHA"
                ],
                "overviews": [
                    {
                        "size": [
                            400,
                            400 ]
                    },
                    {
                        "size": [
                            200,
                            200 ],
                    }
                ]
            },
            "metadata": { (if -nomd not specified)
                "__default__": {
                    "key1": "value1"
                },
                "IMAGE_STRUCTURE": {
                    "key1": "value1"
                },
                "OTHER_DOMAIN": {
                    "key1": "value1"
                },
            },
            "histogram": { (if -hist specified)
                "count": 25,
                "min": -0.5,
                "max": 255.5,
                "buckets": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
            },
            "checksum": 4672, (if -checksum specified)
            "colorTable": { (if -noct not specified)
                "palette": "RGB",
                "count": 6,
                "entries": [
                    [255,255,255,255],
                    [255,255,208,255],
                    [255,255,204,255],
                    [153,204,255,255],
                    [0,153,255,255],
                    [102,102,102,255]
                ]
            }
        },
        {
            "band": 2,
            "block": [
                20,
                20
            ],
            .
            .
            .
        }
    ]
}

受影响的驱动程序

没有。

受影响的公用事业

gdalinfo

  • 添加“-xml”输出选项。

  • 添加“-json”输出选项。

ogrinfo

  • 添加“-xml”输出选项。

  • 添加“-json”输出选项。

向后兼容性

这种变化对C API/ABI和C++ +API/ABI级别的向后兼容性没有影响。默认输出将保持不变。新的XML输出将只影响在命令行上指定“-XML”或“-json”的用户。

测试

Python自动测试套件将被扩展以测试新的XML/JSON输出,现有的测试将被修改以检查STDERR的诊断消息。

车票

没有票。

投票历史

提出。