Exemplo n.º 1
0
def areas():
    lat = float(request.args['lat'])
    lon = float(request.args['lon'])

    include_geom = bool(request.args.get('include_geom', True))
    pretty = bool(request.args.get('pretty', False))
    json_callback = request.args.get('callback', None)
    
    # This. Is. Python.
    ogr.UseExceptions()
    
    features = []
    point = ogr.Geometry(wkt='POINT(%f %f)' % (lon, lat))
    args = point, include_geom

    #
    # Look at four files in turn
    #
    for (dataname, shpname, zipname) in filenames:
        features += get_intersecting_features(ogr.Open(shpname), dataname, *args)

    geojson = dict(type='FeatureCollection', features=features)
    body, mime = json_encode(geojson, pretty=pretty), 'application/json'
    
    if json_callback:
        body = '%s(%s);\n' % (json_callback, body)
        mime = 'text/javascript'
    
    return Response(body, headers={'Content-type': mime})
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)
    
    geojson = dict(type='FeatureCollection', features=features)
    body, mime = json_encode(geojson), 'application/json'
    
    if json_callback:
        body = '%s(%s);\n' % (json_callback, body)
        mime = 'text/javascript'
    
    return Response(body, headers={'Content-type': mime, 'Access-Control-Allow-Origin': '*'})
Exemplo n.º 3
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.º 4
0
def select():
    ''' Retrieve features.
    '''
    if is_census_datasource(environ):
        error = "Can't select individual features from " + census_url
        return Response(render_template('error.html', error=error), status=404)

    where_clause = request.args.get('where', None)
    where_clause = where_clause and str(where_clause)
    
    page_number = int(request.args.get('page', 1))
    
    include_geom = bool(request.args.get('include_geom', True))
    json_callback = request.args.get('callback', None)

    # This. Is. Python.
    ogr.UseExceptions()
    
    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: '*'})
Exemplo n.º 5
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.º 6
0
def status():
    datasource = get_datasource(environ)
    
    status = {
        'status': 'ok' if bool(datasource) else 'Bad datasource: %s' % repr(datasource),
        'updated': int(time()),
        'dependencies': [],
        'resources': {}
        }

    body = json_encode(status)

    return Response(body, headers={'Content-type': 'application/json', cors: '*'})
Exemplo n.º 7
0
def status():
    datasource = get_datasource(environ)

    status = {
        'status':
        'ok' if bool(datasource) else 'Bad datasource: %s' % repr(datasource),
        'updated':
        int(time()),
        'dependencies': [],
        'resources': {}
    }

    body = json_encode(status)

    return Response(body,
                    headers={
                        'Content-type': 'application/json',
                        cors: '*'
                    })
Exemplo n.º 8
0
def select():
    ''' Retrieve features.
    '''
    if is_census_datasource(environ):
        error = "Can't select individual features from " + census_url
        return Response(render_template('error.html', error=error), status=404)

    where_clause = request.args.get('where', None)
    where_clause = where_clause and str(where_clause)

    page_number = int(request.args.get('page', 1))

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

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

    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: '*'
                        })
Exemplo n.º 9
0
 def show_component(self, name):
     self.save()
     self.clear()
     config = self.ctx.getConfig()
     component = config.getComponent(name)
     self.name = (name,)
     type = component.getAttribute('type')
     template_params = util.dictify(config.getTemplateParams(type))        
     params = config.getParams(component)
     self.widget.resize(len(params)+4, 2)
     
     i = 0        
     label = gtk.Label('name')
     label.set_alignment(0.,0.5)
     self.widget.attach(label, 0, 1, i, i+1, ypadding=PROPERTIES_YPAD)                
     self.button = gtk.Button()
     self.button.set_label(name)
     self.button.connect('clicked', self.eventRename)
     self.widget.attach(self.button, 1, 2, i, i+1, xpadding=PROPERTIES_XPAD, ypadding=PROPERTIES_YPAD)
     i += 1
     
     label = gtk.Label('type')
     label.set_alignment(0.,0.5)
     self.widget.attach(label, 0, 1, i, i+1, xpadding=PROPERTIES_XPAD, ypadding=PROPERTIES_YPAD)                
     entry = gtk.Button()
     entry.set_label(type)
     self.widget.attach(entry, 1, 2, i, i+1, xpadding=PROPERTIES_XPAD, ypadding=PROPERTIES_YPAD)
     i += 1
     
     sep = gtk.HSeparator()
     self.widget.attach(sep, 0, 2, i, i+1, xpadding=PROPERTIES_XPAD, ypadding=PROPERTIES_YPAD)
     i += 1
     
     for param in params:            
         name = param.getAttribute('name')
         ptype = param.getAttribute('type')
         str = '{0} ({1})'.format(name, ptype)
         label = gtk.Label(str)
         label.set_alignment(0.,0.5)
         #label.set_ellipsize(pango.ELLIPSIZE_END)
         if name in template_params:
             label.set_tooltip_text(template_params[name].getAttribute('desc'))
         else:
             label.set_tooltip_text('No description available')
         self.widget.attach(label, 0, 1, i, i+1, xpadding=PROPERTIES_XPAD, ypadding=PROPERTIES_YPAD)                
         if ptype == 'bool':
             entry = gtk.combo_box_new_text()                
             entry.append_text('False')
             entry.append_text('True')
             val = util.bool(param.getAttribute('val'))
             if val:
                 entry.set_active(1)
             else:
                 entry.set_active(0)
             entry.connect('changed', self.eventEdit, name)
         else:
             entry = gtk.Entry()
             entry.set_alignment(0.)
             entry.set_text(param.getAttribute('val'))
             entry.connect('changed', self.eventEdit, name)
         
         self.widget.attach(entry, 1, 2, i, i+1, xpadding=PROPERTIES_XPAD, ypadding=PROPERTIES_YPAD)
         i += 1
         
     sep = gtk.HSeparator()
     self.widget.attach(sep, 0, 2, i, i+1, xpadding=PROPERTIES_XPAD, ypadding=PROPERTIES_YPAD)
     i += 1
         
     self.desc = gtk.TextView()
     self.desc.set_wrap_mode(gtk.WRAP_WORD)
     str = self.ctx.getConfig().getComponentDesc(type)
     if not str:
         str = 'No description available.'
     self.desc.get_buffer().set_text(str)
     self.desc.set_editable(False)
     self.widget.attach(self.desc, 0, 2, i, i+1, xpadding=PROPERTIES_XPAD, ypadding=PROPERTIES_YPAD )
     
     self.widget.show_all()
     self.widget.set_reallocate_redraws(True)
     gobject.timeout_add( 100, self.widget.check_resize)