0

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')
Grismar
  • 27,561
  • 4
  • 31
  • 54
Kourosh
  • 51
  • 9
  • No images please. Update **text**. What is the question? – balderman Sep 22 '21 at 08:26
  • Create a KML file to plot a path between siteA coordinates and Site B coordinates. There is a problem with my code which does not create the lines. I will add the csv file. – Kourosh Sep 22 '21 at 18:09
  • Note that what you included as data is not csv, it appears to be either tab-delimited or some fixed width format which got mangled. – Grismar Sep 22 '21 at 22:17
  • 1
    Without a copy of the start of the actual file, it's hard to say what exactly your problem is, but perhaps the issue is that you're providing string values, including a degrees symbol. If I just use the relevant parts of your code for the first line of data (removing the ° symbol), I get a line in British Columbia, which is what you expect, I assume. – Grismar Sep 22 '21 at 22:24
  • Yes, the code is correctr, tested after the degree symboles were removed. Thanks. – Kourosh Sep 22 '21 at 23:22

0 Answers0