Exemplo n.º 1
0
def areas():
    ''' Retrieve geographic areas.
    '''
    is_census = is_census_datasource(environ)

    lat = float(request.args['lat'])
    lon = float(request.args['lon'])

    include_geom = bool(request.args.get('include_geom', True))
    json_callback = request.args.get('callback', None)

    layer_names = is_census and request.args.get('layers', '')
    layer_names = layer_names and set(layer_names.split(','))

    # This. Is. Python.
    ogr.UseExceptions()

    point = ogr.Geometry(wkt='POINT(%f %f)' % (lon, lat))

    if is_census:
        features = census_features(point, include_geom, layer_names)

    else:
        datasource = get_datasource(environ)
        features = get_intersecting_features(datasource, point, include_geom)

    body, mime = features_geojson(features, json_callback)

    return Response(body, headers={'Content-type': mime, cors: '*'})
Exemplo n.º 2
0
def areas():
    ''' Retrieve geographic areas.
    '''
    is_census = is_census_datasource(environ)
    
    lat = float(request.args['lat'])
    lon = float(request.args['lon'])

    include_geom = bool(request.args.get('include_geom', True))
    json_callback = request.args.get('callback', None)

    layer_names = is_census and request.args.get('layers', '')
    layer_names = layer_names and set(layer_names.split(','))
    
    # This. Is. Python.
    ogr.UseExceptions()
    
    point = ogr.Geometry(wkt='POINT(%f %f)' % (lon, lat))

    if is_census:
        features = census_features(point, include_geom, layer_names)
    
    else:
        datasource = get_datasource(environ)
        features = get_intersecting_features(datasource, point, include_geom)
    
    body, mime = features_geojson(features, json_callback)
    
    return Response(body, headers={'Content-type': mime, cors: '*'})
Exemplo n.º 3
0
    except QueryError, e:
        body, mime = json_encode({'error': str(e)}), 'application/json'

        if json_callback:
            body = '%s(%s);\n' % (json_callback, body)
            mime = 'text/javascript'

        return Response(body,
                        status=400,
                        headers={
                            'Content-type': mime,
                            cors: '*'
                        })

    else:
        body, mime = features_geojson(features, json_callback)
        return Response(body, headers={'Content-type': mime, cors: '*'})


@app.errorhandler(404)
def error_404(error):
    return render_template('error.html', error=str(error))


@app.route('/datasource.zip')
def download_zip():
    if is_census_datasource(environ):
        error = "Can't download all of " + census_url
        return Response(render_template('error.html', error=error), status=404)

    buffer = StringIO()
Exemplo n.º 4
0
    
    try:
        datasource = get_datasource(environ)
        features = get_matching_features(datasource, where_clause, page_number, include_geom)

    except QueryError, e:
        body, mime = json_encode({'error': str(e)}), 'application/json'

        if json_callback:
            body = '%s(%s);\n' % (json_callback, body)
            mime = 'text/javascript'

        return Response(body, status=400, headers={'Content-type': mime, cors: '*'})
    
    else:
        body, mime = features_geojson(features, json_callback)
        return Response(body, headers={'Content-type': mime, cors: '*'})

@app.errorhandler(404)
def error_404(error):
    return render_template('error.html', error=str(error))

@app.route('/datasource.zip')
def download_zip():
    if is_census_datasource(environ):
        error = "Can't download all of " + census_url
        return Response(render_template('error.html', error=error), status=404)
    
    buffer = StringIO()
    archive = ZipFile(buffer, 'w', ZIP_DEFLATED)
    archive.write('datasource.shp')