May-08-2018, 06:50 PM
(This post was last modified: May-08-2018, 06:50 PM by disruptfwd8.)
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
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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.