为什么Google地球会改变KML多边形坐标?

时间:2015-02-10 16:57:25

标签: xml google-maps google-maps-api-3 kml google-earth

我的目标是能够使用KML文件在Google地球的定义区域上绘制阴影多边形。我创建了一个KML文档,其中包含一个地标和一个具有所需坐标的多边形,并且能够将文件导入Google My maps并显示多边形。但是,当我用google earth打开相同的文件时,坐标似乎被解析得不同,并且多边形不正确(参见图片)。我的KML文件中是否有一些错误导致谷歌地球这样做?

这些是原始文件坐标。

<coordinates>
    149.02126, -36.489864, 100
    149.3816, -36.31477, 100
    149.25783, -36.134285, 100
    148.9647, -36.4074, 100
    149.02126, -36.489864, 100
</coordinates>

如果我从google earth复制多边形并将其粘贴到文本文件中作为KML我得到以下坐标

<coordinates>
    149.02126,-36.489864,100 
    149.3816,0,0 
    -36.31477,100,0 
    149.25783,-36.134285,100 
    148.9647,-36.4074,100 
    149.02126,-36.489864,100 
</coordinates>

完整的原始KML文件:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
   <Document>
      <Style id="examplePolyStyle">
         <PolyStyle>
            <color>7f0000ff</color>
            <colorMode>random</colorMode>
            <fill>1</fill>
            <outline>1</outline>
         </PolyStyle>
      </Style>
      <Placemark>
         <name>ID: AU201502070705001Issued: 2015-02-07T07:53:00.000Z</name>
         <description>Begins: 2015-02-07T07:53:00.000ZEnds: 2015-02-07T08:38:00.000Z</description>
         <styleUrl>#examplePolyStyle</styleUrl>
         <Polygon>
            <outerBoundaryIs>
               <LinearRing>
                  <coordinates>149.02126, -36.489864, 100 149.3816, -36.31477, 100 149.25783, -36.134285, 100 148.9647, -36.4074, 100 149.02126, -36.489864, 100</coordinates>
               </LinearRing>
            </outerBoundaryIs>
         </Polygon>
      </Placemark>
   </Document>
</kml>    

从Google地球复制的完整KML文件

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>Latest_Single_noCommaNoSpaces.kml</name>
    <Style id="examplePolyStyle">
        <PolyStyle>
            <color>7f0000ff</color>
            <colorMode>random</colorMode>
        </PolyStyle>
    </Style>
    <Placemark>
        <name>ID: AU201502070705001Issued: 2015-02-07T07:53:00.000Z</name>
        <description>Begins: 2015-02-07T07:53:00.000ZEnds: 2015-02-07T08:38:00.000Z</description>
        <styleUrl>#examplePolyStyle</styleUrl>
        <gx:balloonVisibility>1</gx:balloonVisibility>
        <Polygon>
            <outerBoundaryIs>
                <LinearRing>
<coordinates>
    149.02126,-36.489864,100 
    149.3816,0,0 
    -36.31477,100,0 
    149.25783,-36.134285,100 
    148.9647,-36.4074,100 
    149.02126,-36.489864,100 
</coordinates>
                </LinearRing>
            </outerBoundaryIs>
        </Polygon>
    </Placemark>
</Document>
</kml>

Screenshot of polygon in Google Maps

Screenshot of same polygon in Google Earth

1 个答案:

答案 0 :(得分:4)

您的原始KML坐标在元组中有空格that is not valid(空格分开元组)。

来自the documentation

  

<强> <coordinates>(必需)
  四个或更多元组,每个元组由经度,纬度和高度的浮点值组成。高度组件是可选的。 不要在元组中包含空格。最后一个坐标必须与第一个坐标相同。坐标仅以十进制度表示。

<coordinates>149.02126, -36.489864, 100 149.3816, -36.31477, 100 149.25783, -36.134285, 100 148.9647, -36.4074, 100 149.02126, -36.489864, 100</coordinates>

应该是:

<coordinates>149.02126,-36.489864,100 149.3816,-36.31477,100 149.25783,-36.134285,100 148.9647,-36.4074,100 149.02126,-36.489864,100</coordinates>