构建大型 KML 文件

发布于 2024-12-04 22:55:12 字数 395 浏览 1 评论 0原文

我生成的 KML 文件可能有 50,000 个或更多地标,根据特定于域的分组排列在文件夹中。 KML 文件使用打包到 KMZ 文件中的自定义图像。

我希望将单个 KML 文件分解为多个文件,并根据分组进行分区,因此我不会拥有 1 个带有文件夹的大型文档,而是拥有一个根/索引 KML 文件,其中包含链接到较小 KML 文件的文件夹。

但这可能吗?我认为一个 KMZ 文件只能包含 1 个 KML 文件,无论它在 zip 中的位置或名称如何。此外,我不太确定 KML 文件如何链接到另一个 KML 文件。这是将其作为本地文件的 的唯一方法吗? 能否链接到同一 KMZ 中的本地文件?

I generate KML files which may have 50,000 placemarks or more, arranged in Folders based on a domain-specific grouping. The KML file uses custom images which are packed in to a KMZ file.

I'm looking to breakup the single KML file in to multiple files, partitioned based on the grouping, so rather than having 1 large document with folders, i'd have a root/index KML file with folders linking to the smaller KML files.

Is this possible though? I think that a KMZ file can contain only 1 KML file, regardless of where it's located or its name, in the zip. Furthermore, I'm not exactly sure how a KML file can link to another KML file. Is the only way to have it as a <NetworkLink> to a local file? Can a <NetworkLink> work to link to a file local in the same KMZ?

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

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

发布评论

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

评论(2

坐在坟头思考人生 2024-12-11 22:55:12

根据设计,您可以在单个 KMZ 文件中包含多个 KML 文件。这样,您可以将许多 KML 文件捆绑在一个 KMZ 文件中,然后通过电子邮件下载、发送或离线访问。

Google 地球可以在单个 KMZ 文件中扩展到大量要素(50,000 个或更多),前提是要素被拆分为多个 KML 文件,并且 KML 的定义使得所有子 KML 文件都包含在内不会立即显示。 KML 提供了使用时间、区域或海拔高度过滤来控制显示哪些要素或子 KML 文件的机制。

大型 KML 文件可以使用以下任意技术进行缩放:

  1. 网络链接
  2. 区域
  3. 文件夹单选样式或显式可见性=0
  4. 每个功能的点数和几何简化

NetworkLinks

您可以在根 KML 文件中拥有任何级别的 NetworkLinks,从平面(单个 KML 文件,包含到 KMZ 内所有其他 KML 文件的网络链接)到深层(每个 KML 文件都带有一个 NetworkLink)到其他 KML 文件,每个文件都有自己的 NetworkLink)。取决于您需要如何构建 KML 以及数据有多大。

关键是 Google 地球选择第一个 KML 作为根 KML 文件,因此您必须确保第一个文件(通常名为 doc.kml)是通过网络链接加载其他 KML 文件的根 KML 文件。常见的结构是在“kml”子文件夹中包含其他 KML 文件,以将其与根 KML 文件区分开来。

以下是包含 4 个文件条目的 KMZ 示例:根 KML 文件 (doc.kml),其中包含指向“kml/sub1.kml”的 NetworkLink 和另一个指向“kml/sub2.kml”的 NetworkLink em>”,它又在“kml”子文件夹中具有指向“sub3.kml”的 NetworkLink。

== test.kmz ==

+doc.kml
   NetworkLink > kml/sub1.kml
   NetworkLink > kml/sub2.kml
+kml/sub1.kml
+kml/sub2.kml
   NetworkLink > sub3.kml
+kml/sub3.kml

以下是此类 doc.kml 文件的结构:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <NetworkLink>
        <name>NetworkLinked sub-item</name>
        <Link>
          <href> kml/sub1.kml </href>
        </Link>
    </NetworkLink>
    <NetworkLink>
        <name>NetworkLinked sub-item</name>
        <Link>
          <href> kml/sub2.kml </href>
        </Link>
    </NetworkLink>
    ...
  </Document>
</kml>

作为最佳实践,如果您在父 KML 文件中包含多个具有基于时间的功能的 NetworkLink,则添加 元素添加到 NetworkLinks 中,包括该功能集合的完整时间范围,否则 Google 地球将在启动时自动加载整个文件。

<NetworkLink>
  <TimeSpan>
    <begin>2007-01-14T01:00:00Z</begin>
    <end>2007-01-14T02:00:00Z</end>
  </TimeSpan>
  <Link>
    <href>...</href>
  </Link>
</NetworkLink>

区域

区域
影响地标几何形状或叠加层图像的可见性。区域与 NetworkLink 相结合,可以访问 KML 文件中的大量数据。区域可以选择具有最小和最大海拔以进行海拔水平过滤。

