Python Forum

Full Version: map great circle routes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Need help finding out why I'm getting an error. Here the data from the CSV file:
olat,olon,dlat,dlon,route
41.48,-81.8,39.96,-75.2,1
36.09,-115.38,42.38,-71.14,2
34,-84.47,42.38,-71.14,3
40.85,-73.91,34.12,-117.71,4
25.7,-80.4,41.31,-72.92,5
42.9,-112.39,41.78,-87.6,6
37.78,-122.24,34.07,-118.44,7
33.59,-112.1,42.37,-71.11,8
36.11,-115.27,42.37,-71.11,9
44.47,-69.29,41.31,-72.92,10
35.69,-108.98,37.41,-122.17,11
13.53,144.88,29.72,-95.42,12
42.31,-88.43,34.02,-118.29,13
35.26,-96.93,35.21,-97.44,14
36.09,-111.13,43.7,-72.27,15
34,-84.47,42.38,-71.14,16
36.11,-115.27,42.37,-71.11,17
38.84,-94.78,37.87,-122.25,18
40.58,-73.95,40.81,-73.95,19
33.61,-84.49,40.81,-73.95,20

# impoprt packages:
from geographiclib.geodesic import Geodesic
import pandas as pd
from lxml import etree as ET

# set up kml structure:
kml = ET.Element('kml')
document = ET.SubElement(kml, 'Document')

# read data
df = pd.read_csv('datapoints.csv')

# loop through routes, calculate waypoints:

for x in (df.index):
    olat = df.iloc[x,1]
    olon = df.iloc[x,2]
    dlat = df.iloc[x,3]
    dlon = df.iloc[x,4]
    route = df.iloc[x,5]

    p = Geodesic.WGS84.Inverse(olat, olon, dlat, dlon)
    l = Geodesic.WGS84.Line(p['lat1'], p['lon1'], p['azi1'])
    if (p['s12'] >= 1000000):
        num = int(p['s12'] / 100000)  # number of waypoints depending on length
    else:
        num = 10
    output = ''
    for i in range(num + 1):
        b = l.Position(i * p['s12'] / num, Geodesic.STANDARD | Geodesic.LONG_UNROLL)
        output += repr(b['lon2']) + "," + repr(b['lat2']) + ",0 "
    # print(str(x)+"/"+str(len(df))) #progess counter

    # inner part of kml file:
    placemark = ET.SubElement(document, 'Placemark')
    name = ET.SubElement(placemark, 'name')
    name.text = route
    description = ET.SubElement(placemark, 'description')
    description.text = 'route ID: ' + str(x) + '; distance: ' + str(p['s12'])
    linestring = ET.SubElement(placemark, 'LineString')
    coordinates = ET.SubElement(linestring, 'coordinates')
    coordinates.text = output

# complete kml file and save:
tree = ET.ElementTree(kml)
tree.write('wfdistance.kml', pretty_print=True, xml_declaration=True, encoding="utf-8")
Error:
line 20, in <module> route = df.iloc[x,5]
Error:
Unresolved attribute reference 'WGS84' for class 'Geodesic'
Please help.
(May-08-2018, 06:50 PM)disruptfwd8 Wrote: [ -> ]Unresolved attribute reference 'WGS84' for class 'Geodesic'
(May-08-2018, 06:50 PM)disruptfwd8 Wrote: [ -> ]p = Geodesic.WGS84.Inverse(olat, olon, dlat, dlon)

The error is telling you that Geodesic doesn't have a WG584. The docs seem to agree.

So... what are you trying to do there?
Thank you nilamo

I'm trying to replicate this code and it doesn't seem to work for me.

https://public.tableau.com/en-us/s/blog/...ableau-104

Python Code: https://public.tableau.com/s/sites/defau...iccalc.zip

What am i doing wrong?