以北京市东城区的边界坐标为例。
a = [[116.443452, 39.872222], [116.421369, 39.872791], [116.41361, 39.870513], [116.41658, 39.866868], [116.413485, 39.860081], [116.3955, 39.858616], [116.394998, 39.86262], [116.387951, 39.867112], [116.381531, 39.866119], [116.381217, 39.871164], [116.399202, 39.87214], [116.397801, 39.898529], [116.395918, 39.900156], [116.395542, 39.908077], [116.392656, 39.907995], [116.392384, 39.92229], [116.399515, 39.923509], [116.39732, 39.928404], [116.396504, 39.940028], [116.394204, 39.942336], [116.393597, 39.957095], [116.386403, 39.956737], [116.387533, 39.961109], [116.38954, 39.963043], [116.39734, 39.96327], [116.407859, 39.962035], [116.407504, 39.974028], [116.411205, 39.971314], [116.411247, 39.965042], [116.41407, 39.961987], [116.42507, 39.962182], [116.425133, 39.959435], [116.430445, 39.959565], [116.42896, 39.957062], [116.430173, 39.950122], [116.435966, 39.949277], [116.435317, 39.952235], [116.442239, 39.9497], [116.440545, 39.94536], [116.446715, 39.946091], [116.444561, 39.941198], [116.443766, 39.92868], [116.434334, 39.92868], [116.4363, 39.901912], [116.448555, 39.903214], [116.447133, 39.894235], [116.450876, 39.890135], [116.444121, 39.88994], [116.445648, 39.879381], [116.443452, 39.872222]] #东城区边界坐标 DongCheng = [] for x, y in a: DongCheng.append({'x': float(x), 'y': float(y)}) # 将列表中的经纬度转换成字典的形式,存入列表DongCheng filename = 'DongChengQu.json' with open(filename, 'w') as fp: json.dump(DongCheng, fp)
输出json文件