You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将GeoJSON经度从-180~180转0~360以在Python的Folium中正确绘图?

经度从-180180转换为0360的最简Python实现

你的思路没错——负经度加360就能转到0~360坐标系,用Python实现的最简方法如下:

核心逻辑

直接对每个经度值取模360(longitude % 360),这个操作比单纯加360更通用:不管原经度是正还是负,都能自动转换到0~360的范围(比如-77.5取模后是282.5,370取模后是10)。

完整代码示例

import json

# 替换成你的GeoJSON数据(也可以从文件读取)
geojson_data = {
  "type": "Polygon",
  "coordinates": [
    [
      [-77.52046966552734, 34.43336486816406],
      [-77.44927978515625, 34.47288513183594],
      [-77.39515686035156, 34.50209426879883]
    ]
  ]
}

# 遍历所有坐标点转换经度
for ring in geojson_data["coordinates"]:
    for point in ring:
        # 点的第一个元素是经度,执行转换
        point[0] = point[0] % 360

# 打印转换结果
print(json.dumps(geojson_data, indent=2))

# 可选:保存到文件
with open("converted_geojson.json", "w") as f:
    json.dump(geojson_data, f, indent=2)

从文件读取原数据的写法

如果你的GeoJSON存在本地文件里,替换开头的geojson_data定义即可:

with open("your_original_file.geojson", "r") as f:
    geojson_data = json.load(f)

内容的提问来源于stack exchange,提问作者bv169

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 12:17:14