Ejemplo n.º 1
0
def getFilteredNeighbors(station,topoThresh=TOPO_THRESHOLD,elevThresh=ELEV_THRESHOLD):
    # Get nearby stations
    # t0neighborQuery = datetime.now()
    neighborQuery = stations.find({
            "_id":{"$ne":station['_id']},
            "loc":{"$near":{"$geometry":station['loc'],
               "$maxDistance":DISTANCE_THRESHOLD}
              }
        },
        {
            "loc":1
        })#.limit(5)
    t0NeighborLoop = datetime.now()
    # dt = datetime.now() - t0neighborQuery
    # print("Neighbor query: %.6fs"%dt.total_seconds())
    neighbors = []
    filteredNeighbors=[]
    if neighborQuery.count()==np.nan:
        print "Station %s has no nearby stations."%station['_id']
    else:
        # print "%s's %i nearby stations:"%(station['_id'],neighborQuery.count())
        c0 = station['loc']['coordinates']
        stationLoc = LatLon(c0[1],c0[0])
        neighborCount = 0
        for neighbor in neighborQuery:
            neighbors.append(neighbor)
            neighborCount+=1
            c1 = neighbor['loc']['coordinates']
            neighborLoc = LatLon(c1[1],c1[0])
            # t0topoQuery = datetime.now()
            elevProfile = np.array(getElevationProfile(stationLoc.lon.decimal_degree,
                                                       stationLoc.lat.decimal_degree,
                                                       neighborLoc.lon.decimal_degree,
                                                       neighborLoc.lat.decimal_degree))
            elevs=elevProfile[:,2]
            #print (elevProfile)
            relativePeakHeight = elevs.max() \
                - np.max([elevs[0],elevs[-1]])
            neighbor['distance'] = stationLoc.distance(neighborLoc)
            # print(neighbor['_id'], elevs.max(),relativePeakHeight,dist)
            elevDiff = abs(elevs[0]-elevs[-1])
            if relativePeakHeight<topoThresh and elevDiff < elevThresh:
                filteredNeighbors.append(neighbor)
        #print("StationLoop: %i stations, %.6fs"%(neighborCount,(datetime.now()-t0NeighborLoop).total_seconds()))
        return filteredNeighbors, neighbors
Ejemplo n.º 2
0
 def do_GET(s):
     """Respond to a GET request."""
     req = urlparse(s.path)
     if req.path.startswith('/index.html'):
         s.send_response(200)
         s.send_header("Content-type", "text/html")
         s.end_headers()
         s.wfile.write(open('public/index.html').read())
     elif req.path.startswith('/elevationProfile'):
         query = parse_qs(req.query)
         try:
             elevProfile = getElevationProfile(
                 float(query['lon0'][0]),
                 float(query['lat0'][0]),
                 float(query['lon1'][0]),
                 float(query['lat1'][0]))
         except:
             s.send_response(500)
             return
         max = -9999
         min = 9000000
         for x,y,z in elevProfile:
             if z > max: max = z
             if z > -999 and z < min: min = z
         elevProfile = [{"lon":x,"lat":y,"elev":float(z)} for x,y,z in elevProfile]
         resp = {
             "maxElevation": float(max),
             "minElevation": float(min),
             "units": 'meters',
             "points": elevProfile
         }
         s.send_response(200)
         s.send_header("Content-type", "application/json")
         s.end_headers()
         s.wfile.write(json.dumps(resp))
     elif req.path.startswith('/getElevation'):
         query = parse_qs(req.query)
         try:
             lon,lat=(query['lon'][0],query['lat'][0])
             elev = getElevation(lon,lat)
         except:
             s.send_response(500)
             return
         resp = {
             "elev": float(elev),
             "lat": float(lat),
             "lon": float(lon),
             "units": 'meters'
         }
         s.send_response(200)
         s.send_header("Content-type", "application/json")
         s.end_headers()
         s.wfile.write(json.dumps(resp))
     elif req.path.startswith('/getFilteredNeighbors'):
         query = parse_qs(req.query)
         try:
             stationId = query['stationId'][0]
             topoThresh = query['topoThresh']
             if len(topoThresh)>0: topoThresh = float(topoThresh[0])/FEET_PER_METER
             elevThresh = query['elevThresh']
             if len(elevThresh)>0: elevThresh = float(elevThresh[0])/FEET_PER_METER
             station = stations.find_one({
                 "_id":stationId
             },{
                 "loc":1
             })
         except:
             s.send_response(500)
             return
         if station:
             filteredNeighbors, neighbors = getFilteredNeighbors(station,topoThresh=topoThresh,elevThresh=elevThresh)
             resp={"station":station,
                   "filteredNeighbors":filteredNeighbors,
                   "neighbors":neighbors
                   }
         else: resp={}
         s.send_response(200)
         s.send_header("Content-type", "application/json")
         s.end_headers()
         s.wfile.write(json.dumps(resp))
     else:
         s.send_response(500)
Ejemplo n.º 3
0
import argparse, json
from GTOPO30 import getElevationProfile
from LatLon import LatLon

parser = argparse.ArgumentParser(description='Get elevation profile for a line between two points.')
parser.add_argument('--lat0', dest='lat0', action='store', type=float, default = -999)
parser.add_argument('--lon0', dest='lon0', action='store', type=float, default = -999)
parser.add_argument('--lat1', dest='lat1', action='store', type=float, default = -999)
parser.add_argument('--lon1', dest='lon1', action='store', type=float, default = -999)
args=parser.parse_args()

p0 = LatLon(args.lat0,args.lon0)
p1 = LatLon(args.lat1,args.lon1)
elevProfile = getElevationProfile(float(args.lon0),float(args.lat0),float(args.lon1),float(args.lat1))
elevProfile = [{"lon":x,"lat":y,"elev":float(z)} for x,y,z in elevProfile]
print json.dumps(elevProfile)