嗨,我有以下代码。
import csv
import math
EASTING_BASE = 500
NORTHING_BASE = 500
def main():
global NORTHING_BASE
global EASTING_BASE
for i, a in getStationCoords():
statione = int(i)
stationn = int(a)
print statione,stationn
stationEasting = int(getStationCoords()[0][0])
stationNorthing = int(getStationCoords()[0][1])
for i in range(0, len(eastingList)):
print "Co-ordinates (" + str(eastingList[i]) + "," + str(northingList[i]) + ")"
print calculateDistance(NORTHING_BASE, EASTING_BASE, northingList[i], eastingList[i])
print calculateBearing(NORTHING_BASE, EASTING_BASE, northingList[i], eastingList[i])
def getStationCoords():
listStation = []
a_reader = None
a_reader = open('data.csv', 'rU')
a_csv_reader = csv.reader(a_reader)
a_csv_reader.next()
for i in [row[-2:] for row in a_csv_reader]:
listStation.append(i)
a_reader.close()
count = 0
sum = 0.0
a_reader = open('data.csv', 'rU')
a_csv_reader = csv.reader(a_reader)
#for row in a_csv_reader:
# if count != 0 and row[0] != '':
# sum = sum + float(row[0])
# count = count + 1
#print 'Number of lines is:',count
#print 'Sum is:',sum
return listStation
def main2():
global NORTHING_BASE
global EASTING_BASE
eastingList = []
northingList = []
def calculateDistance(northingOne, eastingOne, northingTwo, eastingTwo):
# Determine differences in eastings and northings
deltaEasting = eastingTwo - eastingOne
deltaNorthing = northingTwo - northingOne
# We don't need to worry about +/- as using pythag below
distance = (deltaEasting **2 + deltaNorthing **2) **0.5
# Return the value for distance
return distance
def calculateBearing(northingOne, eastingOne, northingTwo, eastingTwo):
diffEasting = eastingTwo - eastingOne
diffNorthing = northingTwo - northingOne
# Work out if in QI/II or QIII/IV
if diffEasting >= 0:
# This is in QI/II
if diffNorthing >0:
# This is in QI
bearing = math.atan(diffEasting / diffNorthing)
else:
# This is in QII
bearing = math.pi - math.atan(diffEasting / abs(diffNorthing))
else:
# This is in QIII/IV
if diffNorthing >0:
# This is in QIV
bearing = 2 * math.pi - math.atan(abs(diffEasting) / diffNorthing)
else:
# This is in QIII
bearing = math.pi + math.atan(abs(diffEasting) / abs(diffNorthing))
# Return the value
return bearing
main2()
main()
好的,所以我知道我必须在东移和北移列表中放置值。以下。我的第一个函数 main() 产生以下
476050 7709929
473971 7707713
465676 7691097
515612 7702192
516655 7704405
519788 7713255
538466 7683341
我被困的地方是如何将这些东移(左)和北移(右)的值放入东移和北移列表中。有人可以帮忙吗,因为我完全不确定如何让他们进入 main2() 中的东向和北向列表
另外,我是否通过从东移和北移列表中调用东移和北移值来正确实现该功能?
任何帮助深表感谢。