使用java对Google Earth图像进行kmz压缩

发布于 2024-07-30 02:07:07 字数 279 浏览 5 评论 0原文

有谁知道在 Java 中使用什么压缩来创建其中存储图像的 KMZ 文件? 我尝试使用标准 Java 压缩(以及各种模式,BEST_COMPRESSION、DEFAULT_COMPRESSION 等),但我的压缩文件和 kmz 文件总是略有不同,无法在 google Earth 中加载。 看起来特别像我的 png 图像(实际的 kml 文件似乎以相同的方式压缩)。

有没有人成功创建了一个 kmz 存档,该存档从谷歌地球外部链接到本地​​图像(并存储在文件目录中)?

谢谢杰夫

Does anyone know what compression to use in Java for creating KMZ files that have images stored within them? I tried using standard Java compression (and various modes, BEST_COMPRESSION, DEFAULT_COMPRESSION, etc), but my compressed file and the kmz file always come out slightly different don't load in google earth. It seems like my png images in particular (the actual kml file seems to compress the same way).

Has anyone successfully created a kmz archive that links to local images (and gets stored in the files directory) from outside of google earth?

thanks

Jeff

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

流年已逝 2024-08-06 02:07:07

KMZ 只是一个包含 KML 文件和资源的 zip 文件。 例如,london_eye.kmz kmz 文件包含:

   $ unzip -l london_eye.kmz 
    Archive:  london_eye.kmz
      Length     Date   Time    Name
     --------    ----   ----    ----
       451823  09-27-07 08:47   doc.kml
            0  09-26-07 07:39   files/
         1796  12-31-79 00:00   files/Blue_Tile.JPG
       186227  12-31-79 00:00   files/Legs.dae
         3960  12-31-79 00:00   files/Olive.JPG
      1662074  12-31-79 00:00   files/Wheel.dae
        65993  12-31-79 00:00   files/Wooden_Fence.jpg
         7598  12-31-79 00:00   files/a0.gif
         7596  12-31-79 00:00   files/a1.gif
         7556  12-31-79 00:00   files/a10.gif
         7569  12-31-79 00:00   files/a11.gif
         7615  12-31-79 00:00   files/a12.gif
         7587  12-31-79 00:00   files/a13.gif
         7565  12-31-79 00:00   files/a14.gif
         7603  12-31-79 00:00   files/a15.gif
         7599  12-31-79 00:00   files/a16.gif
         7581  12-31-79 00:00   files/a17.gif
         7606  12-31-79 00:00   files/a18.gif
         7613  12-31-79 00:00   files/a19.gif
         7607  12-31-79 00:00   files/a2.gif
         7592  12-31-79 00:00   files/a3.gif
         7615  12-31-79 00:00   files/a4.gif
         7618  12-31-79 00:00   files/a5.gif
         7618  12-31-79 00:00   files/a6.gif
         7578  12-31-79 00:00   files/a7.gif
         7609  12-31-79 00:00   files/a8.gif
         7603  12-31-79 00:00   files/a9.gif
        57185  12-31-79 00:00   files/capsule.dae
       310590  12-31-79 00:00   files/groundoverlay.jpg
       224927  12-31-79 00:00   files/mechanism.dae
       160728  12-31-79 00:00   files/shadowoverlay.jpg
        33044  12-31-79 00:00   files/shed.dae
     --------                   -------
      3310275                   32 files

您可以使用 java.util.zip 构建此文件,如果需要,甚至可以使用 jar 构建它。

就图像而言,它们不应该被压缩,因为它们已经包含压缩数据。 您不会获得任何显着的节省。

