<legend id='sSsf3'><style id='sSsf3'><dir id='sSsf3'><q id='sSsf3'></q></dir></style></legend>

<tfoot id='sSsf3'></tfoot>
  • <i id='sSsf3'><tr id='sSsf3'><dt id='sSsf3'><q id='sSsf3'><span id='sSsf3'><b id='sSsf3'><form id='sSsf3'><ins id='sSsf3'></ins><ul id='sSsf3'></ul><sub id='sSsf3'></sub></form><legend id='sSsf3'></legend><bdo id='sSsf3'><pre id='sSsf3'><center id='sSsf3'></center></pre></bdo></b><th id='sSsf3'></th></span></q></dt></tr></i><div id='sSsf3'><tfoot id='sSsf3'></tfoot><dl id='sSsf3'><fieldset id='sSsf3'></fieldset></dl></div>

          <bdo id='sSsf3'></bdo><ul id='sSsf3'></ul>
      1. <small id='sSsf3'></small><noframes id='sSsf3'>

      2. 在 Python 中从 csv 创建 kml

        时间:2023-09-28
          • <bdo id='nSfuv'></bdo><ul id='nSfuv'></ul>

          • <i id='nSfuv'><tr id='nSfuv'><dt id='nSfuv'><q id='nSfuv'><span id='nSfuv'><b id='nSfuv'><form id='nSfuv'><ins id='nSfuv'></ins><ul id='nSfuv'></ul><sub id='nSfuv'></sub></form><legend id='nSfuv'></legend><bdo id='nSfuv'><pre id='nSfuv'><center id='nSfuv'></center></pre></bdo></b><th id='nSfuv'></th></span></q></dt></tr></i><div id='nSfuv'><tfoot id='nSfuv'></tfoot><dl id='nSfuv'><fieldset id='nSfuv'></fieldset></dl></div>

                <tfoot id='nSfuv'></tfoot>

                  <tbody id='nSfuv'></tbody>
              • <small id='nSfuv'></small><noframes id='nSfuv'>

                  <legend id='nSfuv'><style id='nSfuv'><dir id='nSfuv'><q id='nSfuv'></q></dir></style></legend>
                  本文介绍了在 Python 中从 csv 创建 kml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Python 新手.我正在处理 gps 文件.我需要将包含所有 gps 数据的 CSV 文件转换为 kml 文件.下面是我正在使用的python中的代码:

                  I am new to Python. I am working on gps files. I need to convert a CSV file having all the gps data to kml file. Below is the code in python I am using :

                  import csv
                  #Input the file name.
                  fname = raw_input("Enter file name WITHOUT extension: ")
                  data = csv.reader(open(fname + '.csv'), delimiter = ',')
                  #Skip the 1st header row.
                  data.next()
                  #Open the file to be written.
                  f = open('csv2kml.kml', 'w')
                  
                  #Writing the kml file.
                  f.write("<?xml version='1.0' encoding='UTF-8'?>
                  ")
                  f.write("<kml xmlns='http://earth.google.com/kml/2.1'>
                  ")
                  f.write("<Document>
                  ")
                  f.write("   <name>" + fname + '.kml' +"</name>
                  ")
                  for row in data:
                      f.write("   <Placemark>
                  ")
                      f.write("       <name>" + str(row[1]) + "</name>
                  ")
                      f.write("       <description>" + str(row[0]) + "</description>
                  ")
                      f.write("       <Point>
                  ")
                      f.write("           <coordinates>" + str(row[3]) + "," + str(row[2]) + "," + str(row[4]) + "</coordinates>
                  ")
                      f.write("       </Point>
                  ")
                      f.write("   </Placemark>
                  ")
                  f.write("</Document>
                  ")
                  f.write("</kml>
                  ")
                  print "File Created. "
                  print "Press ENTER to exit. "
                  raw_input()
                  

                  我使用的 csv 文件可在此处获得:dip12Sep11newEdited.csv生成的 kml 文件可在此处获得:csv2kml.kml但是没有正确创建 kml 文件.显然,在 csv 中的某些行之后,代码无法生成更多地标.它无法迭代.您可以通过滚动到生成的 kml 文件的最后部分来查看.

                  The csv file I am using is available here : dip12Sep11newEdited.csv The kml file generated is available here : csv2kml.kml But the kml file is not getting created correctly. Apparently after some rows in the csv the code is not able to generate more Placemarks. Its not able to iterate. You can see that by scrolling to the last part of the kml file generated.

                  谁能帮我找出代码中的错误,因为对于一些较小的 csv 文件,它可以正常工作并完全创建 kml 文件.

                  Can anyone help me finding out the error in the code, because for some smaller csv files it worked correctly and created kml files fully.

                  谢谢.

                  推荐答案

                  你没有回答上面的问题,但我猜错误是你没有关闭你的输出文件(这会刷新你的输出).

                  You didn't answer the query above, but my guess is that the error is that you're not closing your output file (which would flush your output).

                  f.close()
                  

                  这篇关于在 Python 中从 csv 创建 kml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:你会为 python 推荐哪个 gps 库? 下一篇:python:找到围绕某个 GPS 位置的圆的 GPS 坐标的优雅方法

                  相关文章

                  <i id='iygBo'><tr id='iygBo'><dt id='iygBo'><q id='iygBo'><span id='iygBo'><b id='iygBo'><form id='iygBo'><ins id='iygBo'></ins><ul id='iygBo'></ul><sub id='iygBo'></sub></form><legend id='iygBo'></legend><bdo id='iygBo'><pre id='iygBo'><center id='iygBo'></center></pre></bdo></b><th id='iygBo'></th></span></q></dt></tr></i><div id='iygBo'><tfoot id='iygBo'></tfoot><dl id='iygBo'><fieldset id='iygBo'></fieldset></dl></div>

                  1. <small id='iygBo'></small><noframes id='iygBo'>

                        <bdo id='iygBo'></bdo><ul id='iygBo'></ul>
                    1. <tfoot id='iygBo'></tfoot>
                    2. <legend id='iygBo'><style id='iygBo'><dir id='iygBo'><q id='iygBo'></q></dir></style></legend>