Google Earth KML中文说明

Google Earth KML中文说明
2008-02-17 16:46
KML 2.0介绍
KML全称是Keyhole Markup Language KML,是一个基于XML语法和文件格式的文件,用来描述和保存地理信息如点、线、图片、折线并在Google Earth客户端之中显示, (KML以前的版本能够被Google Earth读取并保存为KML 2.0) KML 2.0提供以下功能:

指定一个地点的图标和标注来区分每一个地点
为每一个视图指定明确的视角来创建不同的特写镜头
使用指定到屏幕或地理位置的图片标注
为特定种类的标注定义显示样式
为标注指定基于简单HTML语法的描述,支持超级链接和图片的显示
使用目录(folders)对标注进行树形的分类管理(为了便于理解和符合习惯,将"folder"翻译为"目录",实际上是代表一组地理标注,请谅解)
基于时间戳记的标注可以用来进行动态的播放
从本地或远程的网络地址动态的加载KML文件
当Google Earth客户端视图变化时,自动将视图信息发送给指定的源服务器并从服务器获取相关的标注信息
KML被Google Earth viewer显示的过程和HTML网页被浏览器处理差不多,而且和HTML一样,KML也使用一种基于标签(名称和属性)的语法格式来描述地里标注信息,可以说,Google Earth viewer是一个KML文件浏览器.

目录
KML 2.0 What's New
编写您自己的Google earth KML文件
KML基础
常用标签
地名标注(Placemarks)
几何图形(Geometry)
目录(Folders)
文档(Documents)
图片标注(Image Overlays)
地理图片标注(Ground Overlays)
屏幕图片标注(Screen Overlays)
时间
样式
Schemas
网络连接
Google Earth KML 2.0参考
KML语法规则
文档结构
标记类型
字符串
KML标签列表
<address>
<altitudeMode>
<begin>
<color>
<coordinates>
<description>
<Document>
<drawOrder>
<east>
<end>
<extrude>
<fill>
<Folder>
<geomColor>
<GeometryCollection>
<geomScale>
<GroundOverlay>
<h>
<heading>
<href>
<Icon>
<IconStyle>
<innerBoundaryIs>
<labelColor>
<latitude>
<LatLonBox>
<LinearRing>
<LineString>
<longitude>
<LookAt>
<name>
<NetworkLink>
<north>
<ObjArrayField>
<ObjField>
<open>
<outerBoundaryIs>
<outline>
<overlayXY>
<Pair>
<parent>
<Placemark>
<Point>
<Polygon>
<PolyStyle>
<range>
<refreshInterval>
<refreshVisibility>
<rotation>
<Schema>
<scale>
<ScreenOverlay>
<screenXY>
<SimpleArrayField>
<SimpleField>
<size>
<south>
<snippet>
<Style>
<StyleMap>
<styleUrl>
<tessellate>
<tilt>
<TimePeriod>
<TimeInstant>
<timePosition>
<type>
<href>
<Url>
<viewRefreshMode>
<viewRefreshTime>
<visibility>
<w>
<west>
<x>
<y>
KML 2.0 What's New
KML 1.0是由原先的Keyhole客户端进行读写的文件格式,Google Earth完全支持KML 1.0文件,KML 2.0 是KML 1.0的升级版本,主要的更新如下:

Google Earth默认的输出文件格式改为KMZ,这是一个经过ZIP格式压缩过的KML文件,可以被任何支持ZIP压缩文件格式的软件打开,这种文件的优点是自身可以包含图片而不需要引用网络上的图片;
<description>标签现在可以支持一些标准的HTML格式语法,例如链接、图片、带格式文本和表格;
过去使用的<View>标签被新的<LookAt>标签替代;
对<ScreenOverlay>标签的语法进行了升级更新;
样式功能更为强大,现在由<IconStyle>、 <LabelStyle>、 <LineStyle>和<PolyStyle>四个分样式组成;
过去的网络连接功能升级后能支持基于视图变化的更新;
线段可以选择是否根据地形进行自动调整;
<opacity>标签不再支持,推荐使用<color>标签来实现透明;
Network links功能现在支持向服务器发送当前视角信息,以便让服务器返回特定的KML文件。
编写您自己的Google earth KML文件
Google Earth中的所有标注都是通过KML来描述的,KML有以下撰写方式:

