こんにちは、次のコードがあります。
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() にある東座標と北座標のリストにそれらを入れる方法が完全にわからないので、誰かがこれを手伝ってくれますか?
また、東座標と北座標のリストから東座標と北座標の値を呼び出して、関数を正しく実装していますか?
どんな助けでも大歓迎です。