Changeset 5424 for cows/trunk/cows/service/imps/StationCollection.py
 Timestamp:
 25/06/09 15:11:22 (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cows/trunk/cows/service/imps/StationCollection.py
r4912 r5424 36 36 37 37 def getNearestStation(self,lat,lon): 38 38 ''' Determines the station nearest to the given geospatial point in the station collection ''' 39 39 40 41 40 curNearest=None 41 curDist = 1 42 42 43 44 45 46 47 48 49 50 43 for station in self.stations: 44 #calculate distance 45 tempDist = self.getDist(lat, lon, station.lat, station.lon) 46 #if distance is smaller than the current shortest distance 47 if curDist < 0 or tempDist < curDist: 48 curNearest = station 49 curDist = tempDist 50 return curNearest 51 51 52 52 53 53 def getDist(self, srcLat, srcLon, destLat, destLon): 54 '''Calculates the distance between to geospatial points''' 55 56 57 58 54 '''Calculates the distance between to geospatial points''' 55 dlon = destLon  srcLon 56 dlat = destLat  srcLat 57 #a = (math.sin(dlat / 2))**2 + math.cos(srcLat) * math.cos(destLat) * (math.sin(dlon / 2))**2 58 #c = 2 * math.asin(min(1, math.sqrt(a))) 59 59 #dist = 3956 * c 60 61 62 63 60 dist = math.sqrt(dlat**2 + dlon**2) 61 return dist 62 63
Note: See TracChangeset
for help on using the changeset viewer.