使用Google Earth client撰写KML文件:
对于希望创建通过E-mail或者网页来发布的不动态的KML文件的用户来说,Google Earth 客户端就是一个很好的KML撰写工具,在Google Earth客户端中简单的按照您自己的要求组织您需要的数据并保存成一个独立的文件即可,在开发人员想要测试复杂的KML文档结构的时候,这个功能也同样有用, Google Earth客户端能够创建和保存几乎所有的KML标签。

使用文本编辑器:
你可以使用一个文本编辑器来创建简单的KML文件,或者测试一个KML文件的结构和语法的有效性。

TIP: 想要快速的检查KML语法,在Google Earth中右键点击一个地名标注或者图片标注,然后在菜单中选择"Copy", 然后你可以打开一个简单的文本文档然后将KML内容粘贴到其中,就可以方便的查看Google Earth撰写的KML内容了

使用开发环境来自动生成KML文件:
您能够使用一种用来动态生成网页内容的编辑平台来生成KML地标文件,只要能够生成XML文件,就可以同样生成KML文件。

下面是一个KML文件范例:

<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
  <description><![CDATA[<a href="http://www.google.com.honeycomb.cs.cornell.edu:8888/">Google Search!</a>]]></description>
  <name>Google Headquarters</name>
  <LookAt>
    <longitude>-122.0839</longitude>
    <latitude>37.4219</latitude>
    <range>540.68</range>
    <tilt>0</tilt>
    <heading>3</heading>
  </LookAt>
  <Point>
    <coordinates>-122.0839,37.4219,0</coordinates>
  </Point>
</Placemark>
</kml>这个文件里有一个<kml>标签,包含一个被命名为Google Headquarters的<Placemark>标签,当这个文件被Google Earth客户端读取的时候,<Placemark>将会以默认的图标和在<Point>中指定的经纬度处显示, <Placemark>的<LookAt>子标签指定当在Google Earth中显示这个标注的时候"照相机"视点.

你可以复制该范例内容并保存成扩展名为.kml的文本文件,在Google Earth之中打开查看效果

本文档的剩下部分还包含以下内容:

在你撰写你自己的KML文件的时候涉及到的Google Earth客户端 标签
程序员和GIS(地理信息系统)专业人员在用适当的方式撰写KML文件的时候需要的KML语法和指导
KML语法参考,包括复合标签和单一标签
KML基础
Google Earth 客户端支持了大量的显示标签用来创建和保存成KML文档。如果你喜欢,你可以先用文本编辑器修改KML文档,然后在Google Earth客户端中打开看显示的效果,这和你修改一个HTML文档并在浏览器之中观看效果是一样的。对于更高级的程序,你可以使用CGI脚本生成KML文件,这一节讲解在Google Earth客户端之中支持的KML基本标签。

常用标签
在本节中描述的所有标注(目录folders,地名标注placemarks,图片标注overlays 和 网络连接)都包含以下元素.

<Name>
KML语法使用<name></name>标签来指定目录(floder)、地名标注(placemark)、图片标注(overlay)或其他标记的名称,以便在Google Earth中进行区别,下面的例子显示了<name>标签在<Folder>标签上的应用:

<Folder>
  <name>My House</name>
  .
  .
  .
</Folder><description>
使用描述元素给标注附加更多的关于该标注的信息,Google Earth自动识别其中的网址并显示为一个链接,并不需要任何HTML标记,不过你也可以再需要时使用HTML格式化文本的显示,甚至还可以使用图片。

为了在描述之中使用HTML标签,您需要使用CDATA XML 标签来避免XML对HTML字符的解析,或者您也可以对特定的字符进行实体引用

注意:在第一个测试版中在<img src="">标签中部允许包含GIF图片,这个错误将在下一版本中修正,不过现在您可能还是只能使用JPG, PNG or BMP这几种格式。

<visibility>
<visibility>用来设置标注在第一次被Google Earth打开时的默认显示属性. Visibility对所有的标注都有效。不过visibility在目录之中使用的时候存在特殊情况,一个标记只有在它和它所有的上级标签都设成true(1)的时候才会显示。

你可以定义该标注在用户打开KML文件的时候是否显示,在文件打开完成之后是否显示该标注完全取决于用户的操作。

<LookAt>
<LookAt>元素用来指定对给定点的特定视角,Google Earth能够为地名标注(placemarks),目录(folders),图片标注(overlays)和其他标注设置视角,当一个标注存在指定的<LookAt>标签时,双击该标注将使Google Earth平滑移动到指定视角。

