示例#1
0
def layer_export(map_name):
    defn_obj = MapDefinition.get_by_name(map_name)
    if defn_obj is None:
        abort(404)
    from dataexport import export_csv_iter
    return Response(headers={
        'Cache-Control' : 'max-age=86400, public',
        'Content-Disposition' : 'inline; filename="%s.csv"' % urllib.quote(map_name)
    }, response=export_csv_iter(defn_obj), status=200, content_type='text/csv')
示例#2
0
def layer_export(map_name):
    defn_obj = MapDefinition.get_by_name(map_name)
    if defn_obj is None:
        abort(404)
    from dataexport import export_csv_iter
    return Response(
        headers={
            'Cache-Control': 'max-age=86400, public',
            'Content-Disposition': 'inline; filename="%s.csv"' % urllib.quote(map_name)
        }, response=export_csv_iter(defn_obj), status=200, content_type='text/csv')
示例#3
0
def layer_export_bounds(map_name, ne, sw):
    defn_obj = MapDefinition.get_by_name(map_name)
    if defn_obj is None:
        abort(404)
    ne = map(float, ne.split(','))
    sw = map(float, sw.split(','))
    if len(ne) != 2 or len(sw) != 2:
        abort(404)
    from dataexport import export_csv_iter
    return Response(headers={
        'Cache-Control': 'max-age=86400, public',
        'Content-Disposition': 'inline; filename="%s_%f_%f_%f_%f.csv"' % (urllib.quote(map_name), ne[0], ne[1], sw[0], sw[1])
    }, response=export_csv_iter(defn_obj, (ne, sw)), status=200, content_type='text/csv')
示例#4
0
def layer_legend(map_name, layer_id, client_rev):
    defn_obj = MapDefinition.get_by_name(map_name)
    if defn_obj is None:
        abort(404)
    defn = defn_obj.get()
    rev = defn.get('rev', 0)
    if not defn.has_key('layers'):
        abort(404)
    layer_defn = defn['layers'].get(layer_id, None)
    if layer_defn is None:
        abort(404)
    scale = colour_for_layer(layer_defn)
    return Response(headers={'Cache-Control' : 'max-age=86400, public'}, response=scale.legend(), status=200, content_type='image/png')
示例#5
0
def api_map(map_name):
    eal = EAlGIS()
    defn = MapDefinition.get_by_name(map_name)
    if request.method == 'POST':
        if (defn is not None) and (not is_administrator(defn)):
            abort(403)
        try:
            if 'json' not in request.form:
                abort(400)
            if defn is None:
                defn = MapDefinition(name=map_name)
                eal.db.session.add(defn)
                eal.db.session.commit()
            try:
                rev = defn.set(json.loads(request.form['json']))
                eal.db.session.commit()
            except ValueError:
                abort(400)
            return jsonify(status="OK", updated=defn.get(), rev=rev)
        except CompilationError as e:
            return jsonify(status="ERROR", title="Expression compilation failed", mesg=e.message)
        except NoMatches as e:
            return jsonify(status="ERROR", title="Attribute could not be resolved", mesg=e.message)
        except TooManyMatches as e:
            return jsonify(status="ERROR", title="Attribube reference is ambiguous", mesg=e.message)
    elif request.method == 'DELETE':
        if defn is None:
            abort(404)
        if not is_administrator(defn):
            abort(403)
        eal.db.session.delete(defn)
        eal.db.session.commit()
        return jsonify(status="OK")
    else:
        if defn is None:
            abort(404)
        return jsonify(defn=defn.get(), administrator=is_administrator(defn))
示例#6
0
def layer_legend(map_name, layer_id, client_rev):
    defn_obj = MapDefinition.get_by_name(map_name)
    if defn_obj is None:
        abort(404)
    defn = defn_obj.get()
    if 'layers' not in defn:
        abort(404)
    layer_defn = defn['layers'].get(layer_id, None)
    if layer_defn is None:
        abort(404)
    scale = colour_for_layer(layer_defn)
    return Response(headers={'Cache-Control': 'max-age=86400, public'},
                    response=scale.legend(),
                    status=200,
                    content_type='image/png')
