예제 #1
0
파일: views.py 프로젝트: zstumgoren/census
def data_as_json(request, geoids):
    tables = get_tables_for_request(request) 

    geographies = {}

    geoids_list = filter(lambda g: bool(g), geoids.split(','))

    for g in utils.fetch_geographies(geoids_list):
        del g['xrefs']

        for table in g["data"]["2010"].keys():
            if table not in tables:
                del g["data"]["2010"][table]

                # Not all data has 2000 values
                try:
                    del g["data"]["2000"][table]
                    del g["data"]["delta"][table]
                    del g["data"]["pct_change"][table]
                except KeyError:
                    continue

        geographies[g['geoid']] = g
        
    return HttpResponse(simplejson.dumps(geographies), mimetype='application/json')
예제 #2
0
def data_as_json(request, geoids):
    tables = get_tables_for_request(request)

    geographies = {}

    geoids_list = filter(lambda g: bool(g), geoids.split(','))

    for g in utils.fetch_geographies(geoids_list):
        del g['xrefs']

        for table in g["data"]["2010"].keys():
            if table not in tables:
                del g["data"]["2010"][table]

                # Not all data has 2000 values
                try:
                    del g["data"]["2000"][table]
                    del g["data"]["delta"][table]
                    del g["data"]["pct_change"][table]
                except KeyError:
                    continue

        geographies[g['geoid']] = g

    return HttpResponse(simplejson.dumps(geographies),
                        mimetype='application/json')
예제 #3
0
파일: views.py 프로젝트: zstumgoren/census
def data_as_kml(request, geoids, format='kml'):
    tables = get_tables_for_request(request) 

    geoid_list = filter(lambda g: bool(g), geoids.split(','))
    boundaries = dict((b.external_id, b) for b in Boundary.objects.filter(external_id__in=geoid_list))
    json_data = dict((j['geoid'], j) for j in utils.fetch_geographies(geoid_list))
    labelset = mongoutils.get_labelset()
    
    placemarks = [
        _create_placemark_dict(boundaries[geoid], json_data[geoid], tables, labelset) for geoid in geoid_list
    ] 

    if format == 'kmz':
        render = render_to_kmz
    else:
        render = render_to_kml

    return render('gis/kml/placemarks.kml', {'places' : placemarks})            
예제 #4
0
파일: views.py 프로젝트: zstumgoren/census
def data_as_csv(request, geoids):
    tables = get_tables_for_request(request) 
    labelset = mongoutils.get_labelset()

    response = HttpResponse(mimetype="text/csv")
    w = csv.writer(response)
    w.writerow(_csv_row_header(tables, labelset))

    geoids_list = filter(lambda g: bool(g), geoids.split(','))

    for g in utils.fetch_geographies(geoids_list):
        csvrow = _csv_row_for_geography(g, tables, labelset)
        w.writerow(csvrow)

    now = datetime.now()
    date_string = "%s-%s-%s-%s" % (now.year, now.month, now.day, now.microsecond)
    response['Content-Disposition'] = "attachment; filename=ire-census-%s.csv" % date_string

    return response
예제 #5
0
def data_as_csv(request, geoids):
    tables = get_tables_for_request(request)
    labelset = mongoutils.get_labelset()

    response = HttpResponse(mimetype="text/csv")
    w = csv.writer(response)
    w.writerow(_csv_row_header(tables, labelset))

    geoids_list = filter(lambda g: bool(g), geoids.split(','))

    for g in utils.fetch_geographies(geoids_list):
        csvrow = _csv_row_for_geography(g, tables, labelset)
        w.writerow(csvrow)

    now = datetime.now()
    date_string = "%s-%s-%s-%s" % (now.year, now.month, now.day,
                                   now.microsecond)
    response[
        'Content-Disposition'] = "attachment; filename=ire-census-%s.csv" % date_string

    return response
예제 #6
0
def data_as_kml(request, geoids, format='kml'):
    tables = get_tables_for_request(request)

    geoid_list = filter(lambda g: bool(g), geoids.split(','))
    boundaries = dict(
        (b.external_id, b)
        for b in Boundary.objects.filter(external_id__in=geoid_list))
    json_data = dict(
        (j['geoid'], j) for j in utils.fetch_geographies(geoid_list))
    labelset = mongoutils.get_labelset()

    placemarks = [
        _create_placemark_dict(boundaries[geoid], json_data[geoid], tables,
                               labelset) for geoid in geoid_list
    ]

    if format == 'kmz':
        render = render_to_kmz
    else:
        render = render_to_kml

    return render('gis/kml/placemarks.kml', {'places': placemarks})