有关更多详细信息,请参阅有关 KML 中的区域的教程
https://developers.google.com/kml/documentation/regions

广播文件夹

您可以使用广播进一步限制在给定时间显示的内容文件夹并允许用户手动切换图层。

下面是一个单选文件夹示例,允许用户一次仅选择一个 NetworkLink。
当内容相互排斥并且在任何给定时间只应出现一组功能时使用此方法。

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>
        <Style id="rf">
            <ListStyle>
                <listItemType>radioFolder</listItemType>
            </ListStyle>
        </Style>
        
        <Folder>        
            <name>One at a time example</name>
            <open>1</open>
            <description>Link 1 visible by default</description>
            <styleUrl>#rf</styleUrl>
            
            <NetworkLink>
                <name>NetworkLinked sub-item-1</name>
                <Link>
                    <href> kml/sub1.kml </href>
                </Link>
            </NetworkLink>
            
            <NetworkLink>
                <name>NetworkLinked sub-item-2</name>
                <visibility>0</visibility>
                <Link>
                    <href> kml/sub2.kml </href>
                </Link>
            </NetworkLink>
            
        </Folder>
    </Document>
</kml>

如果这些层不是互斥的,并且用户可能希望一次看到多个层,则在每个层中设置 Visibility=0 以使它们默认不显示。通过向加载子 KML 文件的父 NetworkLink 添加visibility=0,可以将其与 NetworkLink 结合起来。

每个要素的点数和几何简化

KML 文件的大小和要素数量并不是需要考虑的唯一问题。具有单个高分辨率多边形(包含 350K 点和 7000 个内部多边形)的 KML 文件漏洞可能会导致 Google 地球性能问题。这种几何形状需要简化并减少点数。您可以使用QGIS打开KML文件,然后对多边形应用简化算法。在QGIS中,选择矢量菜单->几何工具 ->简化然后保存结果。

By design you can have multiple KML files within a single KMZ file. That way you can bundle many KML files in a single KMZ file that is downloaded, sent via e-mail or accessed offline.

Google Earth can scale to a large number of features (50,000 or much larger) in a single KMZ file if the features are split into multiple KML files and the KML is defined such that all the sub-KML files are not displayed at once. KML provides mechanisms to control which features or sub-KML files are displayed using time, region, or altitude level filtering.

Large KML files can scale using any of the following techniques:

  1. NetworkLinks
  2. Regions
  3. Folder Radio style or explicit visiblity=0
  4. Number of Points per feature and geometry simplification

NetworkLinks

You can have any level of NetworkLinks from within your root KML file from flat (single KML file with Networklinks to all other KML files within the KMZ) to deep (with each KML file with a NetworkLink to other KML files each with its own NetworkLink). Depends on how you need to structure your KML and how large the data is.

The key is that Google Earth chooses the first KML as the root KML file so you must ensure that the first file (typically named doc.kml) is the root KML file that loads the other KML files via network links. A common structure is to include additional KML files in a "kml" sub-folder to differentiate it from the root KML file.

Here's a KMZ example with 4 file entries: root KML file (doc.kml) that contains a NetworkLink to "kml/sub1.kml" and another to "kml/sub2.kml", which in turn has a NetworkLink to "sub3.kml" also in "kml" sub-folder.

== test.kmz ==

+doc.kml
   NetworkLink > kml/sub1.kml
   NetworkLink > kml/sub2.kml
+kml/sub1.kml
+kml/sub2.kml
   NetworkLink > sub3.kml
+kml/sub3.kml

Here is the structure of such a doc.kml file:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <NetworkLink>
        <name>NetworkLinked sub-item</name>
        <Link>
          <href> kml/sub1.kml </href>
        </Link>
    </NetworkLink>
    <NetworkLink>
        <name>NetworkLinked sub-item</name>
        <Link>
          <href> kml/sub2.kml </href>
        </Link>
    </NetworkLink>
    ...
  </Document>
</kml>

As a best practice if you include more than one NetworkLink with time-based features in a parent KML file then add a <TimeSpan> element to the NetworkLinks including the full range of time for that collection of features otherwise Google Earth will automatically load the entire file at startup.

<NetworkLink>
  <TimeSpan>
    <begin>2007-01-14T01:00:00Z</begin>
    <end>2007-01-14T02:00:00Z</end>
  </TimeSpan>
  <Link>
    <href>...</href>
  </Link>
</NetworkLink>

Regions

A Region
affects visibility of a Placemark's geometry or an Overlay's image. Regions combined with NetworkLinks enable access to massive amounts of data in KML files. A region can optionally have a min and max altitude for altitude level filtering.

For more details, here's a tutorial on Regions in KML
https://developers.google.com/kml/documentation/regions

Radio Folders

You can further restrict what is displayed at a given time using radio folders and allowing the user to manually toggle the layers.

