我有一个包含lat / long的csv文件,如下所示
xx.xxxxx, yy.yyyyy
xx.xxxxx, yy.yyyyy
xx.xxxxx, yy.yyyyy
xx.xxxxx, yy.yyyyy
xx.xxxxx, yy.yyyyy
如何使用此csv文件在Google地球上绘制线条?
答案 0 :(得分:0)
您可以使用以下代码创建用于Google地图或Google地球的KML文件。它假定您的CSV文件名为yourCSV.csv
#!/bin/bash
# Output KML header
cat<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<Placemark>
<LineString>
<coordinates>
EOF
# Read in CSV and append a zero altitude to each line
sed s/$/,0.0/ yourCSV.csv
cat<<EOF
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
EOF
将其保存在名为CSV2KML
的文件中,然后执行此操作以使其可执行并运行它以生成名为mylines.kml
的文件:
chmod +x CSV2KML
./CSV2KML > mylines.kml
<强>输出:强>
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<Placemark>
<LineString>
<coordinates>
xx.xxxxx, yy.yyyyy,0.0
xx.xxxxx, yy.yyyyy,0.0
xx.xxxxx, yy.yyyyy,0.0
xx.xxxxx, yy.yyyyy,0.0
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
例如,如果您希望线条为红色,请更改最后一部分,使其如下所示:
</coordinates>
</LineString>
<Style>
<LineStyle>
<color>#ff0000ff</color>
</LineStyle>
</Style>
</Placemark>
</Document>
</kml>