{"id":21844496,"url":"https://github.com/pudding0503/nc2kml","last_synced_at":"2025-08-01T15:08:24.429Z","repository":{"id":56733179,"uuid":"524315397","full_name":"pudding0503/nc2kml","owner":"pudding0503","description":"将 netCDF 数据转换为适用于 Google Earth 和 Map 的 KML/KMZ 文件","archived":false,"fork":false,"pushed_at":"2022-08-16T06:28:20.000Z","size":3997,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T11:43:30.511Z","etag":null,"topics":["earth","googleearth","kml","kmz","netcdf","netcdf4","panoply"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pudding0503.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-13T05:58:28.000Z","updated_at":"2023-06-12T07:40:40.000Z","dependencies_parsed_at":"2022-08-16T00:50:15.247Z","dependency_job_id":null,"html_url":"https://github.com/pudding0503/nc2kml","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pudding0503%2Fnc2kml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pudding0503%2Fnc2kml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pudding0503%2Fnc2kml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pudding0503%2Fnc2kml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pudding0503","download_url":"https://codeload.github.com/pudding0503/nc2kml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244826995,"owners_count":20516864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["earth","googleearth","kml","kmz","netcdf","netcdf4","panoply"],"created_at":"2024-11-27T22:23:06.945Z","updated_at":"2025-03-21T16:24:21.071Z","avatar_url":"https://github.com/pudding0503.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n \u003cimg width=\"100px\" src=\"assets/satellite.svg\" align=\"center\" alt=\"Logo\" /\u003e\n \u003ch2 align=\"center\"\u003enc2kml\u003c/h2\u003e\n \u003cp align=\"center\"\u003e将 netCDF 数据转换为适用于 Google Earth 和 Map 的 KML/KMZ 文件\u003c/p\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.giss.nasa.gov/tools/panoply/download/\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/Panoply-5.11-blue.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/pudding0503/nc2kml/releases\"\u003e\n  \t\u003cimg src=\"https://img.shields.io/github/v/release/pudding0503/nc2kml?label=version\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/pudding0503/nc2kml/issues\"\u003e\n  \t\u003cimg alt=\"Issues\" src=\"https://img.shields.io/github/issues/pudding0503/my-git-bash.svg?color=F48D73\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/pudding0503/nc2kml/blob/main/LICENSE\"\u003e\n  \t\u003cimg alt=\"Github\" src=\"https://img.shields.io/github/license/pudding0503/my-git-bash.svg?logo=github\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\n### 1.安装 Panoply\n\n由于我没有写 netCDF 生成并导出 Plot 的代码，所以需要借助 NASA 的 [Panoply](https://www.giss.nasa.gov/tools/panoply/download/) 软件进行导出。\n\n[Panoply](https://www.giss.nasa.gov/tools/panoply/download/) 需要 Java 11 的环境，如果你不想安装整套的 JDK，可以使用 `.zip` 版并按照如下进行环境配置：\n\n1. 去 Oracle 下载 JDK 包，下载 zip 格式的包：https://www.oracle.com/java/technologies/downloads/#jdk18-windows\n2. 解压缩后放到合适的目录\n3. 配置环境变量\n\n```\nCLASSPATH=,;%JAVA_HOME%\\lib;%JAVA_HOME%\\lib\\tools.jar\nJAVA_HOME=D:\\dev\\jdk-11.0.15\n\nPATH=;%JAVA_HOME%\\bin;%JAVA_HOME%\\jre\\bin;\n\n（注：注意：变量值之间用\";\"隔开。注意原来Path的变量值末尾有没有;号，如果没有，先输入;号再输入。）\n```\n\n4. 输入 `java -version` 检查 Java 版本\n\n### 2.例示数据\n\n本例采用的 nc 数据为：\n\n```\n# 1979年1月至2018年12月的中国逐月太阳辐射数据集\nlrad_CMFD_V0106_B-01_01mo_010deg_197901-201812.nc\n```\n\n本例采用的 nc4 数据为：\n\n```\n# 1980年1月1日的全球太阳辐射数据集\nMERRA2_100.tavg1_2d_rad_Nx.19800101.nc4\n```\n\n这两个文件均可在 [Release](https://github.com/pudding0503/nc2kml/releases) 页面下载。\n\n### 3.导出 Plot\n\n使用 [Panoply](https://www.giss.nasa.gov/tools/panoply/download/) 打开 nc 文件，然后生成相应的 Plot 界面。在导出前需要对 Plot 进行一些设置，去掉一些元素。\n\n#### 3.1 Plot 设置与导出\n\n在 Plot 页面打开 **Overlays**、 **Grid**、 **Layout**、 **Scale** 这四个窗口，并根据红框标注的位置进行修改：\n\n- Overlays：将线条宽度改为 0\n- Grid：将线条宽度改为 0\n- Layout：全部取消选中\n- Scale：填充颜色改为黑色，线条宽度改为 0\n\n![](assets/screenshots-1.png)\n\n然后选择 **File -\u003e Export Animation**，按需导出需要的 png 图片序列：\n\n![](assets/screenshots-2.png)\n\n#### 3.2 图片按序号排序\n\n在你保存图片序列的文件夹根目录下，运行 `当前目录下按序号重命名.bat` 的批处理文件，即可将所有的 png 图片从序号 1 开始，逐个重命名。\n\n#### 3.3 图片移除底色\n\n由于 Panoply 导出的 png 图片无法设置为透明背景，所以还需要将白色底色进行移除。\n\n你需要安装 Pillow 库：\n\n```shell\npip install Pillow \n```\n\n在 `去除黑白底色底.py` 中，设置路径为你的图片序列所在的文件夹即可（注意 Windows 下建议采用双斜杠或者单反斜杠）：\n\n```python\n# 设定 png 图片目录\n# 由于 Windows 的安全特性，不要使用 C 盘路径\npath = \"D://yourpath//\"\n```\n\n然后运行此 Python 脚本即可，所有图片将全部删去白色底色。\n\n### 4.生成 KML\n\nKML 文件就是 Google Earth 导入需要的格式文件，而 KMZ 就是将 KML 和图片打包在一起的 ZIP 文件。KMZ 文件可以用 WinRAR 等进行解压。\n\n打开 `生成KML文件.py` 文件，并且设置一些信息，例如数据标题，开始的年月、结束的年月日期等：\n\n```python\n# 信息\nname = \"1979年1月至2018年12月的中国逐日太阳辐射\"\nbegin_year = 1979\nbegin_month = 1\nend_year = 2018\nend_month = 12\n```\n\n然后运行此 Python 脚本即可，运行成功后会在当前目录下生成 KML 文件。**最后请将这个 KML 文件放到你的图片序列的文件夹根目录下。**\n\n![](assets/screenshots-3.png)\n\n如果你想要打包 KMZ 文件，请将上面截图中的全部文件进行 ZIP 打包，然后把后缀名更改为 KMZ 即可。\n\n### 5.KML 的时间轴\n\n当你编辑 KML 文件中的时间数据时，要注意参照官方文档 [Keyhole时间和动画](https://developers.google.com/kml/documentation/time?hl=zh_cn#timespans--) 中的说明。\n\n```\n# 例如逐月的时间\n# 注意 1~9 必须要使用 01~09，否则将不能识别时间。\n2018-01\n2018-02\n\n# 例如逐日的时间\n2018-01-01\n2018-12-28\n\n# 例如 UTC 时间\n1980-01-01T00:30:00+08:00\n```\n\n### 6.导入 Google Earth\n\n将打包好的 KMZ 文件导入到 Google Earth Web 版，而 Google Earth Pro 同时支持 KML 和 KMZ 文件。\n\n```\n├── 2016至2017中国逐月太阳辐射\n├── MERRA2 地表吸收的长波辐射 KML\n```\n\n两个由例示数据导出的 KML 文件，也在 [Release](https://github.com/pudding0503/nc2kml/releases) 页面提供下载。\n\n![](assets/screenshots-4.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpudding0503%2Fnc2kml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpudding0503%2Fnc2kml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpudding0503%2Fnc2kml/lists"}