Esempio n. 1
0
def getvector(request):
    assert isinstance(request, HttpRequest)
    json_request = json.dumps(request.GET)
    try:
        table = request.GET.get('table',None)
        glName = request.GET.get('name',None)
        glName += " Glacier"
        body = cache.blobstore.get_blob_to_bytes('ice2ocean',json_request)
        response = HttpResponse(body,'text/xml')
    except:
        try:
            if 'moderncenterlines' in table:
                query = """SELECT ST_AsText(ST_Transform(geom,4246)) FROM %s WHERE glimsid IN (SELECT glimsid FROM modern WHERE name = '%s')""" %(table, glName)
            else:
                query = """SELECT ST_AsText(ST_Transform(geom,4246)) FROM %s WHERE name = '%s'""" %(table, glName)
            ds = b.fetch_query(query)
            # Kilroy: switch to shapely
            # AAA: this is to accommodate 
 #           poly = geometry.from_wkt(ds[0][0])
 #           for p in poly.geoms:
 #               e = p.exterior
 #               for i in range(0,len(e.coords),20):
 #                   lat = e.coords[i][1]
 #                   lon = e.coords[i][0]
 #           response = HttpResponse(ds[0][0],content_type = "text/plain")
 #           print 'past response'
 #           return response
        except:
            print ""
            a.message
            return cr.invalid_parameter()
Esempio n. 2
0
def gettimeseries(request):
    assert isinstance(request, HttpRequest)
    json_request = json.dumps(request.GET)
    try:
        table = request.GET.get('table',None)
        mascon = request.GET.get('mascon',None)
        location = request.GET.get('location',None)
        version = request.GET.get('version',None) 
        region = request.GET.get('region',None)
        glacier = request.GET.get('glacier',None)
        collection = request.GET.get('collection',None)
        body = cache.blobstore.get_blob_to_bytes('ice2ocean',json_request)
        response = HttpResponse(body,'text/xml')
    except:
        try:
            if 'GRACE' in table:
                if mascon <> None:
                    query = """SELECT main.date, SUM(main.values_filter1d * cf.correction) FROM
                        (SELECT mascon, (area_km2 / 1e5) AS correction FROM mascon_fit WHERE mascon=%s) as cf LEFT JOIN
                        (SELECT mascon, date, values_filter1d from mascon_solution where version = %s) as main
                        ON cf.mascon = main.mascon GROUP BY date ORDER BY date;""" %(mascon,version)
                else:
                    query = """SELECT main.date, SUM(main.values_filter1d * cf.correction) FROM
                        (SELECT mascon, (area_km2 / 1e5) AS correction FROM mascon_fit WHERE region=%s) as cf LEFT JOIN
                        (SELECT mascon, date, values_filter1d from mascon_solution where version = %s) as main
                        ON cf.mascon = main.mascon GROUP BY date ORDER BY date;""" %(region,version)
            elif 'streamgauges' in table:
                query = """SELECT date, gaugeid, discharge FROM streamgauge_data WHERE gaugeid IN  
                          (SELECT gaugeid from streamgauges where name ~ %s) ORDER BY date""" %(location)
            elif 'pointbalances' in table:
                query = """SELECT start_date, end_date, stake, elevation, balance, 
                           ST_AsText(ST_Transform(geom,4246)) FROM point_balances 
                           WHERE name = %s ORDER BY start_date""" %(glacier)
            elif 'snowradar' in table:
                query = """SELECT s.gid, s.elevation, s.geom, s.swe FROM snowradar AS s,
                          snowradar_lines AS line WHERE line.collection = %s 
                          AND ST_Intersects(line.geom, s.geom) ORDER BY s.elevation""" %(collection)
            print(query)
            ds = b.fetch_query(query)
            response = HttpResponse(mimetype = 'text/csv')
            ds.to_csv(response)
            return response
        except:
            print ""
            a.message
            return cr.invalid_parameter()