值得注意的是,视角和标注的经纬度没有任何关系,例如,一个地名标注可能在一大片陆地的中央,而该标注对应的视角观察者却朝向陆地的左边边界。

实际上,一个标注的视点可能被设置到甚至根本看不到该标注本身的位置,因此当你为一个地名标注设置一个视点的时候,不要认为它会自动的让该标注出现在Google Earth视图之中。这样可能在你想为一个特定的标注使用一个特定的,不受限制的视角时非常有用,可有时候也会带来麻烦,因此,请谨慎使用本功能。当一个标记没有<LookAt>标签时,双击该标签将使Google Earth缩放当前视图到包含该标注点

<address>
你可以使用包含地址字符串的<Point>标签来代替指定经纬度,例如<address>1600 Amphitherter Pkwy, Mountain View, CA</address> 这样将使用Google Earth的功能来解析这个地址(请注意这个功能现在只支持美国地址)

<snippet>
<snippet>标签允许您插入多行的描述文本,当用户选中该标签的时候,这些文本将显示在窗口的底部。

地名标注<Placemark>
Placemarks are the primary means of marking a location on the earth.A plcaemark may contain a single point, linestring, polygon, or arbitrary collections of these features. User-defined styles may be created to control the appearance of each of these elements.

With KML, you can customize your placemark information in a variety of ways. In addition to the common elements, the placemark element uses a style reference (<styleUrl>) to specify the desired style for that placemark.

For example, you can use any image-such as your company logo-as the icon for a placemark by using the style reference to point to the desired icon. In addition, the style can reference a style map in order to display a different style when the user mouses over a placemark. In this way, you can have both a normal and a highlighted state for placemark icons. Finally, you can also use style references to set scale and color for geometry as well as point labels.

You can also specify a <Style> within a <Placemark>. This style is known as the Placemark's local style. Any fields that are specified in the local style will override the corresponding fields in the referenced style (i.e., any style referenced through <styleUrl>). Minimal use of local styles is recommended for best efficiency.

几何图形Geometry
The following types of geometry can be expressed in the Google Earth client viewer:

Point geometry
Points may be mapped on the earth's surface as either icons or labels, or both. Placemarked points may be richly annotated within the Google Earth client, and may be positioned three-dimensionally. Points positioned at altitude may also be extruded, creating a line that tethers the placemark to the ground.

Line geometry
This includes lines and linestrings (polylines), but not road data. As with points, lines may be positioned at altitude, and extruded to form solid walls.

Polygons
Two dimensional polygons may be created in the Google Earth client. As with lines, polygons may be positioned at altitude and extruded to form three-dimensional objects. Using a combination of points, lines, and polygons, it is easy to create rich, visually arresting displays of your data.

Collections
Lines and polygons may be grouped into collections.

Coordinates
Coordinate values for geometry must be entered in degrees (longitude, latitude) and meters (elevation above sea level). KML uses the <coordinates> tag to describe this feature. See the entry for <coordinates> for more information.

Important: The required geographic coordinates specification is Longitude, Latitude, and Altitude, in that order. If you don't follow this method, your coordinate specifications will be misinterpreted.

3D Geometry
In the Google Earth client it is possible to create three-dimensional shapes by extruding two-dimensional objects. See the entry for <extrude> for more information.

目录<Folder>
Most uses of KML employ folders to organize placemarks, screen and ground overlays, and other folders. Use folders to structure collections of features and overlay groups, andto provide a unified view for a group of placemarks and/or overlays. In addition to the common elements, folders may have a number of extra properties:

<open>
A switch (0 or 1) that controls whether or not the folder will be in an expanded or collapsed state when it is loaded.

Logical containment of related data, and folder nesting
You can use a folder to contain related placemarks, overlays, and other folders. By providing folders with a name and LookAt values, you can group information in way to make it easily identifiable and manageable. For example, you can use a folder to associate a placemark with a related overlay image file for a multi-layered view of a particular region.

You can create a hierarchical structure in a manner similar to the Microsoft Windows folder view, so that folders can be expanded or collapsed to reveal or hide content as needed. Do this in the Google Earth client by dragging and dropping folders on top of other folders in order to nest them. In KML, <Folder></Folder> tags simply nest within each other, in the same way that <table></table> tags can be nested in HTML.

http://www.step1.cn/googleapi/map/kml.htm

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangjie_xiaoke/archive/2008/03/27/2222281.aspx

原文地址:https://www.cnblogs.com/googlegis/p/2979033.html