使用java对Google Earth图像进行kmz压缩
有谁知道在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
KMZ 只是一个包含 KML 文件和资源的 zip 文件。 例如,
london_eye.kmz
kmz 文件包含:您可以使用 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: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.
当然,我已经用 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?
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...
理解这一点的关键是 @fraser 的答案,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:
Apache Commons has an archive handling library which would be handy for this: http://commons.apache.org/proper/commons-vfs/filesystems.html
正如 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.
默认情况下ZipOutputStream Java 中的类将创建 Google 地球可以读取的兼容 KMZ 文件。
在 ZipEntry您可以指定STORED或DEFLATED压缩方法,这两种方法都与Google Earth兼容。
2.0 或“传统”压缩方法(即 STORED 和 DEFLATE 方法),除非这些是默认方法。 在 WinZip 文档。
下面是用 Java 创建 KMZ 文件的简单代码片段。
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.
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.
Here's simple code snippet to create a KMZ file in Java.