KML(OpenGIS® KML Encoding Standard)从2.2.0版本开始由Google提交到OGC并被接受为标准,当前OGC KML的版本也就是2.2.0。
KML和GML在名称上类似,但是功能有很大不同。GML主要用于地理数据的交换;而KML主要用于地理数据的可视化,它不仅包括地理数据的描述,还包括数据的符号化方式、用户视角的控制等信息。
KML的Schema可以从http://schemas.opengis.net/kml/ 访问到。所有KML中耳熟能详的Placemark、LookAt等名称都可以在这里找到定义,相对OGC给出的文档,更好的关于KML Schema的参考在Google Code上http://code.google.com/intl/zh-CN/apis/kml/documentation/kml_tut.html ,这里还有关于Schema对象的关系,如图 11。
图 11 KML Schema对象关系图
注意,在图 11中的方框中的对象是逻辑上的对象,并不真实存在于Schema定义中。还有,红色标注的对象是Google对KML 2.2.0的扩展,在Google Earth 5.0以上版本中被支持,因此,对于需要了解KML标准的人来说,这些红色的内容都可以被忽略。
关于地理数据的描述,下面是一个最简单的描述“地标”的KML,它包含了一个点要素信息:
xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Simple placemark name> <description>Attached to the ground. Intelligently places itself at the height of the underlying terrain. description> <Point> <coordinates>-122.0822035425683,37.42228990140251,0 coordinates> Point> Placemark> kml>
下面是另外一个定义了显示样式的多边形数据:
xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="transBluePoly">
<LineStyle>
<width>1.5 width> LineStyle> <PolyStyle> <color>7dff0000 color> PolyStyle> Style> <Placemark> <name>Building 41 name> <styleUrl>#transBluePoly styleUrl> <Polygon> <extrude>1 extrude> <altitudeMode>relativeToGround altitudeMode> <outerBoundaryIs> <LinearRing> <coordinates> -122.0857412771483,37.42227033155257,17 -122.0858169768481,37.42231408832346,17 -122.085852582875,37.42230337469744,17 -122.0858799945639,37.42225686138789,17 -122.0858860101409,37.4222311076138,17 -122.0858069157288,37.42220250173855,17 -122.0858379542653,37.42214027058678,17 -122.0856732640519,37.42208690214408,17 -122.0856022926407,37.42214885429042,17 -122.0855902778436,37.422128290487,17 -122.0855841672237,37.42208171967246,17 -122.0854852065741,37.42210455874995,17 -122.0855067264352,37.42214267949824,17 -122.0854430712915,37.42212783846172,17 -122.0850990714904,37.42251282407603,17 -122.0856769818632,37.42281815323651,17 -122.0860162273783,37.42244918858722,17 -122.0857260327004,37.42229239604253,17 -122.0857412771483,37.42227033155257,17 coordinates> LinearRing> outerBoundaryIs> Polygon> Placemark> Document> kml> 这是一个定义了视点属性的点要素: xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Placemark> <name>Machu Picchu, Peru name> <LookAt> <longitude>-72.503364 longitude> <latitude>-13.209676 latitude> <altitude>0 altitude> <range>14794.882995 range> <tilt>66.768762 tilt> <heading>71.131493 heading> LookAt> <Point> <coordinates>-72.516244,-13.162806,0 coordinates> Point> Placemark> kml>