2022.3.11 KML點集的基本結構

? ? ? ? ? ? ? ? 工作需要,處理過一些KML文件,最近想借助KML梳理一下某些坐標點集,系統(tǒng)的了解一下KML文件的語法結構。(具體的格式解析用例放到最后)

? ? ? ? ? ? ? ? 這里我用<Point> 標記多個點的方式,整理我所收集到各省重點大學的坐標集合(舉個例子)。

點集

? ? ? ? ? ? ? ? 然后把KML直接拖入到奧維地圖軟件中,選擇全部導入

這里可以修改name屬性值修改顯示名稱

? ? ? ? ? ? ? ? 做個簡單的記錄,把軟件工具和kml用例上傳到百度網(wǎng)盤:

????????????????鏈接:https://pan.baidu.com/s/16xdZmBEOgPPeEreQxS2zLw

????????????????提取碼:9xlr


????????????????基于XML,并定義了一些TAG用于規(guī)定地理數(shù)據(jù)的顯示方式。KML可用于定義的地理特征包括地點、描述、疊層、路徑和多邊形等。

? ??????基本格式

1 地點標記(Placemarks)

一個簡單的地點標記的KML代碼如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<kml xmlns="http://earth.google.com/kml/2.1">

?<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>

它包括以下幾個部分:

(1)XML頭:<?xml version="1.0" encoding="UTF-8"?>

(2)KML命名空間定義:<kml xmlns="http://earth.google.com/kml/2.1">

(3)地點標記對象,包括:

名稱(name):用于對地點標記進行注記;

描述(description):對地點標記進行描述,“氣球(ballon)”中的顯示內容;

點(Point):指定地點標記的位置。

2 使用HTML描述地點標記

有兩種方式來使用HTML描述地點標記,一種是直接在,<Snippet>和<BalloonStyle>中的<text>標記中寫入標準HTTP超鏈接地址,如www.google.com,這樣Google Earth 4.0及更高版本將利用Auto-Markup技術自動把它顯示為超鏈接。另一種是使用CDATA元素在標記中寫入自己的HTML標記語言,如下所示:

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.1">

?<Document>

??? <Placemark>

????? <name>CDATA example</name>

????? <description>

??????? <![CDATA[

????????? <h1>CDATA Tags are useful!</h1>

????????? <p><font color="red">Text is <i>more readable</i> and

????????? <b>easier to write</b> when you can avoid using entity

????????? references.</font></p>

??????? ]]>

????? </description>

????? <Point>

??????? <coordinates>102.595626,14.996729</coordinates>

????? </Point>

??? </Placemark>

?</Document>

</kml>

3 疊層

疊層是覆蓋在地球表面的圖像。一個簡單的疊層KML代碼如下所示:

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.1">

<Folder>???

<name>Ground Overlays</name>???

<description>Examples of ground overlays</description>???

<GroundOverlay>?????

<name>Large-scale overlay on terrain</name>?????

<description>Overlay shows Mount Etna erupting on July 13th, 2001.</description>

<Icon>???????

<href>http://code.google.com/apis/kml/documentation/etna.jpg</href>?????

</Icon>?????

<LatLonBox>???????

<north>37.91904192681665</north>???????

<south>37.46543388598137</south>???????

<east>15.35832653742206</east>???????

<west>14.60128369746704</west>???????

<rotation>-0.1556640799496235</rotation>?????

</LatLonBox>???

</GroundOverlay>?

</Folder>

</kml>

在<GroundOverlay>中,它包含兩個較新的標記:

<Icon>:指定圖片的URL;

<LatLonBox>:指定圖片的位置和范圍。

Google Earth支持JPEG,BMP, GIF, TIFF, TGA和PNG等格式的圖像。

4 路線

在KML里面,路線由<LineString>元素來創(chuàng)建。如下所示:

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.1">

<Document>???

<name>Paths</name>

<description>Examples of paths. Note that the tessellate tag is by default????? set to 0. If you want to create tessellated lines, they must be authored????? (or edited) directly in KML.</description>

<Style id="yellowLineGreenPoly">?????

<LineStyle>???????

<color>7f00ffff</color>???????

<width>4</width>?????

</LineStyle>?????

<PolyStyle>???????

<color>7f00ff00</color>?????

</PolyStyle>???

</Style>

<Placemark>

<name>Absolute Extruded</name>?????

<description>Transparent green wall with yellow outlines</description>????? <styleUrl>#yellowLineGreenPoly</styleUrl>?????

<LineString>???????

<extrude>1</extrude>???????

<tessellate>1</tessellate>???????

<altitudeMode>absolute</altitudeMode>???????

<coordinates>

-112.2550785337791,36.07954952145647,2357?????????

-112.2549277039738,36.08117083492122,2357?????????

-112.2552505069063,36.08260761307279,2357?????????

-112.2564540158376,36.08395660588506,2357?????????

-112.2580238976449,36.08511401044813,2357?????????

-112.2595218489022,36.08584355239394,2357?????????

-112.2608216347552,36.08612634548589,2357?????????

-112.262073428656,36.08626019085147,2357?????????

-112.2633204928495,36.08621519860091,2357?????????

-112.2644963846444,36.08627897945274,2357?????????

-112.2656969554589,36.08649599090644,2357

</coordinates>?????

</LineString>

</Placemark>?

</Document>

</kml>

5 多邊形

多邊形由<Polygon>定義,包括<outerBoundaryIs>和<innerBoundaryIs>,如下所示:

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.1">

<Placemark>???

<name>The Pentagon</name>???

<Polygon>?????

<extrude>1</extrude>?????

<altitudeMode>relativeToGround</altitudeMode>?????

<outerBoundaryIs>???????

<LinearRing>?????????

<coordinates>???????????

-77.05788457660967,38.87253259892824,100????????????

-77.05465973756702,38.87291016281703,100????????????

-77.05315536854791,38.87053267794386,100????????????

-77.05552622493516,38.868757801256,100????????????

-77.05844056290393,38.86996206506943,100????????????

-77.05788457660967,38.87253259892824,100?????????

</coordinates>???????

</LinearRing>?????

</outerBoundaryIs>?????

<innerBoundaryIs> ???????

<LinearRing>?????????

<coordinates>???????????

-77.05668055019126,38.87154239798456,100????????????

-77.05542625960818,38.87167890344077,100????????????

-77.05485125901024,38.87076535397792,100????????????

-77.05577677433152,38.87008686581446,100????????????

-77.05691162017543,38.87054446963351,100????????????

-77.05668055019126,38.87154239798456,100?????????

</coordinates>???????

</LinearRing>?????

</innerBoundaryIs>???

</Polygon>?

</Placemark>

</kml>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容