如何将坐标 Y、X 交换为列表中的坐标 X、Y?

How do I swap the coordinates Y,X to coordinates X,Y in a list?

如何在包含多个列表的列表中将坐标从 Y、X 交换到 X、Y? (见下面的 geojson)

目前,我检索了一个包含立交桥涡轮坐标列表的 geojson 文件,我想使用我的 geojson 文件中的坐标列表使用 folium 折线绘制路径。但是,我注意到 geojson 文件中的坐标是经度、纬度而不是纬度、经度。因此折线没有出现在我的地图上。

下面是我的代码,我试过交换坐标。但是,坐标仍然没有被交换

代码

with open('BusPath/BusService.geojson') as access_json:
        read_content = json.load(access_json)
        bus_access = read_content['features']

    for bus_data in bus_access:
        busName = bus_data['properties']
        if busPath == busName['name']:
            busCoord = [v[::-1] for v in bus_data['geometry']['coordinates']]
            print(busCoord)

folium.PolyLine(busCoord, opacity=1, color='red').add_to(self.m)
data = io.BytesIO()
self.m.save(data, close_file=False)
self.view.setHtml(data.getvalue().decode())


#Output of print(busCoord)
[[[103.9060467, 1.3991345], [103.9058912, 1.3992605], [103.9056954, 1.3994], [103.9053896, 1.3996064], [103.9052668, 1.3996311], [103.9051645, 1.399626], [103.905072, 1.3995938], [103.9049717, 1.3995537], [103.9046416, 1.3988584], [103.9044522, 1.3984454], [103.9042792, 1.3980713]]]

JSON FILE 如您所见,有多个包含路径坐标的列表,包含在主列表调用中 "coordinates"

"geometry": {
        "type": "MultiLineString",
        "coordinates": [
          [
            [
              103.9060467,
              1.3991345
            ],
            [
              103.9058912,
              1.3992605
            ],
            [
              103.9056954,
              1.3994
            ],
            [
              103.9053896,
              1.3996064
            ],
            [
              103.9052668,
              1.3996311
            ],
            [
              103.9051645,
              1.399626
            ],
            [
              103.905072,
              1.3995938
            ],
            [
              103.9049717,
              1.3995537
            ],
            [
              103.9046416,
              1.3988584
            ],
            [
              103.9044522,
              1.3984454
            ],
            [
              103.9042792,
              1.3980713
            ],
            [
              103.9041011,
              1.3977284
            ],
            [
              103.9040748,
              1.3975609
            ],
            [
              103.9040403,
              1.3974097
            ],
            [
              103.9040419,
              1.3973301
            ]
          ],
          [
            [
              103.910618,
              1.3954313
            ],
            [
              103.9096382,
              1.3962145
            ],
            [
              103.9084619,
              1.3971647
            ],
            [
              103.9079136,
              1.3976289
            ],
            [
              103.9077352,
              1.3977763
            ],
            [
              103.9073965,
              1.3980253
            ],
            [
              103.9072047,
              1.398188
            ],
            [
              103.9071445,
              1.3982345
            ],
            [
              103.9068999,
              1.3984727
            ]
          ],
          [
            [
              103.9023155,
              1.4034919
            ],
            [
              103.9022324,
              1.4036635
            ],
            [
              103.9022109,
              1.4037547
            ],
            [
              103.9022109,
              1.403819
            ],
            [
              103.9024009,
              1.4041775
            ],
            [
              103.9026193,
              1.4045984
            ],
            [
              103.9026671,
              1.4046228
            ],
            [
              103.9028788,
              1.4044948
            ],
            [
              103.9023155,
              1.4034919
            ],
            [
              103.9025304,
              1.403368
            ],
            [
              103.9026886,
              1.4032743
            ],
            [
              103.9029776,
              1.4031102
            ],
            [
              103.902983,
              1.4031189
            ],
            [
              103.9033585,
              1.4037261
            ],
            [
              103.9034812,
              1.4039168
            ],
            [
              103.9036107,
              1.4041337
            ],
            [
              103.9037633,
              1.4043804
            ],
            [
              103.9038275,
              1.4044809
            ],
            [
              103.9039067,
              1.4044437
            ],
            [
              103.904112,
              1.4043433
            ],
            [
              103.9047004,
              1.4040091
            ],
            [
              103.9049444,
              1.4038705
            ],
            [
              103.9052092,
              1.4036879
            ],
            [
              103.9055394,
              1.4034604
            ],
            [
              103.9056471,
              1.4033926
            ],
            [
              103.9059194,
              1.4032213
            ],
            [
              103.9062514,
              1.4029677
            ],
            [
              103.9063671,
              1.4028932
            ],
            [
              103.9065893,
              1.4027593
            ],
            [
              103.9071575,
              1.4023613
            ],
            [
              103.9072297,
              1.4023108
            ],
            [
              103.9077716,
              1.40193
            ],
            [
              103.9083671,
              1.4014838
            ],
            [
              103.9085667,
              1.4013343
            ]
          ]
        ]
      }

您的坐标列表太深,而不是:

busCoord = [v[::-1] for v in bus_data['geometry']['coordinates']]

你应该试过:

busCoord = [v[::-1] for v in bus_data['geometry']['coordinates'][0]]

获取实际坐标。您当前的代码正在反转只有 1 个元素的最外层列表——坐标列表。