【问题标题】:How to create kml to geocode addresses in Google Earth?如何在 Google 地球中创建 kml 以对地址进行地理编码?
【发布时间】:2013-03-20 13:33:42
【问题描述】:

如果您有一个包含地址信息的 .csv 文件,您可以将其拖放到 Google 地球(以下简称 GE)上,然后会出现一个向导,以便您分配字段,然后 GE 将开始地理编码位置并为每个地址创建点(纬度和经度)。然后,您可以将地理编码文件导出为 kml 并获取每个点的纬度/经度。但是,此过程有 2500 行的限制。

我听说可以创建一个 kml(或者可能是一个 xml)文件并将其拉入 GE 以启动地理编码过程,并且这种方法没有行限制。有人可以帮我弄清楚如何做到这一点吗?我已经尝试了以下代码,它确实成功导入 GE,但没有创建任何点。

我知道一些 Google Maps API 可以做类似的事情,并且每天有 100,000 行的行限制用于商业用途,但我真的很想与 GE 合作。

<?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>GEImport1.csv</name>
    <Schema name="GEImport1" id="S_GEImport1_S">
        <SimpleField type="string" name="Adress"><displayName>&lt;b&gt;Adress&lt;/b&gt;</displayName>
</SimpleField>
    </Schema>
    <Style id="hlightPointStyle">
        <IconStyle>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle_highlight.png</href>
            </Icon>
        </IconStyle>
        <BalloonStyle>
            <text><![CDATA[<table border="0">
  <tr><td><b>Adress</b></td><td>$[GEImport1/Adress]</td></tr>
</table>
]]></text>
        </BalloonStyle>
    </Style>
    <Style id="normPointStyle">
        <IconStyle>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href>
            </Icon>
        </IconStyle>
        <BalloonStyle>
            <text><![CDATA[<table border="0">
  <tr><td><b>Adress</b></td><td>$[GEImport1/Adress]</td></tr>
</table>
]]></text>
        </BalloonStyle>
    </Style>
    <StyleMap id="pointStyleMap">
        <Pair>
            <key>normal</key>
            <styleUrl>#normPointStyle</styleUrl>
        </Pair>
        <Pair>
            <key>highlight</key>
            <styleUrl>#hlightPointStyle</styleUrl>
        </Pair>
    </StyleMap>
    <Folder id="layer 0">
        <name>GEImport1</name>
        <visibility>0</visibility>
        <Placemark>
            <visibility>0</visibility>
            <styleUrl>#pointStyleMap</styleUrl>
            <ExtendedData>
                <SchemaData schemaUrl="#S_GEImport1_S">
                    <SimpleData name="Adress">6212 GATUN CT Port ST Lucie, FL</SimpleData>
                </SchemaData>
            </ExtendedData>
        </Placemark>
        <Placemark>
            <visibility>0</visibility>
            <styleUrl>#pointStyleMap</styleUrl>
            <ExtendedData>
                <SchemaData schemaUrl="#S_GEImport1_S">
                    <SimpleData name="Adress">6213 DIANA CT Port ST Lucie, FL</SimpleData>
                </SchemaData>
            </ExtendedData>
        </Placemark>
        <Placemark>
            <visibility>0</visibility>
            <styleUrl>#pointStyleMap</styleUrl>
            <ExtendedData>
                <SchemaData schemaUrl="#S_GEImport1_S">
                    <SimpleData name="Adress">6213 DUKE CIR Port ST Lucie, FL</SimpleData>
                </SchemaData>
            </ExtendedData>
        </Placemark>
    </Folder>
</Document>
</kml>

编辑:最终结果
JasonM1 的解决方案效果很好! 我最终得到了以下格式的 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>AddressImport</name>
    <Style id="normPointStyle">
        <IconStyle>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href>
            </Icon>
        </IconStyle>
        <BalloonStyle>
            <text><![CDATA[<table border="0">
          <tr><td><b>Address</b></td><td>$[address]</td></tr>
          </table>]]>
      </text>
        </BalloonStyle>
    </Style>
    <StyleMap id="pointStyleMap">
        <Pair>
            <key>normal</key>
            <styleUrl>#normPointStyle</styleUrl>
        </Pair>
    </StyleMap>
    <Folder id="layer 0">
        <name>AddressImport</name>
        <visibility>1</visibility>
        <Placemark>
            <visibility>1</visibility>
            <address>9994 CHADWICK DR Port ST Lucie, FL</address>
            <styleUrl>#pointStyleMap</styleUrl>
        </Placemark>
        <Placemark>
            <visibility>1</visibility>
            <address>9995 AMBROSE WAY Port ST Lucie, FL</address>
            <styleUrl>#pointStyleMap</styleUrl>
        </Placemark>
        <Placemark>
            <visibility>1</visibility>
            <address>9997 STONEGATE DR Port ST Lucie, FL</address>
            <styleUrl>#pointStyleMap</styleUrl>
        </Placemark>
    </Folder>
