将 GeoJSON 特征集合转为 GeoJSON 列表

Turn GeoJSON Feature Collection Into GeoJSON List

我使用 geopandas Python 库创建了一个观测特征集合。我想将这些功能传递到 paquo 库中,具体到 load_geojson 函数。 documentation 说这需要一个 geojson 列表。如何使用 Python 将我的要素集合转换为地理 json 列表?

我正在使用的 geojson 要素集合的一个小(或更小)示例。这是当前存储在一个名为 detections.geojson 的文件中,所以我想加载它,将其转换为 json 列表,然后将其传递给 paquo 函数。

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {"detection_probability": 0.87956196069717407},
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [28.142841339111328, 20.0],
                        [27.9241943359375, 21.974044799804688],
                        [27.838161468505859, 24.075099945068359],
                        [27.054649353027344, 26.05012321472168],
                        [25.991479873657227, 27.991479873657227],
                        [24.507223129272461, 29.738746643066406],
                        [22.665504455566406, 31.263526916503906],
                        [20.393911361694336, 32.035003662109375],
                        [18.0, 32.760498046875],
                        [15.599363327026367, 32.068817138671875],
                        [13.329315185546875, 31.276031494140625],
                        [11.544240951538086, 29.661724090576172],
                        [10.210344314575195, 27.789655685424805],
                        [9.085145950317383, 25.956714630126953],
                        [8.081482887268066, 24.108383178710938],
                        [7.748076438903809, 22.039234161376953],
                        [7.085014343261719, 20.0],
                        [7.310750961303711, 17.873775482177734],
                        [7.473111152648926, 15.639619827270508],
                        [8.647182464599609, 13.750646591186523],
                        [10.066623687744141, 12.066623687744141],
                        [11.863254547119141, 10.81571102142334],
                        [13.732873916625977, 9.698246955871582],
                        [15.904006958007812, 9.462733268737793],
                        [18.0, 9.074560165405273],
                        [20.057140350341797, 9.658054351806641],
                        [22.142807006835938, 9.998381614685059],
                        [23.879213333129883, 11.20113468170166],
                        [25.340042114257812, 12.659957885742188],
                        [26.492183685302734, 14.325704574584961],
                        [27.511556625366211, 16.060184478759766],
                        [27.725831985473633, 18.065412521362305],
                        [28.142841339111328, 20.0],
                    ]
                ],
            },
        },
        {
            "type": "Feature",
            "properties": {"detection_probability": 0.86374783515930176},
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [38.809555053710938, 80.0],
                        [38.455738067626953, 81.681953430175781],
                        [38.047962188720703, 83.333572387695312],
                        [37.099494934082031, 84.743728637695312],
                        [35.913818359375, 85.913818359375],
                        [34.750617980957031, 87.10980224609375],
                        [33.307960510253906, 87.986129760742188],
                        [31.675350189208984, 88.42254638671875],
                        [30.0, 89.093971252441406],
                        [28.252479553222656, 88.785377502441406],
                        [26.422569274902344, 88.636680603027344],
                        [24.8177490234375, 87.755790710449219],
                        [23.439481735229492, 86.560516357421875],
                        [22.210916519165039, 85.204498291015625],
                        [21.157306671142578, 83.662765502929688],
                        [20.90095329284668, 81.809913635253906],
                        [20.468769073486328, 80.0],
                        [20.850358963012695, 78.180023193359375],
                        [20.958005905151367, 76.254684448242188],
                        [21.764236450195312, 74.497039794921875],
                        [22.845193862915039, 72.845191955566406],
                        [24.237794876098633, 71.376251220703125],
                        [25.900157928466797, 70.102104187011719],
                        [28.002780914306641, 69.959304809570312],
                        [30.0, 69.636734008789062],
                        [31.906478881835938, 70.415481567382812],
                        [33.741344451904297, 70.967597961425781],
                        [35.21875, 72.189590454101562],
                        [36.442733764648438, 73.557266235351562],
                        [37.461330413818359, 75.014495849609375],
                        [38.330062866210938, 76.549575805664062],
                        [38.496204376220703, 78.30999755859375],
                        [38.809555053710938, 80.0],
                    ]
                ],
            },
        },
    ],
}

paquo.hierarchy.QuPathPathObjectHierarchy.load_geojson 函数需要一个字典列表,每个字典都必须有一个“几何”键,对应的值可由 shapely.geometry.shape 解析。所以以下应该有效:

load_geojson(detections["features"])