项目作者: DSOlab

项目描述 :
Transform plain ascii points to kml Placemarks
高级语言: Python
项目地址: git://github.com/DSOlab/ascii2kml.git
创建时间: 2020-11-27T12:10:53Z
项目社区:https://github.com/DSOlab/ascii2kml

开源协议:MIT License

下载


ascii2kml

Transform plain ascii files to kml format

This is a dead simple python script to transform points recorded in plain ascii
format to Palcemarks in a valid KML document. The program will read points
(aka lines of code, latitude, longtitude) from STDIN and transform them to KML
Placemarks inside a KML document. For a description of the input file format,
see the file sample.ascii; the output of the script for this file is presented in the file sample.kml.

input format for data points

The program reads in points from STDIN; every line is considered a new
individual point. The points should follow the following convention:
CODE LATITUDE LONGTITUDE DESCRIPTION
where:

  • CODE is a name for the specific point; it will be interpreted as the
    Placemark’s name tag. In default mode, CODE must not contain whitespace
    characters
    . If it does (contain whitespaces and or tabs characters),
    then use the switch --name-w-spaces; this will trigger a different
    approach where the programm will interpret as CODE all columns starting from
    the first one up untill it finds a column that contains a float number. The
    latter is interpreted as latitude; everything before this column is
    interpreted as the CODE. E.g.
    046007 37.305266755 21.553844827 is ok, ‘046007’ is interpreted as CODE.
    Name With Spaces 37.794930591 22.817623263 is not ok in default mode. If
    we use the switch --name-w-spaces though, the program will interpret the
    string ‘Name With Spaces` as CODE.

  • LATITUDE is the latitude of the point. It must follow the CODE and follow
    a floating point format convention. Latitude should be given in decimal
    degrees.

  • LONGTITUDE is the longtitude of the point. It must follow the LATITUDE and follow
    a floating point format convention. Longtitude should be given in decimal
    degrees.

  • DESCRIPTION [optional] An optional description of the point which will be
    written in the Placemark’s description tag. Note that you must use the switch
    --description-after-col=N for the program to know that the string starting
    at column N to the end of line is a description (otherwise columns after
    LONGTITUDE will be ignored). Note that column numbering starts at column 0 and
    that if you specify the --name-w-spaces switch, the string interpreted as
    CODE will be counted as one column (whatever number of columns/whitespaces it
    contains). E.g. the line Name2 With Big Name 37.694930591 22.717623263 and it also has a description!
    with the command ascii2kml.py --description-after-col=3 --name-w-spaces will
    be interpreted as: Column[0] = CODE = 'Name2 With Big Name', Column[1] = LATITUDE = 37.694930591,
    Column[2] = LONGTITUDE = 22.717623263 and everything after column 3 is a
    description, Column[3 to EOL] = DESCRIPTION = 'and it also has a description!'.

For more information and usage, type:
$>./ascii2kml.py -h
to display the help message.

Example:

  1. $> cat sample.ascii
  2. 046006 38.305266755 22.553844827
  3. 047007 39.023304923 23.246122441 This is a description for the point with code "047007"
  4. 048052 37.594930591 22.617623263
  5. # this is a comment line, no problem!
  6. # this is also a comment line
  7. 046007 37.305266755 21.553844827
  8. Name With Spaces 37.794930591 22.817623263
  9. Name2 With Big Name 37.694930591 22.717623263 and it also has a description!
  10. This is an erronuous line
  11. Also an erronuous line 37.594930591
  12. # the following is also an erronuous line
  13. 37.594930591 22.617623263
  14. $> cat sample.ascii | ./ascii2kml.py \
  15. --document-name=foobar --description-after-col=3 \
  16. --name-w-spaces --ignore-error-lines
  17. <?xml version="1.0" encoding="UTF-8"?>
  18. <kml xmlns="http://www.opengis.net/kml/2.2">
  19. <Document>
  20. <name>foobar</name>
  21. <Placemark>
  22. <name>046006</name>
  23. <description></description>
  24. <Point><coordinates>22.553844827,38.305266755,0.0</coordinates></Point>
  25. </Placemark>
  26. <Placemark>
  27. <name>047007</name>
  28. <description>This is a description for the point with code "047007"</description>
  29. <Point><coordinates>23.246122441,39.023304923,0.0</coordinates></Point>
  30. </Placemark>
  31. <Placemark>
  32. <name>048052</name>
  33. <description></description>
  34. <Point><coordinates>22.617623263,37.594930591,0.0</coordinates></Point>
  35. </Placemark>
  36. <Placemark>
  37. <name>046007</name>
  38. <description></description>
  39. <Point><coordinates>21.553844827,37.305266755,0.0</coordinates></Point>
  40. </Placemark>
  41. <Placemark>
  42. <name>Name With Spaces</name>
  43. <description></description>
  44. <Point><coordinates>22.817623263,37.794930591,0.0</coordinates></Point>
  45. </Placemark>
  46. <Placemark>
  47. <name>Name2 With Big Name</name>
  48. <description>and it also has a description!</description>
  49. <Point><coordinates>22.717623263,37.694930591,0.0</coordinates></Point>
  50. </Placemark>
  51. </Document>
  52. </kml>