KMZ is simply a zip file with a KML file and assets. For example, the london_eye.kmz kmz file contains:

   $ unzip -l london_eye.kmz 
    Archive:  london_eye.kmz
      Length     Date   Time    Name
     --------    ----   ----    ----
       451823  09-27-07 08:47   doc.kml
            0  09-26-07 07:39   files/
         1796  12-31-79 00:00   files/Blue_Tile.JPG
       186227  12-31-79 00:00   files/Legs.dae
         3960  12-31-79 00:00   files/Olive.JPG
      1662074  12-31-79 00:00   files/Wheel.dae
        65993  12-31-79 00:00   files/Wooden_Fence.jpg
         7598  12-31-79 00:00   files/a0.gif
         7596  12-31-79 00:00   files/a1.gif
         7556  12-31-79 00:00   files/a10.gif
         7569  12-31-79 00:00   files/a11.gif
         7615  12-31-79 00:00   files/a12.gif
         7587  12-31-79 00:00   files/a13.gif
         7565  12-31-79 00:00   files/a14.gif
         7603  12-31-79 00:00   files/a15.gif
         7599  12-31-79 00:00   files/a16.gif
         7581  12-31-79 00:00   files/a17.gif
         7606  12-31-79 00:00   files/a18.gif
         7613  12-31-79 00:00   files/a19.gif
         7607  12-31-79 00:00   files/a2.gif
         7592  12-31-79 00:00   files/a3.gif
         7615  12-31-79 00:00   files/a4.gif
         7618  12-31-79 00:00   files/a5.gif
         7618  12-31-79 00:00   files/a6.gif
         7578  12-31-79 00:00   files/a7.gif
         7609  12-31-79 00:00   files/a8.gif
         7603  12-31-79 00:00   files/a9.gif
        57185  12-31-79 00:00   files/capsule.dae
       310590  12-31-79 00:00   files/groundoverlay.jpg
       224927  12-31-79 00:00   files/mechanism.dae
       160728  12-31-79 00:00   files/shadowoverlay.jpg
        33044  12-31-79 00:00   files/shed.dae
     --------                   -------
      3310275                   32 files

You can build this with java.util.zip, or even with jar if you want.

As far as the images go, they should not be compressed, since they already contain compressed data. You don't get any significant savings.

篱下浅笙歌 2024-08-06 02:07:07

当然,我已经用 c# 中的图像打包了 Kmz 文件。 据我所知,唯一支持的压缩方法是 ZIP(PKZIP 兼容)。 你使用的 Java 中的哪个库?

Sure, I have package Kmz files with images in c#. AFAIK the only compression method that is supported is ZIP (PKZIP-compatible). What library in Java are you using?

汹涌人海 2024-08-06 02:07:07

Java 中有一个用于处理 KML 的库,名为 JAK (KML 的 Java API) 。

不幸的是,它似乎有一个错误:问题 1:保存 KMZ 文件确实不起作用 - 所以看来您不是第一个在生成 KMZ 文件时遇到问题的人...

There is a library for dealing with KML in Java called JAK (Java API for KML).

Unfortunately, it seems to have a bug: Issue 1: save KMZ file does not work - so it looks like you're not the first one who has problems with generating a KMZ file...

笨笨の傻瓜 2024-08-06 02:07:07

理解这一点的关键是 @fraser 的答案,KML 开发人员支持的以下代码片段支持了该答案:

唯一支持的压缩方法是 ZIP(PKZIP 兼容),因此
gzip 和 bzip 都不起作用。 用此压缩的 KMZ 文件
API 完全支持方法。

Google 地球 API 中的 KMZ Unix环境下的KML压缩

Apache Commons 有一个存档处理库,这对于此操作非常方便:http://commons.apache.org/proper/commons-vfs/filesystems.html

The key to understanding this is the answer from @fraser, which is supported by this snippet from KML Developer Support:

The only supported compression method is ZIP (PKZIP-compatible), so
neither gzip nor bzip would work. KMZ files compressed with this
method are fully supported by the API.

KMZ in Google Earth API & KML Compression in a Unix environment

Apache Commons has an archive handling library which would be handy for this: http://commons.apache.org/proper/commons-vfs/filesystems.html

雨轻弹 2024-08-06 02:07:07

