Create CSV2KML file to plot paths with sets of coordinates in CSV, using Python

244 Views Asked by At

I have the following csv file with Site A and Site B coordinates. I would like to plot a path between Site A and Site B using Python. The following is csv file.

    Site A          Site B  
Site A  Lat Long    Site B  Lat Long
PRGR     53.906969° -122.788618°    TABR     53.906319° -122.452036°
TABR     53.906319° -122.452036°    HIXN     53.470608° -122.630719°
HIXN     53.470608° -122.630719°    DRGN     52.883608° -122.339258°
DRGN     52.883608° -122.339258°    POTA     52.301208° -121.841503°
POTA     52.301208° -121.841503°    TIMO     51.904336° -121.251706°
LIME     51.093293° -121.665607°    SAVO     50.699822° -120.816183°
SAVO     50.699822° -120.816183°    IRON     50.047728° -120.757496°
IRON     50.047728° -120.757496°    TUK  50.464231° -119.581204°
IRON     50.047728° -120.757496°    THYN     49.702183° -120.922895°
TUK  50.464231° -119.581204°    SILV     50.369695° -119.063741°
TUK  50.464231° -119.581204°    RUTL     49.915597° -119.318128°
RUTL     49.915597° -119.318128°    KELW     49.876475° -119.451763°
TIMO     51.904336° -121.251706°    LIME     51.093293° -121.665607°

enter image description here

Here is my code but does not plot lines.

import csv
import simplekml


inputfile = csv.reader(open('FBCRN.csv',encoding="utf8", errors='ignore'))
kml=simplekml.Kml()
next(inputfile)
next(inputfile)

for row in inputfile:
    
    lin = kml.newlinestring(name=row[0], coords=[(row[2],row[1]), (row[5], row[4])])
    lin.style.linestyle.color = 'ff0000ff'  # Red
    lin.style.linestyle.width= 10  # 10 pixels    
kml.save('FBG.kml')
0

There are 0 best solutions below