Here's a radio folder example allowing the user to only choose one of the NetworkLinks at a time.
This is used when the content is mutually exclusive and only one set of features should appear at any given time.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>
        <Style id="rf">
            <ListStyle>
                <listItemType>radioFolder</listItemType>
            </ListStyle>
        </Style>
        
        <Folder>        
            <name>One at a time example</name>
            <open>1</open>
            <description>Link 1 visible by default</description>
            <styleUrl>#rf</styleUrl>
            
            <NetworkLink>
                <name>NetworkLinked sub-item-1</name>
                <Link>
                    <href> kml/sub1.kml </href>
                </Link>
            </NetworkLink>
            
            <NetworkLink>
                <name>NetworkLinked sub-item-2</name>
                <visibility>0</visibility>
                <Link>
                    <href> kml/sub2.kml </href>
                </Link>
            </NetworkLink>
            
        </Folder>
    </Document>
</kml>

If the layers are not mutually exclusive and user may want to see more than one at a time then set visibility=0 in each of the layers to make them not display by default. This can be combined with NetworkLinks by adding visibility=0 to the parent NetworkLink that loads the sub-KML file.

Number of Points per feature and geometry simplification

Size of the KML file and number of features is not the only issue to consider. A KML file with a single hi-res polygon having 350K points and 7000 inner holes can cause Google Earth performance issues. Such geometries would need to be simplified and the number of points reduced. You can use QGIS to open a KML file then apply a simplify algorithm on the polygon. In QGIS, select Vector menu -> Geometry tools -> Simplify then save the result.

迷你仙 2024-12-11 22:55:12

是的,您可以使用网络链接来完成此操作,据我所知,这是执行您所要求的操作的唯一方法。是的,您可以在网络链接中引用本地文件

请参阅:http ://code.google.com/intl/nl-NL/apis/kml/documentation/kml_tut.html(搜索“网络链接”),其中显示:

网络链接包含一个带有(超文本
参考)加载文件。可以是本地文件
规范或绝对 URL。尽管有这个名字,但
不一定从网络加载文件。在一个
链接指定以下任意一项的位置:

• 图标样式、地面叠加层和屏幕叠加层中的图标使用的图像文件
• 元素中使用的模型文件
• 通过网络链接加载的 KML 或 KMZ 文件

否,您不能引用kmz 内的其他文件。 kmz 只能包含 1 个 kml 文件(不过它可以包含其他类型的文件)您可以找到 kmz 文件的布局以及其中可能包含的内容 此处 特别注意以下部分:

2.输入默认的 KML 文件(doc.kml,或任何您想要指定的名称)
它)位于该文件夹的顶层。仅包含一个 .kml 文件。
(当 Google 地球打开 KMZ 文件时,它会扫描该文件,寻找
此列表中的第一个 .kml 文件。它忽略所有后续的 .kml
存档中的文件(如果有)。如果存档包含多个 .kml
文件,您无法确定首先找到哪个文件,因此您需要
仅包含一个。)

最后一点是,您的问题并不能说明您是否需要这 50.000 个地标作为脱机文件。如果您可以动态地为它们提供服务,您可以使用基于区域的链接,其中 GE 将告诉您客户端的查看区域,以便您可以返回一小部分航路点(仅限用户视图内的航路点)。 href="http://code.google.com/intl/nl-NL/apis/kml/documentation/regions.html" rel="nofollow">此是要点击的链接。

Yes you can use a networklink to accomplish this and as far as I know it's the only way to do what you ask. And yes you can reference local files in Network links

See: http://code.google.com/intl/nl-NL/apis/kml/documentation/kml_tut.html (search for "Network Links") where it says:

A network link contains a element with an (a hypertext
reference) that loads a file. The can be a local file
specification or an absolute URL. Despite the name, a <NetworkLink>
does not necessarily load files from the network. The <href> in a
link specifies the location of any of the following:

• An image file used by icons in icon styles, ground overlays, and screen overlays
• A model file used in the element
• A KML or KMZ file loaded by a Network Link

No you can't reference to another file inside a kmz. A kmz can only contain 1 kml file (it can contain other type of files though) You can find the layout of kmz files and what may be put in them here Specifically note the following section:

2.Put the default KML file (doc.kml, or whatever name you want to give
it) at the top level within this folder. Include only one .kml file.
(When Google Earth opens a KMZ file, it scans the file, looking for
the first .kml file in this list. It ignores all subsequent .kml
files, if any, in the archive. If the archive contains multiple .kml
files, you cannot be sure which one will be found first, so you need
to include only one.)

One final remark is that your question doesn't tell anything if you need these 50.000 placemarks as offline files or not. If you could serve them dynamically you could use the region based links where GE will tell you the viewing region of the client so you can return a small subset of the waypoints (only the ones that are inside the users view) For more info this is the link to click on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文