正如 simsong 所说,KMZ 只是压缩的 KML。 我注意到的一件事是 doc.kml 需要成为 zip 文件中的第一个条目才能可靠地工作。 我不记得对图像做了任何特殊的事情(除了将除 doc.kml 之外的所有内容都放在子目录中)。 我的 KMZ 文件是使用 java.util.zip 生成的。

As simsong said, KMZ is simply zipped KML. One thing I did notice is that doc.kml needs to be the first entry in the zip file for it to work reliably. I don't recall doing anything special with the images (apart from putting everything but doc.kml in a subdirectory). My KMZ files are generated using java.util.zip.

悲喜皆因你 2024-08-06 02:07:07

默认情况下ZipOutputStream Java 中的类将创建 Google 地球可以读取的兼容 KMZ 文件。

ZipEntry您可以指定STOREDDEFLATED压缩方法,这两种方法都与Google Earth兼容。

  • 请注意,无论您使用哪个 ZIP 库或 API,都必须确保指定 ZIP
    2.0 或“传统”压缩方法(即 STORED 和 DEFLATE 方法),除非这些是默认方法。 在 WinZip 文档
  • Google 地球还支持通常以短名称“Defl:X”显示的最大或增强型放气方法。
  • 更高级的压缩方法(例如 bzip2、LZMA 等)与 Google 地球兼容,此类 KMZ 文件在打开时将被忽略。

下面是用 Java 创建 KMZ 文件的简单代码片段。

  FileOutputStream fos = new FileOutputStream("example.kmz");
  ZipOutputStream zoS = new ZipOutputStream(fos);
  ZipEntry ze = new ZipEntry("doc.kml");
  zoS.putNextEntry(ze);
  PrintStream ps = new PrintStream(zoS);
  ps.println("<?xml version='1.0' encoding='UTF-8'?>");
  ps.println("<kml xmlns='http://www.opengis.net/kml/2.2'>");
  // write out contents of KML file ...
  ps.println("<Document>");
  ps.println("<Placemark>");
  // ...
  ps.println("</Placemark>");
  ps.println("</Document>");
  ps.println("</kml>");
  ps.flush();
  zoS.closeEntry(); // close KML entry
  // include and write other files (E.g. icons, overlays, other KML files, etc.)
  zoS.close();

By default the ZipOutputStream class in Java will create a compatible KMZ file that Google Earth can read.

In the ZipEntry you can specify either STORED or DEFLATED compression method, both of which are compatible with Google Earth.

  • Note whichever ZIP library or API you use, you must make sure to specify ZIP
    2.0 or "legacy" compression methods (i.e., STORED and DEFLATE methods) unless these are the default methods. DEFLATE method is called SuperFast and STORED is called None or 'No Compression' in WinZip documentation.
  • Maximum or enhanced deflate method often displayed with the short name "Defl:X" is also supported in Google Earth.
  • More advanced compression methods (e.g., bzip2, LZMA, etc.) are NOT compatible with Google Earth and such KMZ files will be silently ignored if opened.

Here's simple code snippet to create a KMZ file in Java.

  FileOutputStream fos = new FileOutputStream("example.kmz");
  ZipOutputStream zoS = new ZipOutputStream(fos);
  ZipEntry ze = new ZipEntry("doc.kml");
  zoS.putNextEntry(ze);
  PrintStream ps = new PrintStream(zoS);
  ps.println("<?xml version='1.0' encoding='UTF-8'?>");
  ps.println("<kml xmlns='http://www.opengis.net/kml/2.2'>");
  // write out contents of KML file ...
  ps.println("<Document>");
  ps.println("<Placemark>");
  // ...
  ps.println("</Placemark>");
  ps.println("</Document>");
  ps.println("</kml>");
  ps.flush();
  zoS.closeEntry(); // close KML entry
  // include and write other files (E.g. icons, overlays, other KML files, etc.)
  zoS.close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文