</Document>
</kml>

另外,我使用以下 Excel VBA 代码来自动创建 kml 文件:

Sub CreateCSV_FSO()
    Dim objFSO
    Dim objTF
    Dim ws As Worksheet
    Dim lRow As Long
    Dim lCol As Long
    Dim strTmp As String
    Dim lFnum As Long
    Dim sFilePath As String
    Dim i As Long
    Dim x As Integer 'used to represent the column that contains the address
    sFilePath = ActiveWorkbook.Path & "\AddressImport.kml"

    Set objFSO = CreateObject("scripting.filesystemobject")
    Set objTF = objFSO.createtextfile(sFilePath, True, False)

    'Header information
    objTF.writeline "<?xml version=""1.0"" encoding=""UTF-8""?>"
    objTF.writeline "<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"">"
    objTF.writeline "    <Document>"
    objTF.writeline "<name>AddressImport</name>"
    objTF.writeline "    <Style id=""normPointStyle"">"
    objTF.writeline "        <IconStyle>"
    objTF.writeline "            <Icon>"
    objTF.writeline "                <href>http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png</href>"
    objTF.writeline "            </Icon>"
    objTF.writeline "        </IconStyle>"
    objTF.writeline "        <BalloonStyle>"
    objTF.writeline "            <text><![CDATA[<table border=""0"">"
    objTF.writeline "          <tr><td><b>Address</b></td><td>$[address]</td></tr>"
    objTF.writeline "          </table>]]>"
    objTF.writeline "      </text>"
    objTF.writeline "        </BalloonStyle>"
    objTF.writeline "    </Style>"
    objTF.writeline "    <StyleMap id=""pointStyleMap"">"
    objTF.writeline "        <Pair>"
    objTF.writeline "            <key>normal</key>"
    objTF.writeline "            <styleUrl>#normPointStyle</styleUrl>"
    objTF.writeline "        </Pair>"
    objTF.writeline "    </StyleMap>"
    objTF.writeline "    <Folder id=""layer 0"">"
    objTF.writeline "        <name>AddressImport</name>"
    objTF.writeline "        <visibility>1</visibility>"

    'input the number representative of the column that contains the address
    x = 7 'a=1,b=2,c=3,d=4.....etc.
    i = 2
    While Cells(i, x) <> ""

        strTmp = ""
        strTmp = Cells(i, x)
        strTmp = Replace(strTmp, "&", "and")

        objTF.writeline "        <Placemark>"
        objTF.writeline "            <visibility>1</visibility>"
        objTF.writeline "            <address>" & strTmp & "</address>"
        objTF.writeline "            <styleUrl>#pointStyleMap</styleUrl>"
        objTF.writeline "        </Placemark>"


        strTmp = Cells(i, x)
        i = i + 1
    Wend

    objTF.writeline "    </Folder>"
    objTF.writeline "</Document>"
    objTF.writeline "</kml>"


    objTF.Close
    Set objFSO = Nothing
    MsgBox "Done!", vbOKOnly

End Sub

【问题讨论】:

    标签: excel geocoding kml google-earth vba


    【解决方案1】:

    在 KML 中使用 address> 元素,Google 地球会在其中自动为您对地址进行地理编码。

    <Placemark>
        <visibility>0</visibility>
        <address>6213 DUKE CIR Port ST Lucie, FL</address>
        <styleUrl>#pointStyleMap</styleUrl>             
    </Placemark>
    

    您可以使用&lt;address&gt; 标签来指定一个点的位置,而不是使用经纬度坐标。 (但是,如果提供了&lt;Point&gt;,则它优先于&lt;address&gt;。)

    此外,您不再需要 Schema 和 Adress SchemaData 元素,而是可以直接内联 BalloonStyle 文本中的 $[address] 字段:

    <BalloonStyle>
          <text><![CDATA[<table border="0">
              <tr><td><b>Adress</b></td><td>$[address]</td></tr>
              </table>]]>
          </text>
    </BalloonStyle>
    

    在 Google Earth 中加载 KML 文件并保存后,您会注意到 Google Earth 会将其更改为以下内容并填写坐标:

    <Placemark>
        <address>6213 DUKE CIR Port ST Lucie, FL</address>
        <styleUrl>#pointStyleMap</styleUrl>
        <MultiGeometry>
            <Point>
                <coordinates>-80.36086,27.366379,0</coordinates>
            </Point>
            <LinearRing>
                <coordinates>
                    -80.36086,27.366379,0 -80.36086,27.366379,0 -80.36086,27.366379,0 -80.36086,27.366379,0 -80.36086,27.366379,0 
                </coordinates>
            </LinearRing>
        </MultiGeometry>
    </Placemark>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 2017-06-17
      • 1970-01-01
      • 2011-03-15
      • 1970-01-01
      相关资源
      最近更新 更多