示例#7
0
 def get_or_create(self, map_name, layer_id):
     defn_obj = MapDefinition.get_by_name(map_name)
     if defn_obj is None:
         return None
     defn = defn_obj.get()
     rev = defn.get('rev', 0)
     if not defn.has_key('layers'):
         return None
     layer_defn = defn['layers'].get(layer_id, None)
     if layer_defn is None:
         return None
     key = (defn_obj.id, layer_id)
     wrapper = self.instances.get(key, None)
     if wrapper is not None and wrapper.rev != rev:
         wrapper = None
         del self.instances[key]
     if wrapper is None:
         wrapper = Map(rev, layer_defn)
         self.instances[key] = wrapper
     return wrapper
示例#8
0
 def get_or_create(self, map_name, layer_id):
     defn_obj = MapDefinition.get_by_name(map_name)
     if defn_obj is None:
         return None
     defn = defn_obj.get()
     rev = defn.get('rev', 0)
     if 'layers' not in defn:
         return None
     layer_defn = defn['layers'].get(layer_id, None)
     if layer_defn is None:
         return None
     key = (defn_obj.id, layer_id)
     wrapper = self.instances.get(key, None)
     if wrapper is not None and wrapper.rev != rev:
         wrapper = None
         del self.instances[key]
     if wrapper is None:
         wrapper = Map(rev, layer_defn)
         self.instances[key] = wrapper
     return wrapper
示例#9
0
def api_map(map_name):
    eal = EAlGIS()
    defn = MapDefinition.get_by_name(map_name)
    if request.method == 'POST':
        if (defn is not None) and (not is_administrator(defn)):
            abort(403)
        try:
            if 'json' not in request.form:
                abort(400)
            if defn is None:
                defn = MapDefinition(name=map_name)
                eal.db.session.add(defn)
                eal.db.session.commit()
            try:
                rev = defn.set(json.loads(request.form['json']))
                eal.db.session.commit()
            except ValueError:
                abort(400)
            return jsonify(status="OK", updated=defn.get(), rev=rev)
        except CompilationError as e:
            return jsonify(status="ERROR",
                           title="Expression compilation failed",
                           mesg=e.message)
        except NoMatches as e:
            return jsonify(status="ERROR",
                           title="Attribute could not be resolved",
                           mesg=e.message)
        except TooManyMatches as e:
            return jsonify(status="ERROR",
                           title="Attribube reference is ambiguous",
                           mesg=e.message)
    elif request.method == 'DELETE':
        if defn is None:
            abort(404)
        if not is_administrator(defn):
            abort(403)
        eal.db.session.delete(defn)
        eal.db.session.commit()
        return jsonify(status="OK")
    else:
        if defn is None:
            abort(404)
        return jsonify(defn=defn.get(), administrator=is_administrator(defn))
示例#10
0
                    row.append(None)
                    new_vals.append((gid, val))
            vals = new_vals
            if len([t for t in row if t is not None]) == 0:
                break
            yield row


def export_csv_iter(*args, **kwargs):
    s = StringIO()
    w = csv.writer(s)
    for row in export_iter(*args, **kwargs):
        w.writerow(row)
        s.flush()
        yield s.getvalue()
        s.truncate(0)


if __name__ == "__main__":
    map_name = sys.argv[1]
    defn_obj = MapDefinition.get_by_name(map_name)
    if defn_obj is None:
        sys.exit(1)
    import csv

    w = csv.writer(sys.stdout)
    for row in export_iter(
        defn_obj, [(-31.91534106639876, 115.91443324565473), (-31.921000867731685, 115.90771699428872)]
    ):
        w.writerow(row)
示例#11
0
                    new_vals.append(next_or_none(iterator))
                else:
                    row.append(None)
                    new_vals.append((gid, val))
            vals = new_vals
            if len([t for t in row if t is not None]) == 0:
                break
            yield row


def export_csv_iter(*args, **kwargs):
    s = StringIO()
    w = csv.writer(s)
    for row in export_iter(*args, **kwargs):
        w.writerow(row)
        s.flush()
        yield s.getvalue()
        s.truncate(0)


if __name__ == '__main__':
    map_name = sys.argv[1]
    defn_obj = MapDefinition.get_by_name(map_name)
    if defn_obj is None:
        sys.exit(1)
    w = csv.writer(sys.stdout)
    for row in export_iter(defn_obj,
                           [(-31.91534106639876, 115.91443324565473),
                            (-31.921000867731685, 115.90771699428872)]):
        w.writerow(row)
示例#12
0
def api_mapexists(map_name):
    defn_obj = MapDefinition.get_by_name(map_name)
    res = {
        'exists': defn_obj is not None
    }
    return jsonify(res)